Revision history for Perl extension Catalyst::Plugin::Authentication
+0.100092_01 - UNRELEASED
- Add hook for failing user restore.
+ - Add test for this.
- Fix bug in Credential::Password with password_type: clear.
- Add test for this.
- Add mock object tests for Credential::Password with password_type:
using the response from $self->user_is_restorable(); Uses $self->from_session()
to decode the frozen user.
+=head2 failed_user_restore($c)
+
+If there is a session to restore, but the restore fails for any reason then this method
+is called. This method supplied just removes the persisted user, but can be overridden
+if required to have more complex logic (e.g. finding a the user by their 'old' username).
=head2 from_session($c, $frozenuser )
use base qw/Class::Accessor::Fast Class::Data::Inheritable/;
-BEGIN {
- __PACKAGE__->mk_accessors(qw/_user/);
-}
+__PACKAGE__->mk_accessors(qw/_user/);
use strict;
use warnings;
use Class::Inspector;
use Catalyst::Authentication::Realm;
-our $VERSION = "0.100092";
+our $VERSION = "0.100092_01";
sub set_authenticated {
my ( $c, $user, $realmname ) = @_;
$c->_user( my $user = $realm->restore_user( $c, $frozen_user ) );
# this sets the realm the user originated in.
- $user->auth_realm($realm->name);
+ $user->auth_realm($realm->name) if $user;
return $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)" );
-
+
+ # Rename the user!
+ $users->{bar} = delete $users->{foo};
+}
+
+sub yak : Local {
+ my ( $self, $c ) = @_;
+ ok( $c->sessionid, "session ID was restored after user renamed" );
+ ok( $c->user_exists, "user appears to exist" );
+ ok( !$c->user, "try to restore - user was not restored");
+ ok( !$c->user_exists, "user no longer appears to exist" );
+}
+
+sub goat : Local {
+ my ( $self, $c ) = @_;
+ ok($c->login( "bar", "s3cr3t" ), "can login with clear (new username)");
+ is( $c->user, $users->{bar}, "user object is in proper place");
$c->logout;
}
sub fluffy_bunny : Local {
- my ( $self, $c ) = @_;
+ my ( $self, $c ) = @_;
- ok( $c->session_is_valid, "no session ID was restored");
- ok( !$c->user, "no user was restored");
+ ok( $c->session_is_valid, "session ID is restored after logout");
+ ok( !$c->user, "no user was restored after logout");
$c->delete_session("bah");
}
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 => 20;
+ plan tests => 28;
}
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/yak", "get ok");
+$m->get_ok("http://localhost/goat", "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");