added role self_check and self_check_any to User store
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / 07-authsessions-cached.t
1 #!perl
2
3 use strict;
4 use warnings;
5 use DBI;
6 use File::Path;
7 use FindBin;
8 use Test::More;
9 use lib "$FindBin::Bin/lib";
10
11 BEGIN {
12     eval { require Test::WWW::Mechanize::Catalyst }
13       or plan skip_all =>
14       "Test::WWW::Mechanize::Catalyst is required for this test";
15
16     eval { require DBD::SQLite }
17         or plan skip_all =>
18         "DBD::SQLite is required for this test";
19
20     eval { require Catalyst::Plugin::Session;
21            die unless $Catalyst::Plugin::Session::VERSION >= 0.02 }
22         or plan skip_all =>
23         "Catalyst::Plugin::Session >= 0.02 is required for this test";
24
25     eval { require Catalyst::Plugin::Session::State::Cookie; }
26         or plan skip_all =>
27         "Catalyst::Plugin::Session::State::Cookie is required for this test";
28
29
30     plan tests => 8;
31
32     use TestApp;
33     TestApp->config( {
34         name => 'TestApp',
35         authentication => {
36             default_realm => "users",
37             realms => {
38                 users => {
39                     credential => {
40                         'class' => "Password",
41                         'password_field' => 'password',
42                         'password_type' => 'clear'
43                     },
44                     store => {
45                         'class' => 'DBIx::Class',
46                         'user_model' => 'TestApp::User',
47                         'use_userdata_from_session' => 1,
48                     },
49                 },
50             },
51         },
52     } );
53
54     TestApp->setup(
55         qw/Authentication
56            Session
57            Session::Store::Dummy
58            Session::State::Cookie
59            /
60     );
61 }
62
63 use Test::WWW::Mechanize::Catalyst 'TestApp';
64 my $m = Test::WWW::Mechanize::Catalyst->new;
65
66 # log a user in
67 {
68     $m->get_ok( 'http://localhost/user_login?username=joeuser&password=hackme', undef, 'request ok' );
69     $m->content_is( 'joeuser logged in', 'user logged in ok' );
70 }
71
72 # verify the user is still logged in
73 {
74     $m->get_ok( 'http://localhost/get_session_user', undef, 'request ok' );
75     $m->content_is( 'joeuser', 'user still logged in' );
76 }
77
78 # log the user out
79 {
80     $m->get_ok( 'http://localhost/user_logout', undef, 'request ok' );
81     $m->content_is( 'logged out', 'user logged out ok' );
82 }
83
84 # verify there is no session
85 {
86     $m->get_ok( 'http://localhost/get_session_user', undef, 'request ok' );
87     $m->content_is( '', "user's session deleted" );
88 }