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;
}
}
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 ) = @_;
$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/};
}
}
}
+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 ) );
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 = {
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';
$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");