Changing module naming from Catalyst::Plugin::Authentication to
[catagits/Catalyst-Plugin-Authentication.git] / t / lib / AuthTestApp.pm
CommitLineData
a3bf437a 1package AuthTestApp;
2use Catalyst qw/
3 Authentication
4 Authentication::Store::Minimal
5 Authentication::Credential::Password
6/;
7
8use Test::More;
9use Test::Exception;
10
11use Digest::MD5 qw/md5/;
12use Digest::SHA1 qw/sha1_base64/;
13
14our $users;
15
16sub moose : Local {
17 my ( $self, $c ) = @_;
18
19 ok(!$c->user, "no user");
20 ok($c->login( "foo", "s3cr3t" ), "can login with clear");
21 is( $c->user, $users->{foo}, "user object is in proper place");
22
23 ok( !$c->user->roles, "no roles for foo" );
24 my @new = qw/foo bar gorch/;
25 $c->user->roles( @new );
26 is_deeply( [ $c->user->roles ], \@new, "roles set as array");
27
28 $c->logout;
29 ok(!$c->user, "no more user, after logout");
30
31 ok($c->login( "bar", "s3cr3t" ), "can login with crypted");
32 is( $c->user, $users->{bar}, "user object is in proper place");
33 $c->logout;
34
35 ok($c->login("gorch", "s3cr3t"), "can login with hashed");
36 is( $c->user, $users->{gorch}, "user object is in proper place");
37 $c->logout;
38
39 ok($c->login("shabaz", "s3cr3t"), "can login with base64 hashed");
40 is( $c->user, $users->{shabaz}, "user object is in proper place");
41 $c->logout;
42
43 ok($c->login("sadeek", "s3cr3t"), "can login with padded base64 hashed");
44 is( $c->user, $users->{sadeek}, "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 $c->res->body( "ok" );
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 shabaz => {
67 hashed_password => sha1_base64("s3cr3t"),
68 hash_algorithm => "SHA-1"
69 },
70 sadeek => {
71 hashed_password => sha1_base64("s3cr3t").'=',
72 hash_algorithm => "SHA-1"
73 },
74 baz => {},
75};
76
77__PACKAGE__->setup;