Adding SimpleDB Realm to make basic configuration of DBIx::Class / Password
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / 06-auth-roles-column.t
CommitLineData
ad93b3e9 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 authentication => {
32 default_realm => "users",
33 realms => {
34 users => {
35 credential => {
36 'class' => "Password",
37 'password_field' => 'password',
38 'password_type' => 'clear'
39 },
40 store => {
41 'class' => 'DBIx::Class',
f55cb81e 42 'user_model' => 'TestApp::User',
ad93b3e9 43 'role_column' => 'role_text'
44 },
45 },
46 },
47 },
48 };
49
50 $ENV{TESTAPP_PLUGINS} = [
51 qw/Authentication
52 Authorization::Roles
53 /
54 ];
55}
56
57use SetupDB;
58
59use Catalyst::Test 'TestApp';
60
61# test user's admin access
62{
63 ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin'), 'request ok' );
64 is( $res->content, 'ok', 'user is an admin' );
65}
66
67# test unauthorized user's admin access
68{
69 ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
70 is( $res->content, 'failed', 'user is not an admin' );
71}
72
73# test multiple auth roles
74{
75 ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' );
76 is( $res->content, 'ok', 'user is an admin and a user' );
77}
78
79# test multiple unauth roles
80{
81 ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin_user'), 'request ok' );
82 is( $res->content, 'failed', 'user is not an admin and a user' );
83}
84
85# clean up
86unlink $ENV{TESTAPP_DB_FILE};