[Catalyst-commits] r9220 - in trunk/Catalyst-Plugin-Authentication:
. lib/Catalyst/Authentication lib/Catalyst/Plugin t t/lib
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Thu Feb 5 21:43:52 GMT 2009
Author: t0m
Date: 2009-02-05 21:43:52 +0000 (Thu, 05 Feb 2009)
New Revision: 9220
Modified:
trunk/Catalyst-Plugin-Authentication/Changes
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Realm.pm
trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm
trunk/Catalyst-Plugin-Authentication/t/lib/AuthSessionTestApp.pm
trunk/Catalyst-Plugin-Authentication/t/live_app_session.t
Log:
Stop accidentally blowing up if we can't restore the user.. Add tests and docs for the new failed_user_restore functionality
Modified: trunk/Catalyst-Plugin-Authentication/Changes
===================================================================
--- trunk/Catalyst-Plugin-Authentication/Changes 2009-02-05 20:12:08 UTC (rev 9219)
+++ trunk/Catalyst-Plugin-Authentication/Changes 2009-02-05 21:43:52 UTC (rev 9220)
@@ -1,6 +1,8 @@
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:
Modified: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Realm.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Realm.pm 2009-02-05 20:12:08 UTC (rev 9219)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Authentication/Realm.pm 2009-02-05 21:43:52 UTC (rev 9220)
@@ -358,7 +358,12 @@
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 )
Decodes the frozenuser information provided and returns an instantiated
Modified: trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm 2009-02-05 20:12:08 UTC (rev 9219)
+++ trunk/Catalyst-Plugin-Authentication/lib/Catalyst/Plugin/Authentication.pm 2009-02-05 21:43:52 UTC (rev 9220)
@@ -2,9 +2,7 @@
use base qw/Class::Accessor::Fast Class::Data::Inheritable/;
-BEGIN {
- __PACKAGE__->mk_accessors(qw/_user/);
-}
+__PACKAGE__->mk_accessors(qw/_user/);
use strict;
use warnings;
@@ -13,7 +11,7 @@
use Class::Inspector;
use Catalyst::Authentication::Realm;
-our $VERSION = "0.100092";
+our $VERSION = "0.100092_01";
sub set_authenticated {
my ( $c, $user, $realmname ) = @_;
@@ -189,7 +187,7 @@
$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;
Modified: trunk/Catalyst-Plugin-Authentication/t/lib/AuthSessionTestApp.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/lib/AuthSessionTestApp.pm 2009-02-05 20:12:08 UTC (rev 9219)
+++ trunk/Catalyst-Plugin-Authentication/t/lib/AuthSessionTestApp.pm 2009-02-05 21:43:52 UTC (rev 9220)
@@ -39,15 +39,31 @@
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");
}
Modified: trunk/Catalyst-Plugin-Authentication/t/live_app_session.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication/t/live_app_session.t 2009-02-05 20:12:08 UTC (rev 9219)
+++ trunk/Catalyst-Plugin-Authentication/t/live_app_session.t 2009-02-05 21:43:52 UTC (rev 9220)
@@ -6,7 +6,7 @@
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';
@@ -16,6 +16,8 @@
$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");
More information about the Catalyst-commits
mailing list