[Rt-commit] r2811 - in rt/branches/QUEBEC-EXPERIMENTAL: . lib/t/regression

jesse at bestpractical.com jesse at bestpractical.com
Thu Apr 28 14:42:33 EDT 2005


Author: jesse
Date: Thu Apr 28 14:42:33 2005
New Revision: 2811

Modified:
   rt/branches/QUEBEC-EXPERIMENTAL/   (props changed)
   rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/07acl.t
Log:
 r14612 at hualien:  jesse | 2005-04-28 14:40:33 -0400
 * Cleaned up and expanded the acl test suite to be more robust.
 


Modified: rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/07acl.t
==============================================================================
--- rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/07acl.t	(original)
+++ rt/branches/QUEBEC-EXPERIMENTAL/lib/t/regression/07acl.t	Thu Apr 28 14:42:33 2005
@@ -1,18 +1,19 @@
 #!/usr/bin/perl -w
-
+use strict;
 use WWW::Mechanize;
 use HTTP::Cookies;
 
-use Test::More tests => 26;
+use Test::More tests => 35;
 use RT;
 RT::LoadConfig();
 RT::Init();
 
 # Create a user with basically no rights, to start.
 my $user_obj = RT::User->new($RT::SystemUser);
-my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('customer at example.com');
-ok($ret, 'ACL test user creation');
-$user_obj->SetName('customer');
+my ($ret, $msg) = $user_obj->LoadOrCreateByEmail($$.'-customer at example.com');
+ok($ret, 'ACL test user created'. $user_obj->Name);
+$user_obj->SetName('customer-'.$$);
+ok($user_obj->Name, "The user's name is ".$user_obj->Name);
 $user_obj->SetPrivileged(1);
 ($ret, $msg) = $user_obj->SetPassword('customer');
 ok($ret, "ACL test password set. $msg");
@@ -20,6 +21,7 @@
 # Now test the web interface, making sure objects come and go as
 # required.
 
+
 my $cookie_jar = HTTP::Cookies->new;
 my $agent = WWW::Mechanize->new();
 
@@ -29,24 +31,7 @@
 
 no warnings 'once';
 # get the top page
-my $url = "http://localhost:".$RT::WebPort.$RT::WebPath."/";
-$agent->get($url);
-
-is ($agent->{'status'}, 200, "Loaded a page - http://localhost".$RT::WebPath);
-# {{{ test a login
-
-# follow the link marked "Login"
-
-ok($agent->{form}->find_input('user'));
-
-ok($agent->{form}->find_input('pass'));
-ok ($agent->{'content'} =~ /username:/i);
-$agent->field( 'user' => 'customer' );
-$agent->field( 'pass' => 'customer' );
-# the field isn't named, so we have to click link 0
-$agent->click(0);
-is($agent->{'status'}, 200, "Fetched the page ok");
-ok($agent->{'content'} =~ /Logout/i, "Found a logout link");
+login($agent, $user_obj);
 
 # Test for absence of Configure and Preferences tabs.
 ok(!$agent->find_link( url => '/Admin/',
@@ -56,19 +41,28 @@
 
 # Now test for their presence, one at a time.  Sleep for a bit after
 # ACL changes, thanks to the 10s ACL cache.
-$user_obj->PrincipalObj->GrantRight(Right => 'ShowConfigTab');
-$agent->reload();
+my ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'ShowConfigTab', Object => $RT::System);
+
+ok($grantid,$grantmsg);
+
+$agent->reload;
+
 ok($agent->{'content'} =~ /Logout/i, "Reloaded page successfully");
+
+
+
 ok($agent->find_link( url => '/Admin/',
 		       text => 'Configuration'), "Found config tab" );
-$user_obj->PrincipalObj->RevokeRight(Right => 'ShowConfigTab');
-$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf');
+my ($revokeid,$revokemsg) =$user_obj->PrincipalObj->RevokeRight(Right => 'ShowConfigTab');
+ok ($revokeid,$revokemsg);
+($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf');
+ok ($grantid,$grantmsg);
 $agent->reload();
 ok($agent->{'content'} =~ /Logout/i, "Reloaded page successfully");
 ok($agent->find_link( url => '/User/Prefs.html',
 		       text => 'Preferences'), "Found prefs pane" );
-$user_obj->PrincipalObj->RevokeRight(Right => 'ModifySelf');
-
+($revokeid,$revokemsg) = $user_obj->PrincipalObj->RevokeRight(Right => 'ModifySelf');
+ok ($revokeid,$revokemsg);
 # Good.  Now load the search page and test Load/Save Search.
 $agent->follow_link( url => '/Search/Build.html',
 		     text => 'Tickets');
@@ -76,13 +70,15 @@
 ok($agent->{'content'} !~ /Load saved search/i, "No search loading box");
 ok($agent->{'content'} !~ /Saved searches/i, "No saved searches box");
 
-$user_obj->PrincipalObj->GrantRight(Right => 'LoadSavedSearch');
+($grantid,$grantmsg) = $user_obj->PrincipalObj->GrantRight(Right => 'LoadSavedSearch');
+ok($grantid,$grantmsg);
 $agent->reload();
 ok($agent->{'content'} =~ /Load saved search/i, "Search loading box exists");
 ok($agent->{'content'} !~ /input\s+type=.submit.\s+name=.Save./i, 
    "Still no saved searches box");
 
-$user_obj->PrincipalObj->GrantRight(Right => 'CreateSavedSearch');
+($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'CreateSavedSearch');
+ok ($grantid,$grantmsg);
 $agent->reload();
 ok($agent->{'content'} =~ /Load saved search/i, 
    "Search loading box still exists");
@@ -93,22 +89,24 @@
 # via SelectOwner.
 
 my $queue_obj = RT::Queue->new($RT::SystemUser);
-($ret, $msg) = $queue_obj->Create(Name => 'CustomerQueue', 
+($ret, $msg) = $queue_obj->Create(Name => 'CustomerQueue-'.$$, 
 				  Description => 'queue for SelectOwner testing');
 ok($ret, "SelectOwner test queue creation. $msg");
 my $group_obj = RT::Group->new($RT::SystemUser);
-($ret, $msg) = $group_obj->CreateUserDefinedGroup(Name => 'CustomerGroup',
+($ret, $msg) = $group_obj->CreateUserDefinedGroup(Name => 'CustomerGroup-'.$$,
 			      Description => 'group for SelectOwner testing');
 ok($ret, "SelectOwner test group creation. $msg");
 
 # Add our customer to the customer group, and give it queue rights.
 ($ret, $msg) = $group_obj->AddMember($user_obj->PrincipalObj->Id());
 ok($ret, "Added customer to its group. $msg");
-$group_obj->PrincipalObj->GrantRight(Right => 'OwnTicket',
+($grantid,$grantmsg) =$group_obj->PrincipalObj->GrantRight(Right => 'OwnTicket',
 				     Object => $queue_obj);
-$group_obj->PrincipalObj->GrantRight(Right => 'SeeQueue',
+                                     
+ok($grantid,$grantmsg);
+($grantid,$grantmsg) =$group_obj->PrincipalObj->GrantRight(Right => 'SeeQueue',
 				     Object => $queue_obj);
-
+ok ($grantid,$grantmsg);
 # Now.  When we look at the search page we should be able to see
 # ourself in the list of possible owners.
 
@@ -117,4 +115,25 @@
 my $input = $agent->current_form->find_input('ValueOfActor');
 ok(grep(/customer/, $input->value_names()), "Found self in the actor listing");
 
+sub login {
+    my $agent = shift;
+
+my $url = "http://localhost:".$RT::WebPort.$RT::WebPath."/";
+$agent->get($url);
+is ($agent->{'status'}, 200, "Loaded a page - http://localhost".$RT::WebPath);
+# {{{ test a login
+
+# follow the link marked "Login"
+
+ok($agent->{form}->find_input('user'));
+
+ok($agent->{form}->find_input('pass'));
+ok ($agent->{'content'} =~ /username:/i);
+$agent->field( 'user' => $user_obj->Name);
+$agent->field( 'pass' => 'customer' );
+# the field isn't named, so we have to click link 0
+$agent->click(0);
+is($agent->{'status'}, 200, "Fetched the page ok");
+ok($agent->{'content'} =~ /Logout/i, "Found a logout link");
+}
 1;


More information about the Rt-commit mailing list