d2b4ef92e3e3fa14c867579aa610e8cd635ab00c
[catagits/Catalyst-Plugin-Session-State-Cookie.git] / t / live_app.t
1 use strict;
2 use warnings;
3
4 use FindBin qw/$Bin/;
5 use lib "$Bin/lib";
6
7 use Test::More;
8
9 BEGIN {
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 $@;
14     plan skip_all => 'Test::WWW::Mechanize::Catalyst >= 0.40 required' if $Test::WWW::Mechanize::Catalyst::VERSION < 0.40;
15     plan 'no_plan';
16 }
17
18 use Test::WWW::Mechanize::Catalyst qw/CookieTestApp/;
19
20 my $m = Test::WWW::Mechanize::Catalyst->new;
21
22 $m->get_ok( "http://localhost/stream", "get page" );
23 $m->content_contains( "hit number 1", "session data created" );
24
25 my $expired;
26 $m->cookie_jar->scan( sub { $expired = $_[8]; } );
27
28 $m->get_ok( "http://localhost/page", "get page" );
29 $m->content_contains( "hit number 2", "session data restored" );
30
31 $m->get_ok( "http://localhost/stream", "get stream" );
32 $m->content_contains( "hit number 3", "session data restored" );
33
34 sleep 1;
35
36 $m->get_ok( "http://localhost/stream", "get page" );
37 $m->content_contains( "hit number 4", "session data restored" );
38
39 my $updated_expired;
40 $m->cookie_jar->scan( sub { $updated_expired = $_[8]; } );
41 cmp_ok( $expired, "<", $updated_expired, "cookie expiration was extended" );
42
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
47 sleep 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]; } );
53 cmp_ok( $expired, "<", $updated_expired, "streaming also extends cookie" );
54
55 $m->get_ok( "http://localhost/deleteme", "get page" );
56 $m->content_is( 1, 'session id changed' );
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" );