added role self_check and self_check_any to User store
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / 08-simpledb-auth-roles-relationship.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
81703a24 16 eval { require Catalyst::Plugin::Authorization::Roles }
17 or plan skip_all =>
18 "Catalyst::Plugin::Authorization::Roles is required for this test";
19
20 plan tests => 8;
21
b4319877 22 use TestApp;
23 TestApp->config( {
81703a24 24 name => 'TestApp',
25 'Plugin::Authentication' => {
26 default => {
27 class => 'SimpleDB',
28 user_model => 'TestApp::User',
c388ac9d 29 password_type => 'clear'
81703a24 30 }
31 }
b4319877 32 } );
81703a24 33
b4319877 34 TestApp->setup(
81703a24 35 qw/Authentication
36 Authorization::Roles
37 /
b4319877 38 );
81703a24 39}
40
81703a24 41use Catalyst::Test 'TestApp';
42
43# test user's admin access
44{
45 ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
46 is( $res->content, 'ok', 'user is an admin' );
47}
48
49# test unauthorized user's admin access
50{
51 ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin'), 'request ok' );
52 is( $res->content, 'failed', 'user is not an admin' );
53}
54
55# test multiple auth roles
56{
57 ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin_user'), 'request ok' );
58 is( $res->content, 'ok', 'user is an admin and a user' );
59}
60
61# test multiple unauth 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, 'failed', 'user is not an admin and a user' );
65}