Commit | Line | Data |
ff4277c9 |
1 | package AuthRealmTestApp::Controller::Root; |
2 | use warnings; |
3 | use strict; |
4 | use base qw/Catalyst::Controller/; |
5 | |
6 | __PACKAGE__->config(namespace => ''); |
7 | |
8 | use Test::More; |
9 | use Test::Exception; |
10 | |
11 | sub moose : Local { |
12 | my ( $self, $c ) = @_; |
13 | |
14 | ok(!$c->user, "no user"); |
15 | |
16 | while ( my ($user, $info) = each %$AuthRealmTestApp::members ) { |
17 | |
18 | ok( |
19 | $c->authenticate( |
20 | { username => $user, password => $info->{password} }, |
21 | 'members' |
22 | ), |
23 | "user $user authentication" |
24 | ); |
25 | |
26 | # check existing realms |
27 | ok( $c->user_in_realm('members'), "user in members realm"); |
28 | ok(!$c->user_in_realm('admins'), "user not in admins realm"); |
29 | |
30 | # check an invalid realm |
31 | ok(!$c->user_in_realm('foobar'), "user not in foobar realm"); |
32 | |
33 | # check if we've got the right user |
34 | is( $c->user, $info, "user object is in proper place"); |
35 | |
36 | $c->logout; |
37 | |
38 | # sanity check |
39 | ok(!$c->user, "no more user after logout"); |
40 | |
41 | } |
42 | |
43 | while ( my ($user, $info) = each %$AuthRealmTestApp::admins ) { |
44 | |
45 | ok( |
46 | $c->authenticate( |
47 | { username => $user, password => $info->{password} }, |
48 | 'admins' |
49 | ), |
50 | "user $user authentication" |
51 | ); |
52 | |
53 | # check existing realms |
54 | ok(!$c->user_in_realm('members'), "user not in members realm"); |
55 | ok( $c->user_in_realm('admins'), "user in admins realm"); |
56 | |
57 | # check an invalid realm |
58 | ok(!$c->user_in_realm('foobar'), "user not in foobar realm"); |
59 | |
60 | # check if we've got the right user |
61 | is( $c->user, $info, "user object is in proper place"); |
62 | |
63 | $c->logout; |
64 | |
65 | # sanity check |
66 | ok(!$c->user, "no more user after logout"); |
67 | |
68 | } |
69 | |
70 | $c->res->body( "ok" ); |
71 | } |
72 | |
73 | 1; |
74 | |