Fix RT#82944
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / 09-simpledb-auth-roles-column.t
CommitLineData
81703a24 1#!perl
2
3use strict;
4use warnings;
5use DBI;
6use File::Path;
7use FindBin;
8use Test::More;
9use lib "$FindBin::Bin/lib";
10
11BEGIN {
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 role_column => 'role_text',
34 password_type => 'clear'
81703a24 35 }
36 }
3581e90f 37
b4319877 38 } );
81703a24 39
b4319877 40 TestApp->setup(
81703a24 41 qw/Authentication
42 Authorization::Roles
43 /
b4319877 44 );
81703a24 45}
46
81703a24 47use 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}