6 use Test::More tests => 19;
11 BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) }
14 my $log = Test::MockObject->new;
15 my $req = Test::MockObject->new;
19 $log->set_true(qw/fatal warn/);
21 $req->set_always( address => "127.0.0.1" );
27 sub new { bless {}, $_[0] }
28 sub config { \%config }
32 sub isa { 1 } # subvert the plugin tests, we're faking them
33 sub get_session_data { \%session }
34 sub store_session_data { }
35 sub delete_session_data { }
43 ok( !$c->{session}, "without a session ID prepare doesn't load a session" );
47 %config = ( session => { expires => 100 } );
50 __expires => time() + 1000,
53 __address => "127.0.0.1",
59 $c->sessionid("the_session");
62 ok( $c->{session}, 'session "restored" with session id' );
67 __expires => time() - 100, # a while ago
68 __created => time() - 1000,
69 __udpated => time() - 1000,
70 __address => "127.0.0.1",
76 $c->sessionid("the_session");
79 ok( !$c->{session}, "expired sessions are deleted" );
80 like( $c->session_delete_reason, qr/expire/i, "with appropriate reason" );
81 ok( !$c->sessionid, "sessionid is also cleared" );
86 __expires => time() + 1000,
89 __address => "unlocalhost",
95 $c->sessionid("the_session");
98 ok( !$c->{session}, "hijacked sessions are deleted" );
99 like( $c->session_delete_reason, qr/mismatch/, "with appropriate reason" );
100 ok( !$c->sessionid, "sessionid is also cleared" );
105 __expires => time() + 1000,
108 __address => "unlocalhost",
111 $config{session}{verify_address} = 0;
113 my $c = MockCxt->new;
116 $c->sessionid("the_session");
119 ok( $c->{session}, "address mismatch is OK if verify_address is disabled" );
128 my $c = MockCxt->new;
132 ok( $c->session, "creating a session works" );
133 ok( $c->sessionid, "session id generated" );
135 cmp_ok( $c->session->{__created}, ">=", $now, "__created time is logical" );
136 cmp_ok( $c->session->{__updated}, ">=", $now, "__updated time is logical" );
138 $c->session->{__expires},
140 ( $now + $config{session}{expires} ),
141 "__expires time is logical"
143 is( $c->session->{__address},
144 $c->request->address, "address is also correct" );
147 [ keys %{ $c->{session} } ],
148 bag(qw/__expires __created __updated __address/),
149 "initial keys in session are all there",
155 __expires => time() + 1000,
158 __address => "127.0.0.1",
161 $config{session}{expires} = 2000;
163 my $c = MockCxt->new;
168 $c->sessionid("the_session");
173 "session is still alive after 1/2 expired and finalized" );
176 $c->session->{__expires},
179 "session expires time extended"