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