-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcat_test.t
48 lines (37 loc) · 1.63 KB
/
cat_test.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use strict;
use warnings;
use Test::Needs {
'Catalyst::Plugin::Authentication' => '0',
'Catalyst::Plugin::Session::State::Cookie' => '0.03',
};
use Test::More;
use HTTP::Request::Common;
use lib "t/lib";
use Catalyst::Test 'SessionTestApp';
my $res;
$res = request(POST 'http://localhost/login', [username => 'bob', password => 's00p3r', remember => 1]);
is($res->code, 200, 'succeeded');
my $cookie = $res->header('Set-Cookie');
ok($cookie, 'Have a cookie');
# cookie is changed by the get
sleep(1);
$res = request(GET 'http://localhost/page', Cookie => $cookie);
like($res->content, qr/logged in/, 'logged in');
my $new_cookie = $res->header('Set-Cookie');
isnt( $cookie, $new_cookie, 'cookie expires has been updated' );
# request with no cookie
$res = request(GET 'http://localhost/page' );
like($res->content, qr/please login/, 'not logged in');
$new_cookie = $res->header('Set-Cookie');
ok( ! defined $new_cookie, 'no cookie created' );
# check that cookie is reset by reset_session_expires
$res = request(GET 'http://localhost/reset_session_expires', Cookie => $cookie);
my $reset_cookie = $res->header('Set-Cookie');
isnt( $cookie, $reset_cookie, 'Cookie has been changed by reset_session' );
# this checks that cookie exists after a logout and redirect
# Catalyst::Plugin::Authentication removes the user session (remove_persisted_user)
$res = request(GET 'http://localhost/logout_redirect', Cookie => $cookie);
is($res->code, 302, 'redirected');
is($res->header('Location'), 'http://localhost/from_logout_redirect', 'Redirected after logout_redirect');
ok($res->header('Set-Cookie'), 'Cookie is there after redirect');
done_testing;