relax dep requirements
[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
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 'Plugin::Authentication' => {
32 default => {
33 class => 'SimpleDB',
34 user_model => 'TestApp::User',
c388ac9d 35 role_column => 'role_text',
36 password_type => 'clear'
81703a24 37 }
38 }
39
40 };
41
42 $ENV{TESTAPP_PLUGINS} = [
43 qw/Authentication
44 Authorization::Roles
45 /
46 ];
47}
48
49use SetupDB;
50
51use Catalyst::Test 'TestApp';
52
53# test user's admin access
54{
55 ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin'), 'request ok' );
56 is( $res->content, 'ok', 'user is an admin' );
57}
58
59# test unauthorized user's admin access
60{
61 ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
62 is( $res->content, 'failed', 'user is not an admin' );
63}
64
65# test multiple auth roles
66{
67 ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' );
68 is( $res->content, 'ok', 'user is an admin and a user' );
69}
70
71# test multiple unauth roles
72{
73 ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin_user'), 'request ok' );
74 is( $res->content, 'failed', 'user is not an admin and a user' );
75}
76
77# clean up
78unlink $ENV{TESTAPP_DB_FILE};