Add a NoTabs test and make it pass.
[catagits/Catalyst-Plugin-Authentication.git] / t / lib / AuthTestApp / Controller / Root.pm
1 package AuthTestApp::Controller::Root;
2 use strict;
3 use warnings;
4 use base qw/ Catalyst::Controller /;
5
6 __PACKAGE__->config( namespace => '' );
7
8 use Test::More;
9 use Test::Exception;
10
11 use Digest::MD5 qw/md5/;
12 use Digest::SHA1 qw/sha1_base64/;
13
14 sub number_of_elements { return scalar @_ }
15
16 sub moose : Local {
17     my ( $self, $c ) = @_;
18
19     is(number_of_elements($c->user), 1, "Array undef");
20     is($c->user, undef, "no user, returns undef");
21     ok(!$c->user, "no user");
22     ok($c->login( "foo", "s3cr3t" ), "can login with clear");
23     is( $c->user, $AuthTestApp::users->{foo}, "user object is in proper place");
24
25     ok( !$c->user->roles, "no roles for foo" );
26     my @new = qw/foo bar gorch/;
27     $c->user->roles( @new );
28     is_deeply( [ $c->user->roles ], \@new, "roles set as array");
29
30     $c->logout;
31     ok(!$c->user, "no more user, after logout");
32
33     ok($c->login( "bar", "s3cr3t" ), "can login with crypted");
34     is( $c->user, $AuthTestApp::users->{bar}, "user object is in proper place");
35     $c->logout;
36
37     ok($c->login("gorch", "s3cr3t"), "can login with hashed");
38     is( $c->user, $AuthTestApp::users->{gorch}, "user object is in proper place");
39     $c->logout;
40
41     ok($c->login("shabaz", "s3cr3t"), "can login with base64 hashed");
42     is( $c->user, $AuthTestApp::users->{shabaz}, "user object is in proper place");
43     $c->logout;
44
45     ok($c->login("sadeek", "s3cr3t"), "can login with padded base64 hashed");
46     is( $c->user, $AuthTestApp::users->{sadeek}, "user object is in proper place");
47     $c->logout;
48
49     ok(!$c->login( "bar", "bad pass" ), "can't login with bad password");
50     ok(!$c->user, "no user");
51
52     throws_ok { $c->login( "baz", "foo" ) } qr/support.*mechanism/, "can't login without any supported mech";
53
54     $c->res->body( "ok" );
55 }
56
57