X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Ft%2Fapi%2Frights.t;h=a6346a737ddbe49f6c95b10aa65d28e773055fc6;hb=0b08a87698a2278f3806a66dd6c93b24b18d4767;hp=a1795ca0a4a179faaaa0f4d192c7e23978bcbb7b;hpb=85e677b86fc37c54e6de2b06340351a28f5a5916;p=freeside.git diff --git a/rt/t/api/rights.t b/rt/t/api/rights.t index a1795ca0a..a6346a737 100644 --- a/rt/t/api/rights.t +++ b/rt/t/api/rights.t @@ -1,66 +1,14 @@ -#!/usr/bin/perl -w -# BEGIN BPS TAGGED BLOCK {{{ -# -# COPYRIGHT: -# -# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC -# -# -# (Except where explicitly superseded by other copyright notices) -# -# -# LICENSE: -# -# This work is made available to you under the terms of Version 2 of -# the GNU General Public License. A copy of that license should have -# been provided with this software, but in any event can be snarfed -# from www.gnu.org. -# -# This work is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301 or visit their web page on the internet at -# http://www.gnu.org/copyleft/gpl.html. -# -# -# CONTRIBUTION SUBMISSION POLICY: -# -# (The following paragraph is not intended to limit the rights granted -# to you to modify and distribute this software under the terms of -# the GNU General Public License and is only of importance to you if -# you choose to contribute your changes and enhancements to the -# community by submitting them to Best Practical Solutions, LLC.) -# -# By intentionally submitting any modifications, corrections or -# derivatives to this work, or any other work intended for use with -# Request Tracker, to Best Practical Solutions, LLC, you confirm that -# you are the copyright holder for those contributions and you grant -# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, -# royalty-free, perpetual, license to use, copy, create derivative -# works based on those contributions, and sublicense and distribute -# those contributions and any derivatives thereof. -# -# END BPS TAGGED BLOCK }}} - -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'; @@ -81,10 +29,8 @@ ok $user && $user->id, 'loaded or created user'; } { - my $group = RT::Group->new( RT->SystemUser ); - ok( $group->LoadQueueRoleGroup( Queue => $queue->id, Type=> 'Owner' ), - "load queue owners role group" - ); + my $group = $queue->RoleGroup( 'Owner' ); + ok( $group->Id, "load queue owners role group" ); my $ace = RT::ACE->new( RT->SystemUser ); my ($ace_id, $msg) = $group->PrincipalObj->GrantRight( Right => 'ReplyToTicket', Object => $queue @@ -136,10 +82,8 @@ my $ticket; { # Testing of EquivObjects - my $group = RT::Group->new( RT->SystemUser ); - ok( $group->LoadQueueRoleGroup( Queue => $queue->id, Type=> 'AdminCc' ), - "load queue AdminCc role group" - ); + my $group = $queue->RoleGroup( 'AdminCc' ); + ok( $group->Id, "load queue AdminCc role group" ); my $ace = RT::ACE->new( RT->SystemUser ); my ($ace_id, $msg) = $group->PrincipalObj->GrantRight( Right => 'ModifyTicket', Object => $queue @@ -195,3 +139,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"; +}