6 use HTTP::Request::Common;
12 # this test was copied from CatalystX::SimpleLogin
15 plan skip_all => "Need Catalyst::Plugin::Session::State::Cookie"
16 unless do { local $@; eval { require Catalyst::Plugin::Session::State::Cookie; } };
17 plan skip_all => "Need Catalyst::Plugin::Authentication"
18 unless do { local $@; eval { require Catalyst::Plugin::Authentication; } };
21 use Catalyst::Test 'SessionTestApp';
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');
29 # cookie is changed by the get
31 ($res, $c) = ctx_request(GET 'http://localhost/page', Cookie => $cookie);
32 like($c->res->body, qr/logged in/, 'logged in');
33 my $new_cookie = $res->header('Set-Cookie');
34 isnt( $cookie, $new_cookie, 'cookie expires has been updated' );
36 # request with no cookie
37 ($res, $c) = ctx_request(GET 'http://localhost/page' );
38 like($c->res->body, qr/please login/, 'not logged in');
39 $new_cookie = $res->header('Set-Cookie');
40 ok( ! defined $new_cookie, 'no cookie created' );
42 # check that cookie is reset by reset_session_expires
43 ($res, $c) = ctx_request(GET 'http://localhost/reset_session_expires', Cookie => $cookie);
44 my $reset_cookie = $res->header('Set-Cookie');
45 isnt( $cookie, $reset_cookie, 'Cookie has been changed by reset_session' );
47 # this checks that cookie exists after a logout and redirect
48 # Catalyst::Plugin::Authentication removes the user session (remove_persisted_user)
49 ($res, $c) = ctx_request(GET 'http://localhost/logout_redirect', Cookie => $cookie);
50 is($res->code, 302, 'redirected');
51 is($res->header('Location'), 'http://localhost/from_logout_redirect', 'Redirected after logout_redirect');
52 ok($res->header('Set-Cookie'), 'Cookie is there after redirect');