8802f04d4341eff5e7fc87b865c09ecdb39f4184
[catagits/Catalyst-Plugin-Authentication.git] / t / live_app.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More 'no_plan';
7
8 {
9         package AuthTestApp;
10         use Catalyst qw/
11                 Authentication
12                 Authentication::Store::Minimal
13                 Authentication::Credential::Password
14         /;
15
16         use Test::More;
17         use Test::Exception;
18
19         use Digest::MD5 qw/md5/;
20
21         our $users;
22
23         sub moose : Local {
24                 my ( $self, $c ) = @_;
25
26                 ok(!$c->user, "no user");
27                 ok($c->login( "foo", "s3cr3t" ), "can login with clear");
28                 is( $c->user, $users->{foo}, "user object is in proper place");
29                 $c->logout;
30
31                 ok(!$c->user, "no more user, after logout");
32
33                 ok($c->login( "bar", "s3cr3t" ), "can login with crypted");
34                 is( $c->user, $users->{bar}, "user object is in proper place");
35                 $c->logout;
36
37                 ok($c->login("gorch", "s3cr3t"), "can login with hashed");
38                 is( $c->user, $users->{gorch}, "user object is in proper place");
39                 $c->logout;
40
41                 ok(!$c->login( "bar", "bad pass" ), "can't login with bad password");
42                 ok(!$c->user, "no user");
43
44                 throws_ok { $c->login( "baz", "foo" ) } qr/support.*mechanism/, "can't login without any supported mech";
45         }
46
47         __PACKAGE__->config->{authentication}{users} = $users = {
48                 foo => {
49                         password => "s3cr3t",
50                 },
51                 bar => {
52                         crypted_password => crypt("s3cr3t", "x8"),
53                 },
54                 gorch => {
55                         hashed_password => md5("s3cr3t"),
56                         hash_algorithm => "MD5",
57                 },
58                 baz => {},
59         };
60
61         __PACKAGE__->setup;
62 }
63
64 use Catalyst::Test qw/AuthTestApp/;
65
66 get("/moose");