This is an automated email from the git hooks/post-receive script. dmn pushed a commit to branch dam-bundle-2.0 in repository libcatalyst-modules-perl.
commit b9f1c45203d35db537b700c983ed0972a9fd098b Author: Damyan Ivanov <d...@debian.org> Date: Thu May 8 13:54:59 2014 +0000 Update Catalyst-Plugin-Session to 0.39 --- sources/Catalyst-Plugin-Session/Changes | 13 ++- sources/Catalyst-Plugin-Session/MANIFEST | 3 + sources/Catalyst-Plugin-Session/META.yml | 3 +- sources/Catalyst-Plugin-Session/Makefile.PL | 1 + sources/Catalyst-Plugin-Session/README | 16 ++- .../lib/Catalyst/Plugin/Session.pm | 117 ++++++++++++++++----- sources/Catalyst-Plugin-Session/t/01_setup.t | 2 +- .../Catalyst-Plugin-Session/t/lib/SessionExpiry.pm | 21 ++++ .../t/lib/SessionExpiry/Controller/Root.pm | 28 +++++ .../t/lib/SessionTestApp.pm | 1 - .../t/live_expiry_threshold.t | 81 ++++++++++++++ 11 files changed, 253 insertions(+), 33 deletions(-) diff --git a/sources/Catalyst-Plugin-Session/Changes b/sources/Catalyst-Plugin-Session/Changes index 60ce0ef..5a3e222 100644 --- a/sources/Catalyst-Plugin-Session/Changes +++ b/sources/Catalyst-Plugin-Session/Changes @@ -1,7 +1,18 @@ Revision history for Perl extension Catalyst::Plugin::Session +0.39 2013-10-16 + - Fixed a bug when "expiry_threshold" is non-zero, where changes to the + session were not saved. + +0.38 2013-09-18 + - New feature: "expiry_threshold" which allows you more control over when + this plugin checks and updates the expiration date for the session. + This is useful when you have high traffic and need to reduce the number + of session expiration hits (like if you are using a database for sessions + and your db is getting pounded). + 0.37 2013-02-25 - - Fix t/live_verify_address.t to skip of Catalyst::Plugin::Authentication + - Fix t/live_verify_address.t to skip if Catalyst::Plugin::Authentication is not installed, fixing RT#81506. 0.36 2012-10-19 diff --git a/sources/Catalyst-Plugin-Session/MANIFEST b/sources/Catalyst-Plugin-Session/MANIFEST index 31e1066..252c5d5 100644 --- a/sources/Catalyst-Plugin-Session/MANIFEST +++ b/sources/Catalyst-Plugin-Session/MANIFEST @@ -27,12 +27,15 @@ t/author/podcoverage.t t/cat_test.t t/lib/FlashTestApp.pm t/lib/FlashTestApp/Controller/Root.pm +t/lib/SessionExpiry.pm +t/lib/SessionExpiry/Controller/Root.pm t/lib/SessionTestApp.pm t/lib/SessionTestApp/Controller/Root.pm t/lib/SessionValid.pm t/lib/SessionValid/Controller/Root.pm t/live_accessor.t t/live_app.t +t/live_expiry_threshold.t t/live_session_fixation.t t/live_verify_address.t t/live_verify_user_agent.t diff --git a/sources/Catalyst-Plugin-Session/META.yml b/sources/Catalyst-Plugin-Session/META.yml index 41085d3..86459e0 100644 --- a/sources/Catalyst-Plugin-Session/META.yml +++ b/sources/Catalyst-Plugin-Session/META.yml @@ -26,6 +26,7 @@ requires: Digest: 0 File::Spec: 0 File::Temp: 0 + List::Util: 0 MRO::Compat: 0 Moose: 0.76 MooseX::Emulate::Class::Accessor::Fast: 0.00801 @@ -37,4 +38,4 @@ requires: resources: license: http://dev.perl.org/licenses/ repository: git://git.shadowcat.co.uk/catagits/Catalyst-Plugin-Session.git -version: 0.37 +version: 0.39 diff --git a/sources/Catalyst-Plugin-Session/Makefile.PL b/sources/Catalyst-Plugin-Session/Makefile.PL index 48798d6..a9beeef 100644 --- a/sources/Catalyst-Plugin-Session/Makefile.PL +++ b/sources/Catalyst-Plugin-Session/Makefile.PL @@ -18,6 +18,7 @@ requires 'namespace::clean' => '0.10'; requires 'Digest'; requires 'File::Spec'; requires 'File::Temp'; +requires 'List::Util'; requires 'Object::Signature'; requires 'MRO::Compat'; requires 'MooseX::Emulate::Class::Accessor::Fast' => '0.00801'; diff --git a/sources/Catalyst-Plugin-Session/README b/sources/Catalyst-Plugin-Session/README index c563395..4e48ad0 100644 --- a/sources/Catalyst-Plugin-Session/README +++ b/sources/Catalyst-Plugin-Session/README @@ -355,15 +355,25 @@ CONFIGURATION The time-to-live of each session, expressed in seconds. Defaults to 7200 (two hours). + expiry_threshold + Only update the session expiry time if it would otherwise expire + within this many seconds from now. + + The purpose of this is to keep the session store from being updated + when nothing else in the session is updated. + + Defaults to 0 (in which case, the expiration will always be + updated). + verify_address - When true, "<$c-"request->address>> will be checked at prepare time. + When true, "$c->request->address" will be checked at prepare time. If it is not the same as the address that initiated the session, the session is deleted. Defaults to false. verify_user_agent - When true, "<$c-"request->user_agent>> will be checked at prepare + When true, "$c->request->user_agent" will be checked at prepare time. If it is not the same as the user agent that initiated the session, the session is deleted. @@ -457,6 +467,8 @@ AUTHORS Contributors Devin Austin (dhoss) <dh...@cpan.org> + Robert Rothenberg <r...@cpan.org> (on behalf of Foxtons Ltd.) + COPYRIGHT & LICENSE Copyright (c) 2005 the aforementioned authors. All rights reserved. This program is free software; you can redistribute diff --git a/sources/Catalyst-Plugin-Session/lib/Catalyst/Plugin/Session.pm b/sources/Catalyst-Plugin-Session/lib/Catalyst/Plugin/Session.pm index 6173146..8733eb8 100644 --- a/sources/Catalyst-Plugin-Session/lib/Catalyst/Plugin/Session.pm +++ b/sources/Catalyst-Plugin-Session/lib/Catalyst/Plugin/Session.pm @@ -10,10 +10,11 @@ use Digest (); use overload (); use Object::Signature (); use Carp; +use List::Util qw/ max /; use namespace::clean -except => 'meta'; -our $VERSION = '0.37'; +our $VERSION = '0.39'; $VERSION = eval $VERSION; my @session_data_accessors; # used in delete_session @@ -80,6 +81,7 @@ sub setup_session { expires => 7200, verify_address => 0, verify_user_agent => 0, + expiry_threshold => 0, %$cfg, ); @@ -136,6 +138,27 @@ sub finalize_session { $c->_clear_session_instance_data; } +sub _session_updated { + my $c = shift; + + if ( my $session_data = $c->_session ) { + + no warnings 'uninitialized'; + if ( Object::Signature::signature($session_data) ne + $c->_session_data_sig ) + { + return $session_data; + } else { + return; + } + + } else { + + return; + + } +} + sub _save_session_id { my $c = shift; @@ -147,26 +170,27 @@ sub _save_session_expires { my $c = shift; if ( defined($c->_session_expires) ) { - my $expires = $c->session_expires; # force extension - my $sid = $c->sessionid; - $c->store_session_data( "expires:$sid" => $expires ); + if (my $sid = $c->sessionid) { + + my $current = $c->_get_stored_session_expires; + my $extended = $c->session_expires; + if ($extended > $current) { + $c->store_session_data( "expires:$sid" => $extended ); + } + + } } } sub _save_session { my $c = shift; - if ( my $session_data = $c->_session ) { + if ( my $session_data = $c->_session_updated ) { - no warnings 'uninitialized'; - if ( Object::Signature::signature($session_data) ne - $c->_session_data_sig ) - { - $session_data->{__updated} = time(); - my $sid = $c->sessionid; - $c->store_session_data( "session:$sid" => $session_data ); - } + $session_data->{__updated} = time(); + my $sid = $c->sessionid; + $c->store_session_data( "session:$sid" => $session_data ); } } @@ -203,7 +227,7 @@ sub _load_session_expires { $c->_tried_loading_session_expires(1); if ( my $sid = $c->sessionid ) { - my $expires = $c->get_session_data("expires:$sid") || 0; + my $expires = $c->_get_stored_session_expires; if ( $expires >= time() ) { $c->_session_expires( $expires ); @@ -361,9 +385,32 @@ sub session_expires { sub extend_session_expires { my ( $c, $expires ) = @_; - $c->_extended_session_expires( my $updated = $c->calculate_initial_session_expires( $expires ) ); - $c->extend_session_id( $c->sessionid, $updated ); - return $updated; + + my $threshold = $c->_session_plugin_config->{expiry_threshold} || 0; + + if ( my $sid = $c->sessionid ) { + my $expires = $c->_get_stored_session_expires; + my $cutoff = $expires - $threshold; + + if (!$threshold || $cutoff <= time || $c->_session_updated) { + + $c->_extended_session_expires( my $updated = $c->calculate_initial_session_expires() ); + $c->extend_session_id( $sid, $updated ); + + return $updated; + + } else { + + return $expires; + + } + + } else { + + return; + + } + } sub change_session_expires { @@ -375,20 +422,24 @@ sub change_session_expires { $c->store_session_data( "expires:$sid" => $time_exp ); } +sub _get_stored_session_expires { + my ($c) = @_; + + if ( my $sid = $c->sessionid ) { + return $c->get_session_data("expires:$sid") || 0; + } else { + return 0; + } +} + sub initial_session_expires { my $c = shift; return ( time() + $c->_session_plugin_config->{expires} ); } sub calculate_initial_session_expires { - my $c = shift; - - my $initial_expires = $c->initial_session_expires; - my $stored_session_expires = 0; - if ( my $sid = $c->sessionid ) { - $stored_session_expires = $c->get_session_data("expires:$sid") || 0; - } - return ( $initial_expires > $stored_session_expires ) ? $initial_expires : $stored_session_expires; + my ($c) = @_; + return max( $c->initial_session_expires, $c->_get_stored_session_expires ); } sub calculate_extended_session_expires { @@ -1043,16 +1094,26 @@ C<Plugin::Session> key in the configuration hash. The time-to-live of each session, expressed in seconds. Defaults to 7200 (two hours). +=item expiry_threshold + +Only update the session expiry time if it would otherwise expire +within this many seconds from now. + +The purpose of this is to keep the session store from being updated +when nothing else in the session is updated. + +Defaults to 0 (in which case, the expiration will always be updated). + =item verify_address -When true, C<<$c->request->address>> will be checked at prepare time. If it is +When true, C<< $c->request->address >> will be checked at prepare time. If it is not the same as the address that initiated the session, the session is deleted. Defaults to false. =item verify_user_agent -When true, C<<$c->request->user_agent>> will be checked at prepare time. If it +When true, C<< $c->request->user_agent >> will be checked at prepare time. If it is not the same as the user agent that initiated the session, the session is deleted. @@ -1177,6 +1238,8 @@ And countless other contributers from #catalyst. Thanks guys! Devin Austin (dhoss) <dh...@cpan.org> +Robert Rothenberg <r...@cpan.org> (on behalf of Foxtons Ltd.) + =head1 COPYRIGHT & LICENSE Copyright (c) 2005 the aforementioned authors. All rights diff --git a/sources/Catalyst-Plugin-Session/t/01_setup.t b/sources/Catalyst-Plugin-Session/t/01_setup.t index 6ade1d4..a75ea93 100644 --- a/sources/Catalyst-Plugin-Session/t/01_setup.t +++ b/sources/Catalyst-Plugin-Session/t/01_setup.t @@ -65,7 +65,7 @@ is( $calls, 0, "no fatal error logged either" ); cmp_deeply( [ keys %{ $config{'Plugin::Session'} } ], - bag(qw/expires verify_address verify_user_agent/), + bag(qw/expires verify_address verify_user_agent expiry_threshold/), "default values for config were populated in successful setup", ); diff --git a/sources/Catalyst-Plugin-Session/t/lib/SessionExpiry.pm b/sources/Catalyst-Plugin-Session/t/lib/SessionExpiry.pm new file mode 100644 index 0000000..3397a7d --- /dev/null +++ b/sources/Catalyst-Plugin-Session/t/lib/SessionExpiry.pm @@ -0,0 +1,21 @@ +package SessionExpiry; +use Catalyst + qw/Session Session::Store::Dummy Session::State::Cookie Authentication/; + +use strict; +use warnings; + +__PACKAGE__->config( + 'Plugin::Session' => { + + expires => 20, + expiry_threshold => 10, + + }, + +); + +__PACKAGE__->setup; + +__PACKAGE__; + diff --git a/sources/Catalyst-Plugin-Session/t/lib/SessionExpiry/Controller/Root.pm b/sources/Catalyst-Plugin-Session/t/lib/SessionExpiry/Controller/Root.pm new file mode 100644 index 0000000..e23cd12 --- /dev/null +++ b/sources/Catalyst-Plugin-Session/t/lib/SessionExpiry/Controller/Root.pm @@ -0,0 +1,28 @@ +package SessionExpiry::Controller::Root; +use strict; +use warnings; + +use base qw/Catalyst::Controller/; + +__PACKAGE__->config( namespace => '' ); + +sub session_data_expires : Global { + my ( $self, $c ) = @_; + $c->session; + if (my $sid = $c->sessionid) { + $c->finalize_headers(); # force expiration to be updated + $c->res->output($c->get_session_data("expires:$sid")); + } +} + +sub session_expires : Global { + my ($self, $c) = @_; + $c->session; + $c->res->output($c->session_expires); +} + +sub update_session : Global { + my ($self, $c) = @_; + $c->session->{foo} ++; + $c->res->output($c->session->{foo}); +} diff --git a/sources/Catalyst-Plugin-Session/t/lib/SessionTestApp.pm b/sources/Catalyst-Plugin-Session/t/lib/SessionTestApp.pm index f569aaa..d2a0f77 100644 --- a/sources/Catalyst-Plugin-Session/t/lib/SessionTestApp.pm +++ b/sources/Catalyst-Plugin-Session/t/lib/SessionTestApp.pm @@ -10,7 +10,6 @@ __PACKAGE__->config('Plugin::Session' => { # needed for live_verify_user_agent.t; should be harmless for other tests verify_user_agent => 1, verify_address => 1, - }, 'Plugin::Authentication' => { diff --git a/sources/Catalyst-Plugin-Session/t/live_expiry_threshold.t b/sources/Catalyst-Plugin-Session/t/live_expiry_threshold.t new file mode 100644 index 0000000..75beb64 --- /dev/null +++ b/sources/Catalyst-Plugin-Session/t/live_expiry_threshold.t @@ -0,0 +1,81 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; + +BEGIN { + eval { require Catalyst::Plugin::Session::State::Cookie; Catalyst::Plugin::Session::State::Cookie->VERSION(0.03) } + or plan skip_all => + "Catalyst::Plugin::Session::State::Cookie 0.03 or higher is required for this test"; + + eval { + require Test::WWW::Mechanize::Catalyst; + Test::WWW::Mechanize::Catalyst->VERSION(0.51); + } + or plan skip_all => + 'Test::WWW::Mechanize::Catalyst >= 0.51 is required for this test'; +} + +use lib "t/lib"; +use Test::WWW::Mechanize::Catalyst "SessionExpiry"; + +my $ua = Test::WWW::Mechanize::Catalyst->new; + +my $res = $ua->get( "http://localhost/session_data_expires" ); +ok($res->is_success, "session_data_expires"); + +my $expiry = $res->decoded_content + 0; + +$res = $ua->get( "http://localhost/session_expires" ); +ok($res->is_success, "session_expires"); +is($res->decoded_content, $expiry, "session_expires == session_data_expires"); + +sleep(1); + +$res = $ua->get( "http://localhost/session_data_expires" ); +ok($res->is_success, "session_data_expires"); + +is($res->decoded_content, $expiry, "expiration not updated"); + +$res = $ua->get( "http://localhost/session_expires" ); +ok($res->is_success, "session_expires"); +is($res->decoded_content, $expiry, "session_expires == session_data_expires"); + +# + +$res = $ua->get( "http://localhost/update_session" ); +ok($res->is_success, "update_session"); + +$res = $ua->get( "http://localhost/session_data_expires" ); +ok($res->is_success, "session_data_expires"); + +my $updated = $res->decoded_content + 0; +ok($updated > $expiry, "expiration updated"); + +$expiry = $updated; + +$res = $ua->get( "http://localhost/session_data_expires" ); +ok($res->is_success, "session_data_expires"); + +is($res->decoded_content, $expiry, "expiration not updated"); + +$res = $ua->get( "http://localhost/session_expires" ); +ok($res->is_success, "session_expires"); +is($res->decoded_content, $expiry, "session_expires == session_data_expires"); + +sleep(10); + +$res = $ua->get( "http://localhost/session_data_expires" ); +ok($res->is_success, "session_data_expires"); + +$updated = $res->decoded_content + 0; +ok($updated > $expiry, "expiration updated"); + +$res = $ua->get( "http://localhost/session_expires" ); +ok($res->is_success, "session_expires"); +is($res->decoded_content, $updated, "session_expires == session_data_expires"); + + +done_testing; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatalyst-modules-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits