Commit | Line | Data |
a2e23c04 |
1 | #!/usr/bin/env perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use Test::More; |
6 | use HTTP::Request::Common; |
7 | |
8 | # setup library path |
9 | use FindBin qw($Bin); |
10 | use lib "$Bin/lib"; |
11 | |
1b41775a |
12 | # this test was copied from CatalystX::SimpleLogin |
13 | |
f851ba4e |
14 | BEGIN { |
15 | plan skip_all => "Need Catalyst::Plugin::Session::State::Cookie" |
16 | unless do { local $@; eval { require Catalyst::Plugin::Session::State::Cookie; } }; |
1b41775a |
17 | plan skip_all => "Need Catalyst::Plugin::Authentication" |
18 | unless do { local $@; eval { require Catalyst::Plugin::Authentication; } }; |
f851ba4e |
19 | } |
20 | |
a2e23c04 |
21 | use Catalyst::Test 'SessionTestApp'; |
22 | my ($res, $c); |
23 | |
24 | ($res, $c) = ctx_request(POST 'http://localhost/login', [username => 'bob', password => 's00p3r', remember => 1]); |
25 | is($res->code, 200, 'succeeded'); |
26 | my $cookie = $res->header('Set-Cookie'); |
27 | ok($cookie, 'Have a cookie'); |
28 | |
1b41775a |
29 | # check that the cookie has not been reset by the get |
30 | ($res, $c) = ctx_request(GET 'http://localhost/page', Cookie => $cookie); |
31 | like($c->res->body, qr/logged in/, 'Am logged in'); |
32 | my $new_cookie = $res->header('Set-Cookie'); |
33 | is( $cookie, $new_cookie, 'cookie is the same' ); |
34 | |
35 | # this checks that cookie exists after a logout and redirect |
36 | # Catalyst::Plugin::Authentication removes the user session (remove_persisted_user) |
37 | ($res, $c) = ctx_request(GET 'http://localhost/logout_redirect', Cookie => $cookie); |
601be17a |
38 | is($res->code, 302, 'redirected'); |
1b41775a |
39 | is($res->header('Location'), 'http://localhost/from_logout_redirect', 'Redirected after logout_redirect'); |
40 | ok($res->header('Set-Cookie'), 'Cookie is there after redirect'); |
a2e23c04 |
41 | |
42 | done_testing; |