Fix RT#82944
[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
b4319877 26 use TestApp;
27 TestApp->config( {
ad93b3e9 28 name => 'TestApp',
29 authentication => {
30 default_realm => "users",
31 realms => {
32 users => {
33 credential => {
34 'class' => "Password",
35 'password_field' => 'password',
36 'password_type' => 'clear'
37 },
38 store => {
39 'class' => 'DBIx::Class',
f55cb81e 40 'user_model' => 'TestApp::User',
ad93b3e9 41 'role_column' => 'role_text'
42 },
43 },
44 },
45 },
b4319877 46 } );
ad93b3e9 47
b4319877 48 TestApp->setup(
ad93b3e9 49 qw/Authentication
50 Authorization::Roles
51 /
b4319877 52 );
ad93b3e9 53}
54
ad93b3e9 55use Catalyst::Test 'TestApp';
56
57# test user's admin access
58{
59 ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin'), 'request ok' );
60 is( $res->content, 'ok', 'user is an admin' );
61}
62
63# test unauthorized user's admin access
64{
65 ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
66 is( $res->content, 'failed', 'user is not an admin' );
67}
68
69# test multiple auth roles
70{
71 ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' );
72 is( $res->content, 'ok', 'user is an admin and a user' );
73}
74
75# test multiple unauth roles
76{
77 ok( my $res = request('http://localhost/user_login?username=joeuser&password=hackme&detach=is_admin_user'), 'request ok' );
78 is( $res->content, 'failed', 'user is not an admin and a user' );
79}