From: Robert Rothenberg Date: Thu, 12 Sep 2013 16:30:57 +0000 (+0100) Subject: Added tests for expiry threshold X-Git-Tag: 0.40~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Session.git;a=commitdiff_plain;h=0421e89a069209a4258a41e375de0209be4a51da Added tests for expiry threshold --- diff --git a/t/lib/SessionTestApp.pm b/t/lib/SessionTestApp.pm index f569aaa..0a93392 100644 --- a/t/lib/SessionTestApp.pm +++ b/t/lib/SessionTestApp.pm @@ -11,6 +11,9 @@ __PACKAGE__->config('Plugin::Session' => { verify_user_agent => 1, verify_address => 1, + expires => 20, + expiry_threshold => 10, + }, 'Plugin::Authentication' => { diff --git a/t/lib/SessionTestApp/Controller/Root.pm b/t/lib/SessionTestApp/Controller/Root.pm index 0afc633..9a38bc8 100644 --- a/t/lib/SessionTestApp/Controller/Root.pm +++ b/t/lib/SessionTestApp/Controller/Root.pm @@ -133,4 +133,13 @@ sub reset_session_expires : Global { $c->res->output($c->session_expires); } +sub get_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")); + } +} + 1; diff --git a/t/live_expiry_threshold.t b/t/live_expiry_threshold.t new file mode 100644 index 0000000..9d4fcf5 --- /dev/null +++ b/t/live_expiry_threshold.t @@ -0,0 +1,45 @@ +#!/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 "SessionTestApp"; + +my $ua = Test::WWW::Mechanize::Catalyst->new; + +my $res = $ua->get( "http://localhost/get_expires" ); +ok($res->is_success, "get expires"); + +my $expiry = $res->decoded_content; + +sleep(1); + +$res = $ua->get( "http://localhost/get_expires" ); +ok($res->is_success, "get expires"); + +is($res->decoded_content, $expiry, "expiration not updated"); + +sleep(10); + +$res = $ua->get( "http://localhost/get_expires" ); +ok($res->is_success, "get expires"); + +isnt($res->decoded_content, $expiry, "expiration updated"); + +done_testing;