Fix calling User->can() as a class method. RT#90715
[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     use TestApp;
27     TestApp->config( {
28         name => 'TestApp',
29         authentication => {
30             default_realm => "users",
31             realms => {
32                 users => {
33                     credential => {
34                         'class' => "Password",
35                         'password_field' => 'password',
36                         'password_type' => 'clear'
37                     },
38                     store => {
39                         'class' => 'DBIx::Class',
40                         'user_model' => 'TestApp::User',
41                         'role_column' => 'role_text'
42                     },
43                 },
44             },
45         },
46     } );
47
48     TestApp->setup(
49         qw/Authentication
50            Authorization::Roles
51            /
52     );
53 }
54
55 use Catalyst::Test 'TestApp';
56
57 # test user's admin access
58 {
59     ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin'), 'request ok' );
60     is( $res->content, 'ok', 'user is an admin' );
61 }
62
63 # test unauthorized user's admin access
64 {
65     ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
66     is( $res->content, 'failed', 'user is not an admin' );
67 }
68
69 # test multiple auth roles
70 {
71     ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' );
72     is( $res->content, 'ok', 'user is an admin and a user' );
73 }
74
75 # test multiple unauth roles
76 {
77     ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin_user'), 'request ok' );
78     is( $res->content, 'failed', 'user is not an admin and a user' );
79 }