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