added role self_check and self_check_any to User store
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / 05-auth-roles-relationship.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
ad93b3e9 16 eval { require Catalyst::Plugin::Authorization::Roles }
17 or plan skip_all =>
18 "Catalyst::Plugin::Authorization::Roles is required for this test";
19
b3c995e9 20 plan tests => 10;
ad93b3e9 21
b4319877 22 use TestApp;
23 TestApp->config( {
ad93b3e9 24 name => 'TestApp',
25 authentication => {
26 default_realm => "users",
27 realms => {
28 users => {
29 credential => {
30 'class' => "Password",
31 'password_field' => 'password',
32 'password_type' => 'clear'
33 },
34 store => {
35 'class' => 'DBIx::Class',
f55cb81e 36 'user_model' => 'TestApp::User',
ad93b3e9 37 'role_relation' => 'roles',
38 'role_field' => 'role'
39 },
40 },
41 },
42 },
b4319877 43 } );
ad93b3e9 44
b4319877 45 TestApp->setup(
ad93b3e9 46 qw/Authentication
47 Authorization::Roles
48 /
b4319877 49 );
ad93b3e9 50}
51
ad93b3e9 52use Catalyst::Test 'TestApp';
53
54# test user's admin access
55{
56 ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
57 is( $res->content, 'ok', 'user is an admin' );
58}
59
60# test unauthorized user's admin access
61{
62 ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin'), 'request ok' );
63 is( $res->content, 'failed', 'user is not an admin' );
64}
65
66# test multiple auth roles
67{
68 ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin_user'), 'request ok' );
69 is( $res->content, 'ok', 'user is an admin and a user' );
70}
71
72# test multiple unauth roles
73{
74 ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' );
75 is( $res->content, 'failed', 'user is not an admin and a user' );
76}
b3c995e9 77
78# test superuser role override fails (not enabled)
79{
80 ok( my $res = request('http://localhost/user_login?username=mark&password=secret&detach=is_admin'), 'request ok' );
81 is( $res->content, 'failed', 'user is not an admin' );
82}