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