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