[Catalyst-commits] r7896 - in trunk/Catalyst-Plugin-Authentication:
lib/Catalyst/Authentication/Store lib/Catalyst/Plugin t t/lib
kane at dev.catalyst.perl.org
kane at dev.catalyst.perl.org
Thu Jun 5 17:30:54 BST 2008
Author: kane
Date: 2008-06-05 17:30:54 +0100 (Thu, 05 Jun 2008)
New Revision: 7896
Added:
trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestAppCompat.pm
trunk/Catalyst-Plugin-Authentication/t/live_app_realms_compat.t
Modified:
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Store/Minimal.pm
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm
trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestApp.pm
Log:
* fixed a nasty bug in compat mode with store::minimal. From the comments left in ->setup():
### If a user does 'use Catalyst qw/Authentication::Store::Minimal/'
### he will be proxied on to this setup routine (and only then --
### non plugins should NOT have their setup routine invoked!)
### Beware what we pass to the 'new' routine; it wants
### a config has with a top level key 'users'. New style
### configs do not have this, and split by realms. If we
### blindly pass this to new, we will 1) overwrite what we
### already passed and 2) make ->userhash undefined, which
### leads to:
### Can't use an undefined value as a HASH reference at
### lib/Catalyst/Authentication/Store/Minimal.pm line 38.
###
### So only do this compatibility call if:
### 1) we have a {users} config directive
###
### Ideally we could also check for:
### 2) we don't already have a ->userhash
### however, that's an attribute of an object we can't access =/
Modified: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Store/Minimal.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Store/Minimal.pm 2008-06-05 13:14:11 UTC (rev 7895)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Store/Minimal.pm 2008-06-05 16:30:54 UTC (rev 7896)
@@ -77,12 +77,32 @@
sub setup {
my $c = shift;
- $c->default_auth_store(
- __PACKAGE__->new(
- $c->config->{'Plugin::Authentication'}, $c
- )
- );
+ ### If a user does 'use Catalyst qw/Authentication::Store::Minimal/'
+ ### he will be proxied on to this setup routine (and only then --
+ ### non plugins should NOT have their setup routine invoked!)
+ ### Beware what we pass to the 'new' routine; it wants
+ ### a config has with a top level key 'users'. New style
+ ### configs do not have this, and split by realms. If we
+ ### blindly pass this to new, we will 1) overwrite what we
+ ### already passed and 2) make ->userhash undefined, which
+ ### leads to:
+ ### Can't use an undefined value as a HASH reference at
+ ### lib/Catalyst/Authentication/Store/Minimal.pm line 38.
+ ###
+ ### So only do this compatibility call if:
+ ### 1) we have a {users} config directive
+ ###
+ ### Ideally we could also check for:
+ ### 2) we don't already have a ->userhash
+ ### however, that's an attribute of an object we can't
+ ### access =/ --kane
+
+ my $cfg = $c->config->{'Plugin::Authentication'}->{users}
+ ? $c->config->{'Plugin::Authentication'}
+ : undef;
+ $c->default_auth_store( __PACKAGE__->new( $cfg, $c ) ) if $cfg;
+
$c->NEXT::setup(@_);
}
Modified: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm 2008-06-05 13:14:11 UTC (rev 7895)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm 2008-06-05 16:30:54 UTC (rev 7896)
@@ -14,7 +14,7 @@
use Catalyst::Authentication::Realm;
-our $VERSION = "0.10007";
+our $VERSION = "0.10007_01";
sub set_authenticated {
my ( $c, $user, $realmname ) = @_;
Modified: trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestApp.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestApp.pm 2008-06-05 13:14:11 UTC (rev 7895)
+++ trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestApp.pm 2008-06-05 16:30:54 UTC (rev 7896)
@@ -2,7 +2,10 @@
use warnings;
use strict;
-use Catalyst qw/Authentication/;
+use Catalyst qw/
+ Authentication
+ Authentication::Store::Minimal
+/;
use Test::More;
use Test::Exception;
Added: trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestAppCompat.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestAppCompat.pm (rev 0)
+++ trunk/Catalyst-Plugin-Authentication/t/lib/AuthRealmTestAppCompat.pm 2008-06-05 16:30:54 UTC (rev 7896)
@@ -0,0 +1,61 @@
+package AuthRealmTestAppCompat;
+use warnings;
+use strict;
+
+### using A::Store::minimal with new style realms
+### makes the app blow up, since c::p::a::s::minimal
+### isa c:a::s::minimal, and it's compat setup() gets
+### run, with an unexpected config has (realms on top,
+### not users). This tests makes sure the app no longer
+### blows up when this happens.
+use Catalyst qw/
+ Authentication
+ Authentication::Store::Minimal
+/;
+
+use Test::More;
+use Test::Exception;
+
+our $members = {
+ bob => {
+ password => "s00p3r"
+ },
+};
+
+sub moose : Local {
+ my ( $self, $c ) = @_;
+
+ while ( my ($user, $info) = each %$members ) {
+
+ my $ok = eval {
+ $c->authenticate(
+ { username => $user, password => $info->{password} },
+ 'members'
+ ),
+ };
+
+ ok( !$@, "Test did not die: $@" );
+ ok( $ok, "user $user authentication" );
+ }
+
+ $c->res->body( "ok" );
+}
+
+__PACKAGE__->config->{'Plugin::Authentication'} = {
+ default_realm => 'members',
+ realms => {
+ members => {
+ credential => {
+ class => 'Password',
+ password_field => 'password',
+ password_type => 'clear'
+ },
+ store => {
+ class => 'Minimal',
+ users => $members,
+ }
+ },
+ }
+};
+
+__PACKAGE__->setup;
Added: trunk/Catalyst-Plugin-Authentication/t/live_app_realms_compat.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/live_app_realms_compat.t (rev 0)
+++ trunk/Catalyst-Plugin-Authentication/t/live_app_realms_compat.t 2008-06-05 16:30:54 UTC (rev 7896)
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+BEGIN {
+ plan "no_plan";
+}
+
+use lib 't/lib';
+use Catalyst::Test qw/AuthRealmTestAppCompat/;
+
+ok(get("/moose"), "get ok");
More information about the Catalyst-commits
mailing list