add some tests to t/cat_test.t
Gerda Shank [Fri, 25 May 2012 18:24:28 +0000 (14:24 -0400)]
t/cat_test.t
t/lib/SessionTestApp/Controller/Root.pm

index 7175b1d..8fedd89 100644 (file)
@@ -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)
index a6d86d1..0afc633 100644 (file)
@@ -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;