X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Session-State-Cookie.git;a=blobdiff_plain;f=t%2Flive_app.t;h=a1039567de01fdf1a39d2ee4f469889be819144b;hp=9ef202e8c72287d59b94cdedce02c49dd6979b0c;hb=6a9ca807fd875bab160038c420728cbc839ce04f;hpb=c4a96adb1d059b734eec945989d48ee54fb0676e diff --git a/t/live_app.t b/t/live_app.t index 9ef202e..a103956 100644 --- a/t/live_app.t +++ b/t/live_app.t @@ -3,6 +3,9 @@ use strict; use warnings; +use FindBin qw/$Bin/; +use lib "$Bin/lib"; + use Test::More; BEGIN { @@ -14,38 +17,6 @@ BEGIN { plan 'no_plan'; } -{ - - package CookieTestApp; - use Catalyst qw/ - Session - Session::Store::Dummy - Session::State::Cookie - /; - - sub page : Local { - my ( $self, $c ) = @_; - $c->res->body( "Hi! hit number " . ++$c->session->{counter} ); - } - - sub stream : Local { - my ( $self, $c ) = @_; - my $count = ++$c->session->{counter}; - $c->res->write("hit number "); - $c->res->write($count); - } - - sub deleteme : Local { - my ( $self, $c ) = @_; - my $id = $c->get_session_id; - $c->delete_session; - my $id2 = $c->get_session_id; - $c->res->body( $id ne ( $id2 || '' ) ); - } - - __PACKAGE__->setup; -} - use Test::WWW::Mechanize::Catalyst qw/CookieTestApp/; my $m = Test::WWW::Mechanize::Catalyst->new; @@ -64,13 +35,31 @@ $m->content_contains( "hit number 3", "session data restored" ); sleep 1; -$m->get_ok( "http://localhost/page", "get stream" ); +$m->get_ok( "http://localhost/stream", "get page" ); $m->content_contains( "hit number 4", "session data restored" ); my $updated_expired; $m->cookie_jar->scan( sub { $updated_expired = $_[8]; } ); - cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended" ); +$expired = $m->cookie_jar->scan( sub { $expired = $_[8] } ); +$m->get_ok( "http://localhost/page", "get page again"); +$m->content_contains( "hit number 5", "session data restored (blah)" ); + +sleep 1; + +$m->get_ok( "http://localhost/stream", "get stream" ); +$m->content_contains( "hit number 6", "session data restored" ); + +$m->cookie_jar->scan( sub { $updated_expired = $_[8]; } ); +cmp_ok( $expired, "<", $updated_expired, "streaming also extends cookie" ); + $m->get_ok( "http://localhost/deleteme", "get page" ); $m->content_is( 1, 'session id changed' ); + +$m->get_ok( "https://localhost/page", "get page over HTTPS - init session"); +$m->content_contains( "hit number 1", "first hit" ); +$m->get_ok( "http://localhost/page", "get page again over HTTP"); +$m->content_contains( "hit number 1", "first hit again - cookie not sent" ); +$m->get_ok( "https://localhost/page", "get page over HTTPS"); +$m->content_contains( "hit number 2", "second hit" );