Support e.g. ->roles in User::Hash if set appropriately
[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
30                 ok( !$c->user->roles, "no roles for foo" );
31                 my @new = qw/foo bar gorch/;
32                 $c->user->roles( @new );
33                 is_deeply( [ $c->user->roles ], \@new, "roles set as array");
34
35                 $c->logout;
36                 ok(!$c->user, "no more user, after logout");
37
38
39                 ok($c->login( "bar", "s3cr3t" ), "can login with crypted");
40                 is( $c->user, $users->{bar}, "user object is in proper place");
41                 $c->logout;
42
43                 ok($c->login("gorch", "s3cr3t"), "can login with hashed");
44                 is( $c->user, $users->{gorch}, "user object is in proper place");
45                 $c->logout;
46
47                 ok(!$c->login( "bar", "bad pass" ), "can't login with bad password");
48                 ok(!$c->user, "no user");
49
50                 throws_ok { $c->login( "baz", "foo" ) } qr/support.*mechanism/, "can't login without any supported mech";
51
52                 
53         }
54
55         __PACKAGE__->config->{authentication}{users} = $users = {
56                 foo => {
57                         password => "s3cr3t",
58                 },
59                 bar => {
60                         crypted_password => crypt("s3cr3t", "x8"),
61                 },
62                 gorch => {
63                         hashed_password => md5("s3cr3t"),
64                         hash_algorithm => "MD5",
65                 },
66                 baz => {},
67         };
68
69         __PACKAGE__->setup;
70 }
71
72 use Catalyst::Test qw/AuthTestApp/;
73
74 get("/moose");