Commit | Line | Data |
b003080b |
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/; |
fd5b31a0 |
20 | use Digest::SHA1 qw/sha1_base64/; |
b003080b |
21 | |
22 | our $users; |
23 | |
24 | sub moose : Local { |
25 | my ( $self, $c ) = @_; |
26 | |
27 | ok(!$c->user, "no user"); |
28 | ok($c->login( "foo", "s3cr3t" ), "can login with clear"); |
29 | is( $c->user, $users->{foo}, "user object is in proper place"); |
b003080b |
30 | |
22be989b |
31 | ok( !$c->user->roles, "no roles for foo" ); |
32 | my @new = qw/foo bar gorch/; |
33 | $c->user->roles( @new ); |
34 | is_deeply( [ $c->user->roles ], \@new, "roles set as array"); |
35 | |
36 | $c->logout; |
b003080b |
37 | ok(!$c->user, "no more user, after logout"); |
38 | |
22be989b |
39 | |
b003080b |
40 | ok($c->login( "bar", "s3cr3t" ), "can login with crypted"); |
41 | is( $c->user, $users->{bar}, "user object is in proper place"); |
42 | $c->logout; |
43 | |
44 | ok($c->login("gorch", "s3cr3t"), "can login with hashed"); |
45 | is( $c->user, $users->{gorch}, "user object is in proper place"); |
46 | $c->logout; |
47 | |
fd5b31a0 |
48 | ok($c->login("shabaz", "s3cr3t"), "can login with base64 hashed"); |
49 | is( $c->user, $users->{shabaz}, "user object is in proper place"); |
50 | $c->logout; |
51 | |
52 | ok($c->login("sadeek", "s3cr3t"), "can login with padded base64 hashed"); |
53 | is( $c->user, $users->{sadeek}, "user object is in proper place"); |
54 | $c->logout; |
55 | |
b003080b |
56 | ok(!$c->login( "bar", "bad pass" ), "can't login with bad password"); |
57 | ok(!$c->user, "no user"); |
58 | |
59 | throws_ok { $c->login( "baz", "foo" ) } qr/support.*mechanism/, "can't login without any supported mech"; |
22be989b |
60 | |
36d8ef79 |
61 | $c->res->body( "ok" ); |
b003080b |
62 | } |
63 | |
64 | __PACKAGE__->config->{authentication}{users} = $users = { |
65 | foo => { |
66 | password => "s3cr3t", |
67 | }, |
68 | bar => { |
69 | crypted_password => crypt("s3cr3t", "x8"), |
70 | }, |
71 | gorch => { |
72 | hashed_password => md5("s3cr3t"), |
73 | hash_algorithm => "MD5", |
74 | }, |
fd5b31a0 |
75 | shabaz => { |
76 | hashed_password => sha1_base64("s3cr3t"), |
77 | hash_algorithm => "SHA-1" |
78 | }, |
79 | sadeek => { |
80 | hashed_password => sha1_base64("s3cr3t").'=', |
81 | hash_algorithm => "SHA-1" |
82 | }, |
b003080b |
83 | baz => {}, |
84 | }; |
85 | |
86 | __PACKAGE__->setup; |
87 | } |
88 | |
89 | use Catalyst::Test qw/AuthTestApp/; |
90 | |
36d8ef79 |
91 | ok( get("/moose"), "get ok"); |