Commit | Line | Data |
ff817455 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | |
8 | BEGIN { |
9 | eval { require Catalyst::Plugin::Session; require Catalyst::Plugin::Session::State::Cookie }; |
0c4ddd06 |
10 | plan skip_all => "This test needs Catalyst::Plugin::Session and Catalyst::Plugin::Session::State::Cookie installed" if $@; |
11 | plan tests => 12; |
ff817455 |
12 | } |
13 | |
14 | { |
c4d560a5 |
15 | package User::SessionRestoring; |
16 | use base qw/Catalyst::Plugin::Authentication::User::Hash/; |
17 | |
18 | sub for_session { $_[0]->id } |
19 | |
ff817455 |
20 | package AuthTestApp; |
21 | use Catalyst qw/ |
22 | Session |
23 | Session::Store::Dummy |
24 | Session::State::Cookie |
25 | |
26 | Authentication |
27 | Authentication::Store::Minimal |
28 | Authentication::Credential::Password |
29 | /; |
30 | |
31 | use Test::More; |
32 | use Test::Exception; |
33 | |
34 | use Digest::MD5 qw/md5/; |
35 | |
36 | our $users; |
37 | |
38 | sub moose : Local { |
39 | my ( $self, $c ) = @_; |
40 | |
41 | ok(!$c->sessionid, "no session id yet"); |
42 | ok(!$c->user, "no user yet"); |
43 | ok($c->login( "foo", "s3cr3t" ), "can login with clear"); |
44 | is( $c->user, $users->{foo}, "user object is in proper place"); |
45 | } |
46 | |
47 | sub elk : Local { |
48 | my ( $self, $c ) = @_; |
49 | |
50 | ok( $c->sessionid, "session ID was restored" ); |
51 | ok( $c->user, "a user was also restored"); |
52 | is_deeply( $c->user, $users->{foo}, "restored user is the right one (deep test - store might change identity)" ); |
53 | |
54 | $c->delete_session("bah"); |
55 | } |
56 | |
57 | sub fluffy_bunny : Local { |
58 | my ( $self, $c ) = @_; |
59 | |
60 | ok( !$c->sessionid, "no session ID was restored"); |
61 | ok( !$c->user, "no user was restored"); |
62 | } |
63 | |
64 | __PACKAGE__->config->{authentication}{users} = $users = { |
c4d560a5 |
65 | foo => User::SessionRestoring->new( |
66 | id => 'foo', |
ff817455 |
67 | password => "s3cr3t", |
c4d560a5 |
68 | ), |
ff817455 |
69 | }; |
70 | |
71 | __PACKAGE__->setup; |
c4d560a5 |
72 | |
73 | $users->{foo}{store} = __PACKAGE__->default_auth_store; |
ff817455 |
74 | } |
75 | |
76 | use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/; # for the cookie support |
77 | |
78 | my $m = Test::WWW::Mechanize::Catalyst->new; |
79 | |
80 | $m->get_ok("http://localhost/moose", "get ok"); |
81 | $m->get_ok("http://localhost/elk", "get ok"); |
82 | $m->get_ok("http://localhost/fluffy_bunny", "get ok"); |
83 | |