add SameSite support
[catagits/Catalyst-Plugin-Session-State-Cookie.git] / t / live_app.t
CommitLineData
db1cda22 1use strict;
2use warnings;
3
602b9593 4use FindBin qw/$Bin/;
5use lib "$Bin/lib";
6
db1cda22 7use Test::More;
8
9BEGIN {
10 eval { require Test::WWW::Mechanize::Catalyst };
11 plan skip_all =>
12 "This test requires Test::WWW::Mechanize::Catalyst in order to run"
13 if $@;
c4a96adb 14 plan skip_all => 'Test::WWW::Mechanize::Catalyst >= 0.40 required' if $Test::WWW::Mechanize::Catalyst::VERSION < 0.40;
db1cda22 15 plan 'no_plan';
16}
17
db1cda22 18use Test::WWW::Mechanize::Catalyst qw/CookieTestApp/;
19
20my $m = Test::WWW::Mechanize::Catalyst->new;
21
a79a56a8 22$m->get_ok( "http://localhost/stream", "get page" );
58730edc 23$m->content_contains( "hit number 1", "session data created" );
db1cda22 24
25my $expired;
c4a96adb 26$m->cookie_jar->scan( sub { $expired = $_[8]; } );
db1cda22 27
a79a56a8 28$m->get_ok( "http://localhost/page", "get page" );
58730edc 29$m->content_contains( "hit number 2", "session data restored" );
db1cda22 30
a79a56a8 31$m->get_ok( "http://localhost/stream", "get stream" );
58730edc 32$m->content_contains( "hit number 3", "session data restored" );
db1cda22 33
a79a56a8 34sleep 1;
db1cda22 35
9013c08b 36$m->get_ok( "http://localhost/stream", "get page" );
58730edc 37$m->content_contains( "hit number 4", "session data restored" );
db1cda22 38
39my $updated_expired;
c4a96adb 40$m->cookie_jar->scan( sub { $updated_expired = $_[8]; } );
58730edc 41cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended" );
dbec0a9d 42
9013c08b 43$expired = $m->cookie_jar->scan( sub { $expired = $_[8] } );
44$m->get_ok( "http://localhost/page", "get page again");
45$m->content_contains( "hit number 5", "session data restored (blah)" );
46
47sleep 1;
48
49$m->get_ok( "http://localhost/stream", "get stream" );
50$m->content_contains( "hit number 6", "session data restored" );
51
52$m->cookie_jar->scan( sub { $updated_expired = $_[8]; } );
53cmp_ok( $expired, "<", $updated_expired, "streaming also extends cookie" );
54
a79a56a8 55$m->get_ok( "http://localhost/deleteme", "get page" );
dbec0a9d 56$m->content_is( 1, 'session id changed' );
6a9ca807 57
58$m->get_ok( "https://localhost/page", "get page over HTTPS - init session");
59$m->content_contains( "hit number 1", "first hit" );
60$m->get_ok( "http://localhost/page", "get page again over HTTP");
61$m->content_contains( "hit number 1", "first hit again - cookie not sent" );
62$m->get_ok( "https://localhost/page", "get page over HTTPS");
63$m->content_contains( "hit number 2", "second hit" );