From: Yuval Kogman Date: Thu, 3 Nov 2005 15:41:21 +0000 (+0000) Subject: Add support for expiration of the cookie according to the session X-Git-Tag: v0.01~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Session-State-Cookie.git;a=commitdiff_plain;h=c3f2575c7016000e1693b29df140c51ba32e078a;hp=14e0914f2f0ebb963299b45f7de58c37dfb38ccf Add support for expiration of the cookie according to the session --- diff --git a/lib/Catalyst/Plugin/Session/State/Cookie.pm b/lib/Catalyst/Plugin/Session/State/Cookie.pm index 741925e..857e454 100644 --- a/lib/Catalyst/Plugin/Session/State/Cookie.pm +++ b/lib/Catalyst/Plugin/Session/State/Cookie.pm @@ -24,7 +24,10 @@ sub finalize { if ( my $sid = $c->sessionid ) { my $cookie = $c->request->cookies->{$cookie_name}; if ( !$cookie or $cookie->value ne $sid ) { - $c->response->cookies->{$cookie_name} = { value => $sid }; + $c->response->cookies->{$cookie_name} = { + value => $sid, + expires => $c->session->{__expires} + }; $c->log->debug(qq/A cookie with the session id "$sid" was saved/) if $c->debug; } diff --git a/t/basic.t b/t/basic.t index aa78b68..e0ca3b5 100644 --- a/t/basic.t +++ b/t/basic.t @@ -24,20 +24,20 @@ $res->set_always( cookies => \%res_cookies ); my $cxt = Test::MockObject::Extends->new("Catalyst::Plugin::Session::State::Cookie"); -$cxt->set_always( config => { } ); +$cxt->set_always( config => {} ); $cxt->set_always( request => $req ); $cxt->set_always( response => $res ); +$cxt->set_always( session => { __expires => 123 } ); $cxt->set_false("debug"); my $sessionid; $cxt->mock( sessionid => sub { shift; $sessionid = shift if @_; $sessionid } ); - can_ok( $m, "setup_session" ); $cxt->setup_session; -is( $cxt->config->{session}{cookie_name}, "session", "default cookie name is set" ); - +is( $cxt->config->{session}{cookie_name}, + "session", "default cookie name is set" ); can_ok( $m, "prepare_cookies" ); @@ -78,7 +78,7 @@ $cxt->finalize; $res->called_ok( "cookies", "response cookie was set when sessionid changed" ); is_deeply( \%res_cookies, - { session => { value => $sessionid } }, + { session => { value => $sessionid, expires => 123 } }, "cookie was set correctly" ); @@ -104,7 +104,7 @@ $res->called_ok( "cookies", "response cookie was set when session was created" ); is_deeply( \%res_cookies, - { session => { value => $sessionid } }, + { session => { value => $sessionid, expires => 123 } }, "cookie was set correctly" );