Commit | Line | Data |
ad93b3e9 |
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 | |
3581e90f |
20 | eval { require Catalyst::Plugin::Session; |
ad93b3e9 |
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 | |
f26005a7 |
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 | |
ad93b3e9 |
30 | plan tests => 8; |
31 | |
b4319877 |
32 | use TestApp; |
33 | TestApp->config( { |
ad93b3e9 |
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', |
f55cb81e |
46 | 'user_model' => 'TestApp::User', |
f26005a7 |
47 | 'use_userdata_from_session' => 0, |
ad93b3e9 |
48 | }, |
49 | }, |
50 | }, |
51 | }, |
b4319877 |
52 | } ); |
ad93b3e9 |
53 | |
b4319877 |
54 | TestApp->setup( |
ad93b3e9 |
55 | qw/Authentication |
56 | Session |
57 | Session::Store::Dummy |
58 | Session::State::Cookie |
59 | / |
b4319877 |
60 | ); |
ad93b3e9 |
61 | } |
62 | |
ad93b3e9 |
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 | } |