Commit | Line | Data |
ad93b3e9 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use DBI; |
6 | use File::Path; |
7 | use FindBin; |
8 | use Test::More; |
9 | use lib "$FindBin::Bin/lib"; |
10 | |
11 | BEGIN { |
12 | eval { require DBD::SQLite } |
13 | or plan skip_all => |
14 | "DBD::SQLite is required for this test"; |
15 | |
ad93b3e9 |
16 | eval { require Catalyst::Plugin::Authorization::Roles } |
17 | or plan skip_all => |
18 | "Catalyst::Plugin::Authorization::Roles is required for this test"; |
19 | |
b3c995e9 |
20 | plan tests => 10; |
ad93b3e9 |
21 | |
b4319877 |
22 | use TestApp; |
23 | TestApp->config( { |
ad93b3e9 |
24 | name => 'TestApp', |
25 | authentication => { |
26 | default_realm => "users", |
27 | realms => { |
28 | users => { |
29 | credential => { |
30 | 'class' => "Password", |
31 | 'password_field' => 'password', |
32 | 'password_type' => 'clear' |
33 | }, |
34 | store => { |
35 | 'class' => 'DBIx::Class', |
f55cb81e |
36 | 'user_model' => 'TestApp::User', |
ad93b3e9 |
37 | 'role_column' => 'role_text' |
38 | }, |
39 | }, |
40 | }, |
41 | }, |
b4319877 |
42 | } ); |
ad93b3e9 |
43 | |
b4319877 |
44 | TestApp->setup( |
ad93b3e9 |
45 | qw/Authentication |
46 | Authorization::Roles |
47 | / |
b4319877 |
48 | ); |
ad93b3e9 |
49 | } |
50 | |
ad93b3e9 |
51 | use Catalyst::Test 'TestApp'; |
52 | |
53 | # test user's admin access |
54 | { |
55 | ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin'), 'request ok' ); |
56 | is( $res->content, 'ok', 'user is an admin' ); |
57 | } |
58 | |
59 | # test unauthorized user's admin access |
60 | { |
61 | ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' ); |
62 | is( $res->content, 'failed', 'user is not an admin' ); |
63 | } |
64 | |
65 | # test multiple auth roles |
66 | { |
67 | ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' ); |
68 | is( $res->content, 'ok', 'user is an admin and a user' ); |
69 | } |
70 | |
71 | # test multiple unauth roles |
72 | { |
73 | ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin_user'), 'request ok' ); |
74 | is( $res->content, 'failed', 'user is not an admin and a user' ); |
75 | } |
b3c995e9 |
76 | |
77 | # test superuser role override fails (not enabled) |
78 | { |
79 | ok( my $res = request('http://localhost/user_login?username=graeme&password=supersecret&detach=is_admin'), 'request ok' ); |
80 | is( $res->content, 'failed', 'user is not an admin' ); |
81 | } |