typo in exception line. fixed
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / 06-auth-roles-column.t
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
26     $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db" unless exists($ENV{TESTAPP_DB_FILE});
27
28
29     $ENV{TESTAPP_CONFIG} = {
30         name => 'TestApp',
31         authentication => {
32             default_realm => "users",
33             realms => {
34                 users => {
35                     credential => {
36                         'class' => "Password",
37                         'password_field' => 'password',
38                         'password_type' => 'clear'
39                     },
40                     store => {
41                         'class' => 'DBIx::Class',
42                         'user_class' => 'TestApp::User',
43                         'role_column' => 'role_text'
44                     },
45                 },
46             },
47         },
48     };
49
50     $ENV{TESTAPP_PLUGINS} = [
51         qw/Authentication
52            Authorization::Roles
53            /
54     ];
55 }
56
57 use SetupDB;
58
59 use Catalyst::Test 'TestApp';
60
61 # test user's admin access
62 {
63     ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin'), 'request ok' );
64     is( $res->content, 'ok', 'user is an admin' );
65 }
66
67 # test unauthorized user's admin access
68 {
69     ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
70     is( $res->content, 'failed', 'user is not an admin' );
71 }
72
73 # test multiple auth roles
74 {
75     ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' );
76     is( $res->content, 'ok', 'user is an admin and a user' );
77 }
78
79 # test multiple unauth roles
80 {
81     ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin_user'), 'request ok' );
82     is( $res->content, 'failed', 'user is not an admin and a user' );
83 }
84
85 # clean up
86 unlink $ENV{TESTAPP_DB_FILE};