[Catalyst-commits] r7685 - in
trunk/Catalyst-Plugin-Authorization-Roles: .
lib/Catalyst/Plugin/Authorization t
threebytesfull at dev.catalyst.perl.org
threebytesfull at dev.catalyst.perl.org
Tue May 6 18:08:47 BST 2008
Author: threebytesfull
Date: 2008-05-06 18:08:47 +0100 (Tue, 06 May 2008)
New Revision: 7685
Modified:
trunk/Catalyst-Plugin-Authorization-Roles/Changes
trunk/Catalyst-Plugin-Authorization-Roles/Makefile.PL
trunk/Catalyst-Plugin-Authorization-Roles/lib/Catalyst/Plugin/Authorization/Roles.pm
trunk/Catalyst-Plugin-Authorization-Roles/t/basic.t
trunk/Catalyst-Plugin-Authorization-Roles/t/hash_user.t
Log:
* Removed use of Test::MockObject
* Fixed code and tests for renamed Catalyst::Authentication::* modules
* Updated changes file and prerequisites list
* Bumped version to 0.06
Modified: trunk/Catalyst-Plugin-Authorization-Roles/Changes
===================================================================
--- trunk/Catalyst-Plugin-Authorization-Roles/Changes 2008-05-06 14:15:22 UTC (rev 7684)
+++ trunk/Catalyst-Plugin-Authorization-Roles/Changes 2008-05-06 17:08:47 UTC (rev 7685)
@@ -1,5 +1,9 @@
Revision history for Perl extension Catalyst::Plugin::Authorization::Roles
+0.06
+ - support renamed Catalyst::Authentication::* modules
+ - removed dependency on Test::MockObject
+
0.05
- fix tests due to a change in Test::MockObject
- add support for check_any style role checks.
Modified: trunk/Catalyst-Plugin-Authorization-Roles/Makefile.PL
===================================================================
--- trunk/Catalyst-Plugin-Authorization-Roles/Makefile.PL 2008-05-06 14:15:22 UTC (rev 7684)
+++ trunk/Catalyst-Plugin-Authorization-Roles/Makefile.PL 2008-05-06 17:08:47 UTC (rev 7685)
@@ -4,10 +4,9 @@
'VERSION_FROM' => 'lib/Catalyst/Plugin/Authorization/Roles.pm',
'PREREQ_PM' => {
'Catalyst' => '5.49',
- 'Catalyst::Plugin::Authentication' => '0.03',
+ 'Catalyst::Plugin::Authentication' => '0.10003',
'Set::Object' => '1.14',
'Test::Exception' => '0',
- 'Test::MockObject' => '1.01',
'UNIVERSAL::isa' => '0.05'
},
'INSTALLDIRS' => 'site',
Modified: trunk/Catalyst-Plugin-Authorization-Roles/lib/Catalyst/Plugin/Authorization/Roles.pm
===================================================================
--- trunk/Catalyst-Plugin-Authorization-Roles/lib/Catalyst/Plugin/Authorization/Roles.pm 2008-05-06 14:15:22 UTC (rev 7684)
+++ trunk/Catalyst-Plugin-Authorization-Roles/lib/Catalyst/Plugin/Authorization/Roles.pm 2008-05-06 17:08:47 UTC (rev 7685)
@@ -9,7 +9,7 @@
use Scalar::Util ();
use Catalyst::Exception ();
-our $VERSION = "0.05";
+our $VERSION = "0.06";
sub check_user_roles {
my ( $c, @roles ) = @_;
@@ -23,7 +23,7 @@
my $user;
if ( Scalar::Util::blessed( $roles[0] )
- && $roles[0]->isa("Catalyst::Plugin::Authentication::User") )
+ && $roles[0]->isa("Catalyst::Authentication::User") )
{
$user = shift @roles;
}
@@ -80,7 +80,7 @@
my $user;
if ( Scalar::Util::blessed( $roles[0] )
- && $roles[0]->isa("Catalyst::Plugin::Authentication::User") )
+ && $roles[0]->isa("Catalyst::Authentication::User") )
{
$user = shift @roles;
}
@@ -129,7 +129,7 @@
=head1 NAME
Catalyst::Plugin::Authorization::Roles - Role based authorization for
-L<Catalyst> based on L<Catalyst::Plugin::Authentication>.
+L<Catalyst> based on L<Catalyst::Authentication>.
=head1 SYNOPSIS
@@ -215,7 +215,7 @@
=head1 SEE ALSO
-L<Catalyst::Plugin::Authentication>
+L<Catalyst::Authentication>
L<http://catalyst.perl.org/calendar/2005/24>
Modified: trunk/Catalyst-Plugin-Authorization-Roles/t/basic.t
===================================================================
--- trunk/Catalyst-Plugin-Authorization-Roles/t/basic.t 2008-05-06 14:15:22 UTC (rev 7684)
+++ trunk/Catalyst-Plugin-Authorization-Roles/t/basic.t 2008-05-06 17:08:47 UTC (rev 7685)
@@ -3,28 +3,17 @@
use strict;
use warnings;
-use Test::More 'no_plan';
-use Test::MockObject;
-use Test::MockObject::Extends;
+use Test::More tests => 21;
use Test::Exception;
+use Catalyst::Authentication::User;
my $m; BEGIN { use_ok($m = "Catalyst::Plugin::Authorization::Roles") }
-# cheat Test::MockObject::Extends
-$INC{"Catalyst/Plugin/Authentication/User.pm"} = 1;
- at Catalyst::Plugin::Authentication::User::ISA = ();
+my $user = MockUser->new;
+$user->roles(qw/admin user moose_trainer/);
-my $user = Test::MockObject::Extends->new("Catalyst::Plugin::Authentication::User");
+my $c = MockAuthz->new($user);
-$user->set_list(roles => qw/admin user moose_trainer/);
-$user->mock( supports => sub { shift; @_ == 1 and $_[0] eq "roles" });
-
-my $c = Test::MockObject::Extends->new( $m );
-
-$c->set_always( "user", $user );
-
-$c->set_false("debug");
-
can_ok( $m, "assert_user_roles" );
can_ok( $m, "check_user_roles" );
can_ok( $m, "assert_any_user_role" );
@@ -46,10 +35,34 @@
ok( $c->check_any_user_role( qw/admin moose_feeder/ ), "check_any_user_role true" );
ok( !$c->check_any_user_role( qw/moose_feeder climber/ ), "check_any_user_role false" );
-$c->set_false( "user" );
+$c = MockAuthz->new(undef);
throws_ok { $c->assert_user_roles( "moose_trainer" ) } qr/no logged in user/i, "can't assert without logged user";
lives_ok { $c->assert_user_roles( $user, "moose_trainer" ) } "unless supplying user explicitly";
throws_ok { $c->assert_any_user_role( qw/moose_trainer/ ) } qr/no logged in user/i, "assert_any_user_role: can't assert without logged user";
lives_ok { $c->assert_any_user_role( $user, "moose_trainer" ) } "unless supplying user explicitly";
+
+package MockAuthz;
+
+use base 'Catalyst::Plugin::Authorization::Roles';
+
+sub new {
+ my ($class, $user) = @_;
+ return bless { user => $user }, $class;
+}
+sub user { return shift->{user}; }
+sub debug { return 0; }
+
+package MockUser;
+use base 'Catalyst::Authentication::User';
+
+sub supported_features { return { roles => 1 } };
+sub roles {
+ my ($self, @roles) = @_;
+ if (@roles) {
+ $self->{_roles} = [@roles];
+ }
+ $self->{_roles} ||= [];
+ @{$self->{_roles}};
+}
Modified: trunk/Catalyst-Plugin-Authorization-Roles/t/hash_user.t
===================================================================
--- trunk/Catalyst-Plugin-Authorization-Roles/t/hash_user.t 2008-05-06 14:15:22 UTC (rev 7684)
+++ trunk/Catalyst-Plugin-Authorization-Roles/t/hash_user.t 2008-05-06 17:08:47 UTC (rev 7685)
@@ -3,25 +3,20 @@
use strict;
use warnings;
-use Test::More 'no_plan';
-use Test::MockObject::Extends;
+use Test::More tests => 21;
use Test::Exception;
-use Catalyst::Plugin::Authentication::User::Hash;
+use Catalyst::Authentication::User::Hash;
my $m; BEGIN { use_ok($m = "Catalyst::Plugin::Authorization::Roles") }
-my $user = Catalyst::Plugin::Authentication::User::Hash->new(
+my $user = Catalyst::Authentication::User::Hash->new(
roles => [qw/admin user moose_trainer/],
id => "foo",
password => "s3cr3t",
);
-my $c = Test::MockObject::Extends->new( $m );
+my $c = MockAuthz->new($user);
-$c->set_always( "user", $user );
-
-$c->set_false("debug");
-
can_ok( $m, "assert_user_roles" );
can_ok( $m, "check_user_roles" );
can_ok( $m, "assert_any_user_role" );
@@ -43,7 +38,7 @@
ok( $c->check_any_user_role( qw/admin moose_feeder/ ), "check_any_user_role true" );
ok( !$c->check_any_user_role( qw/moose_feeder climber/ ), "check_any_user_role false" );
-$c->set_false( "user" );
+$c = MockAuthz->new(undef);
throws_ok { $c->assert_user_roles( "moose_trainer" ) } qr/no logged in user/i, "can't assert without logged user";
lives_ok { $c->assert_user_roles( $user, "moose_trainer" ) } "unless supplying user explicitly";
@@ -51,3 +46,13 @@
throws_ok { $c->assert_any_user_role( qw/moose_trainer/ ) } qr/no logged in user/i, "assert_any_user_role: can't assert without logged user";
lives_ok { $c->assert_any_user_role( $user, "moose_trainer" ) } "unless supplying user explicitly";
+package MockAuthz;
+
+use base 'Catalyst::Plugin::Authorization::Roles';
+
+sub new {
+ my ($class, $user) = @_;
+ return bless { user => $user }, $class;
+}
+sub user { return shift->{user}; }
+sub debug { return 0; }
More information about the Catalyst-commits
mailing list