3 use RT::Test tests => 10;
5 RT::System->AddRight( General =>
6 'RTxUserRight' => 'Just a right for testing rights',
10 no warnings qw(redefine once);
12 ok(my $users = RT::Users->new(RT->SystemUser));
13 $users->WhoHaveRight(Object => RT->System, Right =>'SuperUser');
14 is($users->Count , 1, "There is one privileged superuser - Found ". $users->Count );
15 # TODO: this wants more testing
17 my $RTxUser = RT::User->new(RT->SystemUser);
18 my ($id, $msg) = $RTxUser->Create( Name => 'RTxUser', Comments => "RTx extension user", Privileged => 1);
21 my $group = RT::Group->new(RT->SystemUser);
22 $group->LoadACLEquivalenceGroup($RTxUser->PrincipalObj);
25 bless $RTxSysObj, 'RTx::System';
26 *RTx::System::Id = sub { 1; };
27 *RTx::System::id = *RTx::System::Id;
28 my $ace = RT::Record->new(RT->SystemUser);
30 $ace->_BuildTableAttributes unless ($RT::Record::_TABLE_ATTR->{ref($ace)});
31 ($id, $msg) = $ace->Create( PrincipalId => $group->id, PrincipalType => 'Group', RightName => 'RTxUserRight', ObjectType => 'RTx::System', ObjectId => 1 );
32 ok ($id, "ACL for RTxSysObj created");
35 bless $RTxObj, 'RTx::System::Record';
36 *RTx::System::Record::Id = sub { 4; };
37 *RTx::System::Record::id = *RTx::System::Record::Id;
39 $users = RT::Users->new(RT->SystemUser);
40 $users->WhoHaveRight(Right => 'RTxUserRight', Object => $RTxSysObj);
41 is($users->Count, 1, "RTxUserRight found for RTxSysObj");
43 $users = RT::Users->new(RT->SystemUser);
44 $users->WhoHaveRight(Right => 'RTxUserRight', Object => $RTxObj);
45 is($users->Count, 0, "RTxUserRight not found for RTxObj");
47 $users = RT::Users->new(RT->SystemUser);
48 $users->WhoHaveRight(Right => 'RTxUserRight', Object => $RTxObj, EquivObjects => [ $RTxSysObj ]);
49 is($users->Count, 1, "RTxUserRight found for RTxObj using EquivObjects");
51 $ace = RT::Record->new(RT->SystemUser);
53 $ace->_BuildTableAttributes unless ($RT::Record::_TABLE_ATTR->{ref($ace)});
54 ($id, $msg) = $ace->Create( PrincipalId => $group->id, PrincipalType => 'Group', RightName => 'RTxUserRight', ObjectType => 'RTx::System::Record', ObjectId => 5 );
55 ok ($id, "ACL for RTxObj created");
58 bless $RTxObj2, 'RTx::System::Record';
59 *RTx::System::Record::Id = sub { 5; };
60 *RTx::System::Record::id = sub { 5; };
62 $users = RT::Users->new(RT->SystemUser);
63 $users->WhoHaveRight(Right => 'RTxUserRight', Object => $RTxObj2);
64 is($users->Count, 1, "RTxUserRight found for RTxObj2");
66 $users = RT::Users->new(RT->SystemUser);
67 $users->WhoHaveRight(Right => 'RTxUserRight', Object => $RTxObj2, EquivObjects => [ $RTxSysObj ]);
68 is($users->Count, 1, "RTxUserRight found for RTxObj2");