From: Gerda Shank Date: Fri, 25 May 2012 18:24:28 +0000 (-0400) Subject: add some tests to t/cat_test.t X-Git-Tag: 0.36~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Session.git;a=commitdiff_plain;h=71bde3b4ab4e43c0e14ec29cd5c13df87d9692db add some tests to t/cat_test.t --- diff --git a/t/cat_test.t b/t/cat_test.t index 7175b1d..8fedd89 100644 --- a/t/cat_test.t +++ b/t/cat_test.t @@ -26,11 +26,23 @@ is($res->code, 200, 'succeeded'); my $cookie = $res->header('Set-Cookie'); ok($cookie, 'Have a cookie'); -# check that the cookie has not been reset by the get +# cookie is changed by the get +sleep(1); ($res, $c) = ctx_request(GET 'http://localhost/page', Cookie => $cookie); -like($c->res->body, qr/logged in/, 'Am logged in'); +like($c->res->body, qr/logged in/, 'logged in'); my $new_cookie = $res->header('Set-Cookie'); -is( $cookie, $new_cookie, 'cookie is the same' ); +isnt( $cookie, $new_cookie, 'cookie expires has been updated' ); + +# request with no cookie +($res, $c) = ctx_request(GET 'http://localhost/page' ); +like($c->res->body, 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, $c) = ctx_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) diff --git a/t/lib/SessionTestApp/Controller/Root.pm b/t/lib/SessionTestApp/Controller/Root.pm index a6d86d1..0afc633 100644 --- a/t/lib/SessionTestApp/Controller/Root.pm +++ b/t/lib/SessionTestApp/Controller/Root.pm @@ -127,4 +127,10 @@ sub change_session_expires : Global { $c->res->output($c->session_expires); } +sub reset_session_expires : Global { + my ($self, $c) = @_; + $c->reset_session_expires; + $c->res->output($c->session_expires); +} + 1;