Added tests for expiry threshold
Robert Rothenberg [Thu, 12 Sep 2013 16:30:57 +0000 (17:30 +0100)]
t/lib/SessionTestApp.pm
t/lib/SessionTestApp/Controller/Root.pm
t/live_expiry_threshold.t [new file with mode: 0644]

index f569aaa..0a93392 100644 (file)
@@ -11,6 +11,9 @@ __PACKAGE__->config('Plugin::Session' => {
         verify_user_agent => 1,
         verify_address => 1,
 
+        expires => 20,
+        expiry_threshold => 10,
+
     },
 
     'Plugin::Authentication' => {
index 0afc633..9a38bc8 100644 (file)
@@ -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 (file)
index 0000000..9d4fcf5
--- /dev/null
@@ -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;