Commit | Line | Data |
81703a24 |
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 | |
16 | eval { require DBIx::Class } |
17 | or plan skip_all => |
18 | "DBIx::Class is required for this test"; |
19 | |
20 | eval { require Catalyst::Plugin::Authorization::Roles } |
21 | or plan skip_all => |
22 | "Catalyst::Plugin::Authorization::Roles is required for this test"; |
23 | |
24 | plan tests => 8; |
25 | |
b4319877 |
26 | use TestApp; |
27 | TestApp->config( { |
81703a24 |
28 | name => 'TestApp', |
29 | 'Plugin::Authentication' => { |
30 | default => { |
31 | class => 'SimpleDB', |
32 | user_model => 'TestApp::User', |
c388ac9d |
33 | password_type => 'clear' |
81703a24 |
34 | } |
35 | } |
b4319877 |
36 | } ); |
81703a24 |
37 | |
b4319877 |
38 | TestApp->setup( |
81703a24 |
39 | qw/Authentication |
40 | Authorization::Roles |
41 | / |
b4319877 |
42 | ); |
81703a24 |
43 | } |
44 | |
81703a24 |
45 | use Catalyst::Test 'TestApp'; |
46 | |
47 | # test user's admin access |
48 | { |
49 | ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' ); |
50 | is( $res->content, 'ok', 'user is an admin' ); |
51 | } |
52 | |
53 | # test unauthorized user's admin access |
54 | { |
55 | ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin'), 'request ok' ); |
56 | is( $res->content, 'failed', 'user is not an admin' ); |
57 | } |
58 | |
59 | # test multiple auth roles |
60 | { |
61 | ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin_user'), 'request ok' ); |
62 | is( $res->content, 'ok', 'user is an admin and a user' ); |
63 | } |
64 | |
65 | # test multiple unauth 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, 'failed', 'user is not an admin and a user' ); |
69 | } |