Fix calling User->can() as a class method. RT#90715
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / 09-simpledb-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         'Plugin::Authentication' => {
30             default => {
31                                 class => 'SimpleDB',
32                                 user_model => 'TestApp::User',
33                                 role_column => 'role_text',
34                                 password_type => 'clear'
35                         }
36                 }
37
38     } );
39
40     TestApp->setup(
41         qw/Authentication
42            Authorization::Roles
43            /
44     );
45 }
46
47 use Catalyst::Test 'TestApp';
48
49 # test user's admin access
50 {
51     ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin'), 'request ok' );
52     is( $res->content, 'ok', 'user is an admin' );
53 }
54
55 # test unauthorized user's admin access
56 {
57     ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
58     is( $res->content, 'failed', 'user is not an admin' );
59 }
60
61 # test multiple auth roles
62 {
63     ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' );
64     is( $res->content, 'ok', 'user is an admin and a user' );
65 }
66
67 # test multiple unauth roles
68 {
69     ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin_user'), 'request ok' );
70     is( $res->content, 'failed', 'user is not an admin and a user' );
71 }