9 eval { require Test::WWW::Mechanize::Catalyst; require Catalyst::Plugin::Session; require Catalyst::Plugin::Session::State::Cookie };
10 plan skip_all => "This test needs Test::WWW::Mechanize::Catalyst, Catalyst::Plugin::Session and Catalyst::Plugin::Session::State::Cookie installed" if $@;
15 package User::SessionRestoring;
16 use base qw/Catalyst::Plugin::Authentication::User::Hash/;
18 sub for_session { $_[0]->id }
19 sub store { $_[0]->{store} }
25 Session::State::Cookie
28 Authentication::Store::Minimal
29 Authentication::Credential::Password
35 use Digest::MD5 qw/md5/;
40 my ( $self, $c ) = @_;
42 ok(!$c->sessionid, "no session id yet");
43 ok(!$c->user_exists, "no user exists");
44 ok(!$c->user, "no user yet");
45 ok($c->login( "foo", "s3cr3t" ), "can login with clear");
46 is( $c->user, $users->{foo}, "user object is in proper place");
50 my ( $self, $c ) = @_;
52 ok( $c->sessionid, "session ID was restored" );
53 ok( $c->user_exists, "user exists" );
54 ok( $c->user, "a user was also restored");
55 is_deeply( $c->user, $users->{foo}, "restored user is the right one (deep test - store might change identity)" );
57 $c->delete_session("bah");
60 sub fluffy_bunny : Local {
61 my ( $self, $c ) = @_;
63 ok( !$c->sessionid, "no session ID was restored");
64 ok( !$c->user, "no user was restored");
67 __PACKAGE__->config->{authentication}{users} = $users = {
68 foo => User::SessionRestoring->new(
76 $users->{foo}{store} = __PACKAGE__->default_auth_store;
79 use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/; # for the cookie support
81 my $m = Test::WWW::Mechanize::Catalyst->new;
83 $m->get_ok("http://localhost/moose", "get ok");
84 $m->get_ok("http://localhost/elk", "get ok");
85 $m->get_ok("http://localhost/fluffy_bunny", "get ok");