4 Authentication::Store::Minimal
5 Authentication::Credential::Password
11 use Digest::MD5 qw/md5/;
12 use Digest::SHA1 qw/sha1_base64/;
16 sub number_of_elements { return scalar @_ }
19 my ( $self, $c ) = @_;
21 is(number_of_elements($c->user), 1, "Array undef");
22 is($c->user, undef, "no user, returns undef");
23 ok(!$c->user, "no user");
24 ok($c->login( "foo", "s3cr3t" ), "can login with clear");
25 is( $c->user, $users->{foo}, "user object is in proper place");
27 ok( !$c->user->roles, "no roles for foo" );
28 my @new = qw/foo bar gorch/;
29 $c->user->roles( @new );
30 is_deeply( [ $c->user->roles ], \@new, "roles set as array");
33 ok(!$c->user, "no more user, after logout");
35 ok($c->login( "bar", "s3cr3t" ), "can login with crypted");
36 is( $c->user, $users->{bar}, "user object is in proper place");
39 ok($c->login("gorch", "s3cr3t"), "can login with hashed");
40 is( $c->user, $users->{gorch}, "user object is in proper place");
43 ok($c->login("shabaz", "s3cr3t"), "can login with base64 hashed");
44 is( $c->user, $users->{shabaz}, "user object is in proper place");
47 ok($c->login("sadeek", "s3cr3t"), "can login with padded base64 hashed");
48 is( $c->user, $users->{sadeek}, "user object is in proper place");
51 ok(!$c->login( "bar", "bad pass" ), "can't login with bad password");
52 ok(!$c->user, "no user");
54 throws_ok { $c->login( "baz", "foo" ) } qr/support.*mechanism/, "can't login without any supported mech";
56 $c->res->body( "ok" );
59 __PACKAGE__->config->{'Plugin::Authentication'}{users} = $users = {
64 crypted_password => crypt("s3cr3t", "x8"),
67 hashed_password => md5("s3cr3t"),
68 hash_algorithm => "MD5",
71 hashed_password => sha1_base64("s3cr3t"),
72 hash_algorithm => "SHA-1"
75 hashed_password => sha1_base64("s3cr3t").'=',
76 hash_algorithm => "SHA-1"