From: Gerda Shank Date: Mon, 23 Apr 2012 14:26:35 +0000 (-0400) Subject: call 'extend_session_expires' in 'session_expires' X-Git-Tag: 0.35~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Session.git;a=commitdiff_plain;h=a2e23c04d0df1b54be769a9d7fcd974ab34b855f call 'extend_session_expires' in 'session_expires' --- diff --git a/Changes b/Changes index 1df0e8b..0ba5e52 100644 --- 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) diff --git a/lib/Catalyst/Plugin/Session.pm b/lib/Catalyst/Plugin/Session.pm index 908d14a..8c102dc 100644 --- a/lib/Catalyst/Plugin/Session.pm +++ b/lib/Catalyst/Plugin/Session.pm @@ -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). 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 index 0000000..19cec42 --- /dev/null +++ b/t/cat_test.t @@ -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; diff --git a/t/lib/SessionTestApp/Controller/Root.pm b/t/lib/SessionTestApp/Controller/Root.pm index 59559b9..37c1931 100644 --- a/t/lib/SessionTestApp/Controller/Root.pm +++ b/t/lib/SessionTestApp/Controller/Root.pm @@ -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;