9 use lib "$FindBin::Bin/lib";
12 eval { require DBD::SQLite }
14 "DBD::SQLite is required for this test";
16 eval { require DBIx::Class }
18 "DBIx::Class is required for this test";
20 eval { require Catalyst::Plugin::Authorization::Roles }
22 "Catalyst::Plugin::Authorization::Roles is required for this test";
26 $ENV{TESTAPP_DB_FILE} = "$FindBin::Bin/auth.db" unless exists($ENV{TESTAPP_DB_FILE});
29 $ENV{TESTAPP_CONFIG} = {
32 default_realm => "users",
36 'class' => "Password",
37 'password_field' => 'password',
38 'password_type' => 'clear'
42 'user_class' => 'User',
43 'role_relation' => 'roles',
44 'role_field' => 'role'
51 $ENV{TESTAPP_PLUGINS} = [
60 use Catalyst::Test 'TestApp';
62 # test user's admin access
64 ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin'), 'request ok' );
65 is( $res->content, 'ok', 'user is an admin' );
68 # test unauthorized user's admin access
70 ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin'), 'request ok' );
71 is( $res->content, 'failed', 'user is not an admin' );
74 # test multiple auth roles
76 ok( my $res = request('http://localhost/user_login?username=jayk&password=letmein&detach=is_admin_user'), 'request ok' );
77 is( $res->content, 'ok', 'user is an admin and a user' );
80 # test multiple unauth roles
82 ok( my $res = request('http://localhost/user_login?username=nuffin&password=much&detach=is_admin_user'), 'request ok' );
83 is( $res->content, 'failed', 'user is not an admin and a user' );
87 unlink $ENV{TESTAPP_DB_FILE};