call 'extend_session_expires' in 'session_expires'
Gerda Shank [Mon, 23 Apr 2012 14:26:35 +0000 (10:26 -0400)]
Changes
lib/Catalyst/Plugin/Session.pm
t/cat_test.t [new file with mode: 0644]
t/lib/SessionTestApp/Controller/Root.pm

diff --git a/Changes b/Changes
index 1df0e8b..0ba5e52 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for Perl extension Catalyst::Plugin::Session
 
+        - Fixed bug from last version where session does not persist across a redirect
+
 0.34 2012-03-30
         - Fixed up t/live_verify_address.t per https://rt.cpan.org/Ticket/Display.html?id=71142
         - Merged in dpetrov's 0.32 changes (extend_session_expire)
index 908d14a..8c102dc 100644 (file)
@@ -351,7 +351,7 @@ sub session_expires {
     if ( defined( my $expires = $c->_extended_session_expires ) ) {
         return $expires;
     } elsif ( defined( $expires = $c->_load_session_expires ) ) {
-        return $c->calculate_initial_session_expires;
+        return $c->extend_session_expires( $expires );
     } else {
         return 0;
     }
@@ -707,16 +707,10 @@ hashref.
 
 =item session_expires
 
-=item session_expires $reset
-
 This method returns the time when the current session will expire, or 0 if
 there is no current session. If there is a session and it already expired, it
 will delete the session and return 0 as well.
 
-If the C<$reset> parameter is true, and there is a session ID the expiry time
-will be reset to the current time plus the time to live (see
-L</CONFIGURATION>). This is used when creating a new session.
-
 =item flash
 
 This is like Ruby on Rails' flash data structure. Think of it as a stash that
diff --git a/t/cat_test.t b/t/cat_test.t
new file mode 100644 (file)
index 0000000..19cec42
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More;
+use HTTP::Request::Common;
+
+# setup library path
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+
+use Catalyst::Test 'SessionTestApp';
+my ($res, $c);
+
+($res, $c) = ctx_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');
+
+# this checks that cookie persists across a redirect
+($res, $c) = ctx_request(GET 'http://localhost/logout_persist', Cookie => $cookie);
+is($res->code, 302, '/logout with cookie redirects');
+is($res->header('Location'), 'http://localhost/', 'Redirect to / after logout');
+ok($res->header('Set-Cookie'), 'Cookie is reset by /logout');
+
+done_testing;
index 59559b9..37c1931 100644 (file)
@@ -28,6 +28,12 @@ sub logout : Global {
     $c->delete_session("logout");
 }
 
+sub logout_persist : Global {
+    my ( $self, $c ) = @_;
+    # session is not deleted
+    $c->res->redirect( $c->uri_for('/') );
+}
+
 sub set_session_variable : Global {
     my ( $self, $c, $var, $val ) = @_;
     $c->session->{$var} = $val;