possibly fix frang's problem
Yuval Kogman [Tue, 1 Aug 2006 05:40:26 +0000 (05:40 +0000)]
lib/Catalyst/Plugin/Authentication.pm
t/lib/AuthSessionTestApp.pm
t/live_app_session.t

index 719d127..0052f60 100644 (file)
@@ -50,8 +50,7 @@ sub user {
     if ( defined(my $user = $c->_user) ) {
         return $user;
     } else {
-        my $frozen = $c->_user_in_session;
-        return $c->auth_restore_user($frozen);
+        return $c->auth_restore_user;
     }
 }
 
@@ -60,16 +59,6 @@ sub user_exists {
        return defined($c->_user) || defined($c->_user_in_session);
 }
 
-sub _user_in_session {
-    my $c = shift;
-
-    if ( $c->isa("Catalyst::Plugin::Session") and $c->session_is_valid ) {
-        return $c->session->{__user};
-    }
-
-    return;
-}
-
 sub save_user_in_session {
     my ( $c, $user ) = @_;
 
@@ -83,9 +72,11 @@ sub logout {
 
     $c->user(undef);
 
-    if (    $c->isa("Catalyst::Plugin::Session")
-        and $c->config->{authentication}{use_session} )
-    {
+    if (
+        $c->isa("Catalyst::Plugin::Session")
+        and $c->config->{authentication}{use_session}
+        and $c->session_is_valid
+    ) {
         delete @{ $c->session }{qw/__user __user_store/};
     }
     
@@ -105,16 +96,26 @@ sub get_user {
     }
 }
 
+sub _user_in_session {
+    my $c = shift;
+
+    return unless
+        $c->isa("Catalyst::Plugin::Session")
+        and $c->config->{authentication}{use_session}
+        and $c->session_is_valid;
+
+    return $c->session->{__user};
+
+    return;
+}
+
 sub auth_restore_user {
     my ( $c, $frozen_user, $store_name ) = @_;
 
-    return
-      unless $c->isa("Catalyst::Plugin::Session")
-      and $c->config->{authentication}{use_session}
-      and $c->sessionid;
+    $frozen_user ||= $c->_user_in_session;
+    return unless defined($frozen_user);
 
     $store_name  ||= $c->session->{__user_store};
-    $frozen_user ||= $c->session->{__user};
 
     my $store = $c->get_auth_store($store_name);
     $c->_user( my $user = $store->from_session( $c, $frozen_user ) );
index 66f2480..273bb55 100644 (file)
@@ -39,15 +39,33 @@ sub elk : Local {
        ok( $c->user_exists, "user exists" );
        ok( $c->user, "a user was also restored");
        is_deeply( $c->user, $users->{foo}, "restored user is the right one (deep test - store might change identity)" );
-
-       $c->delete_session("bah");
+    
+    $c->logout;
 }
 
 sub fluffy_bunny : Local {
        my ( $self, $c ) = @_;
 
-       ok( !$c->session_is_valid, "no session ID was restored");
+       ok( $c->session_is_valid, "no session ID was restored");
        ok( !$c->user, "no user was restored");
+       
+    $c->delete_session("bah");
+}
+
+sub possum : Local {
+    my ( $self, $c ) = @_;
+
+       ok( !$c->session_is_valid, "no session ID was restored");
+    $c->session->{definitely_not_a_user} = "moose";
+
+}
+
+sub butterfly : Local {
+    my ( $self, $c ) = @_;
+
+    ok( $c->session_is_valid, "valid session" );
+    ok( !$c->user_exists, "but no user exists" );
+    ok( !$c->user, "no user object either" );
 }
 
 __PACKAGE__->config->{authentication}{users} = $users = {
index b23a767..e1be7cd 100644 (file)
@@ -8,7 +8,7 @@ use Test::More;
 BEGIN {
        eval { require Test::WWW::Mechanize::Catalyst; require Catalyst::Plugin::Session; require Catalyst::Plugin::Session::State::Cookie };
        plan skip_all => "This test needs Test::WWW::Mechanize::Catalyst, Catalyst::Plugin::Session and Catalyst::Plugin::Session::State::Cookie installed" if $@;
-       plan tests => 14;
+       plan tests => 20;
 }
 
 use lib 't/lib';
@@ -19,3 +19,5 @@ my $m = Test::WWW::Mechanize::Catalyst->new;
 $m->get_ok("http://localhost/moose", "get ok");
 $m->get_ok("http://localhost/elk", "get ok");
 $m->get_ok("http://localhost/fluffy_bunny", "get ok");
+$m->get_ok("http://localhost/possum", "get ok");
+$m->get_ok("http://localhost/butterfly", "get ok");