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 | { |
15 | package AuthTestApp; |
16 | use Catalyst qw/ |
17 | Session |
18 | Session::Store::Dummy |
19 | Session::State::Cookie |
20 | |
21 | Authentication |
22 | Authentication::Store::Minimal |
23 | Authentication::Credential::Password |
24 | /; |
25 | |
26 | use Test::More; |
27 | use Test::Exception; |
28 | |
29 | use Digest::MD5 qw/md5/; |
30 | |
31 | our $users; |
32 | |
33 | sub moose : Local { |
34 | my ( $self, $c ) = @_; |
35 | |
36 | ok(!$c->sessionid, "no session id yet"); |
37 | ok(!$c->user, "no user yet"); |
38 | ok($c->login( "foo", "s3cr3t" ), "can login with clear"); |
39 | is( $c->user, $users->{foo}, "user object is in proper place"); |
40 | } |
41 | |
42 | sub elk : Local { |
43 | my ( $self, $c ) = @_; |
44 | |
45 | ok( $c->sessionid, "session ID was restored" ); |
46 | ok( $c->user, "a user was also restored"); |
47 | is_deeply( $c->user, $users->{foo}, "restored user is the right one (deep test - store might change identity)" ); |
48 | |
49 | $c->delete_session("bah"); |
50 | } |
51 | |
52 | sub fluffy_bunny : Local { |
53 | my ( $self, $c ) = @_; |
54 | |
55 | ok( !$c->sessionid, "no session ID was restored"); |
56 | ok( !$c->user, "no user was restored"); |
57 | } |
58 | |
59 | __PACKAGE__->config->{authentication}{users} = $users = { |
60 | foo => { |
61 | password => "s3cr3t", |
62 | }, |
63 | }; |
64 | |
65 | __PACKAGE__->setup; |
66 | } |
67 | |
68 | use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/; # for the cookie support |
69 | |
70 | my $m = Test::WWW::Mechanize::Catalyst->new; |
71 | |
72 | $m->get_ok("http://localhost/moose", "get ok"); |
73 | $m->get_ok("http://localhost/elk", "get ok"); |
74 | $m->get_ok("http://localhost/fluffy_bunny", "get ok"); |
75 | |