Commit | Line | Data |
a3bf437a |
1 | package User::SessionRestoring; |
5c5af345 |
2 | use base qw/Catalyst::Authentication::User::Hash/; |
a3bf437a |
3 | |
4 | sub for_session { $_[0]->id } |
5 | sub store { $_[0]->{store} } |
6 | |
7 | package AuthSessionTestApp; |
8 | use Catalyst qw/ |
9 | Session |
10 | Session::Store::Dummy |
11 | Session::State::Cookie |
12 | |
13 | Authentication |
14 | Authentication::Store::Minimal |
15 | Authentication::Credential::Password |
16 | /; |
17 | |
18 | use Test::More; |
19 | use Test::Exception; |
20 | |
21 | use Digest::MD5 qw/md5/; |
22 | |
23 | our $users; |
24 | |
25 | sub moose : Local { |
26 | my ( $self, $c ) = @_; |
27 | |
28 | ok(!$c->sessionid, "no session id yet"); |
29 | ok(!$c->user_exists, "no user exists"); |
30 | ok(!$c->user, "no user yet"); |
31 | ok($c->login( "foo", "s3cr3t" ), "can login with clear"); |
32 | is( $c->user, $users->{foo}, "user object is in proper place"); |
33 | } |
34 | |
35 | sub elk : Local { |
36 | my ( $self, $c ) = @_; |
37 | |
38 | ok( $c->sessionid, "session ID was restored" ); |
39 | ok( $c->user_exists, "user exists" ); |
40 | ok( $c->user, "a user was also restored"); |
41 | is_deeply( $c->user, $users->{foo}, "restored user is the right one (deep test - store might change identity)" ); |
9c469e37 |
42 | |
43 | # Rename the user! |
44 | $users->{bar} = delete $users->{foo}; |
45 | } |
46 | |
47 | sub yak : Local { |
48 | my ( $self, $c ) = @_; |
49 | ok( $c->sessionid, "session ID was restored after user renamed" ); |
50 | ok( $c->user_exists, "user appears to exist" ); |
eea5667a |
51 | ok( !$c->user, "user was not restored"); |
52 | ok(scalar(@{ $c->error }), 'Error recorded'); |
9c469e37 |
53 | ok( !$c->user_exists, "user no longer appears to exist" ); |
54 | } |
55 | |
56 | sub goat : Local { |
57 | my ( $self, $c ) = @_; |
58 | ok($c->login( "bar", "s3cr3t" ), "can login with clear (new username)"); |
59 | is( $c->user, $users->{bar}, "user object is in proper place"); |
47c6643f |
60 | $c->logout; |
a3bf437a |
61 | } |
62 | |
63 | sub fluffy_bunny : Local { |
9c469e37 |
64 | my ( $self, $c ) = @_; |
a3bf437a |
65 | |
9c469e37 |
66 | ok( $c->session_is_valid, "session ID is restored after logout"); |
67 | ok( !$c->user, "no user was restored after logout"); |
47c6643f |
68 | |
69 | $c->delete_session("bah"); |
70 | } |
71 | |
72 | sub possum : Local { |
73 | my ( $self, $c ) = @_; |
74 | |
75 | ok( !$c->session_is_valid, "no session ID was restored"); |
76 | $c->session->{definitely_not_a_user} = "moose"; |
77 | |
78 | } |
79 | |
80 | sub butterfly : Local { |
81 | my ( $self, $c ) = @_; |
82 | |
83 | ok( $c->session_is_valid, "valid session" ); |
84 | ok( !$c->user_exists, "but no user exists" ); |
85 | ok( !$c->user, "no user object either" ); |
a3bf437a |
86 | } |
87 | |
bf4d93a4 |
88 | __PACKAGE__->config->{'authentication'}{users} = $users = { |
a3bf437a |
89 | foo => User::SessionRestoring->new( |
90 | id => 'foo', |
91 | password => "s3cr3t", |
92 | ), |
93 | }; |
94 | |
95 | __PACKAGE__->setup; |
96 | |
97 | $users->{foo}{store} = __PACKAGE__->default_auth_store; |