[Rt-commit] rt branch, 4.0/uninitialized-warning-rt-principal-hasright, created. rt-4.0.13-66-gdccc657
Alex Vandiver
alexmv at bestpractical.com
Thu Jun 13 15:35:34 EDT 2013
The branch, 4.0/uninitialized-warning-rt-principal-hasright has been created
at dccc6574dc5773ebff6f8d0db7fdd391032e2140 (commit)
- Log -----------------------------------------------------------------
commit 3943679cecb96805ee07a9f6f81fc2843f470384
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Tue Sep 18 13:14:06 2012 -0400
Fix uninitialized value warning in RT::Principal::HasRight
HasRight was storing the cananicalized value of a passed-in Right
argument back in the argument hash, so the debug log output on an
invalid right had an uninitialized value rather than the invalid right
argument.
Use a temporary variable to store the canonicalized value, in case
canonicalization fails and we need access to the pre-canonicalized form.
diff --git a/lib/RT/Principal.pm b/lib/RT/Principal.pm
index 175f1b0..34632b0 100644
--- a/lib/RT/Principal.pm
+++ b/lib/RT/Principal.pm
@@ -263,8 +263,9 @@ sub HasRight {
return 1;
}
- $args{'Right'} = RT::ACE->CanonicalizeRightName( $args{'Right'} );
- unless ( $args{'Right'} ) {
+ if ( my $right = RT::ACE->CanonicalizeRightName( $args{'Right'} ) ) {
+ $args{'Right'} = $right;
+ } else {
$RT::Logger->error(
"Invalid right. Couldn't canonicalize right '$args{'Right'}'");
return undef;
commit dccc6574dc5773ebff6f8d0db7fdd391032e2140
Author: Thomas Sibley <trs at bestpractical.com>
Date: Fri Sep 21 10:51:22 2012 -0700
Tests for right name canonicalization
Tests inserting into the database and pulling back out of the database.
diff --git a/t/api/rights.t b/t/api/rights.t
index 107fb2b..5cf3a00 100644
--- a/t/api/rights.t
+++ b/t/api/rights.t
@@ -1,17 +1,14 @@
-use RT::Test nodata => 1, tests => 30;
+use RT::Test nodata => 1, tests => 38;
use strict;
use warnings;
+use Test::Warn;
+
+sub reset_rights { RT::Test->set_rights }
+
# clear all global right
-{
- my $acl = RT::ACL->new(RT->SystemUser);
- $acl->Limit( FIELD => 'RightName', OPERATOR => '!=', VALUE => 'SuperUser' );
- $acl->LimitToObject( $RT::System );
- while( my $ace = $acl->Next ) {
- $ace->Delete;
- }
-}
+reset_rights;
my $queue = RT::Test->load_or_create_queue( Name => 'Regression' );
ok $queue && $queue->id, 'loaded or created queue';
@@ -146,3 +143,38 @@ my $ticket2;
"user is not AdminCc and can't modify ticket2 (same question different answer)"
);
}
+
+my $queue2 = RT::Test->load_or_create_queue( Name => 'Rights' );
+ok $queue2 && $queue2->id, 'loaded or created queue';
+
+my $user2 = RT::Test->load_or_create_user(
+ Name => 'user2', Password => 'password',
+);
+ok $user2 && $user2->id, 'Created user: ' . $user2->Name . ' with id ' . $user2->Id;
+
+warning_like {
+ ok( !$user2->HasRight( Right => 'Foo', Object => $queue2 ),
+ "HasRight false for invalid right Foo"
+ );
+} qr/Invalid right\. Couldn't canonicalize right 'Foo'/,
+ 'Got warning on invalid right';
+
+
+note "Right name canonicalization";
+{
+ reset_rights;
+ my ($ok, $msg) = $user->PrincipalObj->GrantRight(
+ Right => "showticket",
+ Object => RT->System,
+ );
+ ok $ok, "Granted showticket: $msg";
+ ok $user->HasRight( Right => "ShowTicket", Object => RT->System ), "HasRight ShowTicket";
+
+ reset_rights;
+ ($ok, $msg) = $user->PrincipalObj->GrantRight(
+ Right => "ShowTicket",
+ Object => RT->System,
+ );
+ ok $ok, "Granted ShowTicket: $msg";
+ ok $user->HasRight( Right => "showticket", Object => RT->System ), "HasRight showticket";
+}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list