Test for ningu's bug
[catagits/Catalyst-Plugin-Authentication.git] / t / live_app.t
CommitLineData
b003080b 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use 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");
b003080b 29
22be989b 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;
b003080b 36 ok(!$c->user, "no more user, after logout");
37
22be989b 38
b003080b 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";
22be989b 51
36d8ef79 52 $c->res->body( "ok" );
b003080b 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
72use Catalyst::Test qw/AuthTestApp/;
73
36d8ef79 74ok( get("/moose"), "get ok");