fixed a nasty bug in compat mode with store::minimal. From the comments left in ...
Jos Boumans [Thu, 5 Jun 2008 16:30:54 +0000 (16:30 +0000)]
### 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 =/

lib/Catalyst/Authentication/Store/Minimal.pm
lib/Catalyst/Plugin/Authentication.pm
t/lib/AuthRealmTestApp.pm
t/lib/AuthRealmTestAppCompat.pm [new file with mode: 0644]
t/live_app_realms_compat.t [new file with mode: 0644]

index 155a921..6fa764f 100644 (file)
@@ -77,12 +77,32 @@ sub get_user {
 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(@_);
 }
 
index 8b29d0b..ba2afad 100644 (file)
@@ -14,7 +14,7 @@ use Class::Inspector;
 use Catalyst::Authentication::Realm;
 
 
-our $VERSION = "0.10007";
+our $VERSION = "0.10007_01";
 
 sub set_authenticated {
     my ( $c, $user, $realmname ) = @_;
index 36cb291..bc70351 100644 (file)
@@ -2,7 +2,10 @@ package AuthRealmTestApp;
 use warnings;
 use strict;
 
-use Catalyst qw/Authentication/;
+use Catalyst qw/
+    Authentication
+    Authentication::Store::Minimal
+/;
 
 use Test::More;
 use Test::Exception;
diff --git a/t/lib/AuthRealmTestAppCompat.pm b/t/lib/AuthRealmTestAppCompat.pm
new file mode 100644 (file)
index 0000000..4a8b50c
--- /dev/null
@@ -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;
diff --git a/t/live_app_realms_compat.t b/t/live_app_realms_compat.t
new file mode 100644 (file)
index 0000000..5deccf1
--- /dev/null
@@ -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");