1 package t::lib::TestSession;
23 $response_test = sub {
24 my ($response, $session_id, $check_expired) = @_;
29 my $r = $request_creator->();
31 my $s = Plack::Session->new(
39 ok(!$s->get('foo'), '... no value stored in foo for session');
42 $s->set( foo => 'bar' );
43 } '... set the value successfully in session';
45 is($s->get('foo'), 'bar', '... got the foo value back successfully from session');
47 ok(!$s->get('bar'), '... no value stored in foo for session');
50 $s->set( bar => 'baz' );
51 } '... set the value successfully in session';
53 is($s->get('bar'), 'baz', '... got the foo value back successfully from session');
55 my $resp = $r->new_response;
58 $s->finalize( $resp );
59 } '... finalized session successfully';
61 is_deeply( $s->store->dump_session( $sids[0] ), { foo => 'bar', bar => 'baz' }, '... got the session dump we expected');
63 $response_test->( $resp, $sids[0] );
67 my $r = $request_creator->();
69 my $s = Plack::Session->new(
77 isnt($sids[0], $sids[1], "no same Session ID");
78 ok(!$s->get('foo'), '... no value stored for foo in session');
81 $s->set( foo => 'baz' );
82 } '... set the value successfully';
84 is($s->get('foo'), 'baz', '... got the foo value back successfully from session');
86 my $resp = $r->new_response;
89 $s->finalize( $resp );
90 } '... finalized session successfully';
92 is_deeply( $s->store->dump_session( $sids[1] ), { foo => 'baz' }, '... got the session dump we expected');
94 $response_test->( $resp, $sids[1] );
98 my $r = $request_creator->({ plack_session => $sids[0] });
100 my $s = Plack::Session->new(
106 is($s->id, $sids[0], '... got a basic session id');
108 is($s->get('foo'), 'bar', '... got the value for foo back successfully from session');
112 } '... removed the foo value successfully from session';
114 ok(!$s->get('foo'), '... no value stored for foo in session');
116 my $resp = $r->new_response;
119 $s->finalize( $resp );
120 } '... finalized session successfully';
122 is_deeply( $s->store->dump_session( $sids[0] ), { bar => 'baz' }, '... got the session dump we expected');
124 $response_test->( $resp, $sids[0] );
129 my $r = $request_creator->({ plack_session => $sids[1] });
131 my $s = Plack::Session->new(
137 is($s->id, $sids[1], '... got a basic session id');
139 is($s->get('foo'), 'baz', '... got the foo value back successfully from session');
141 my $resp = $r->new_response;
144 $s->finalize( $resp );
145 } '... finalized session successfully';
147 is_deeply( $s->store->dump_session( $sids[1] ), { foo => 'baz' }, '... got the session dump we expected');
149 $response_test->( $resp, $sids[1] );
153 my $r = $request_creator->({ plack_session => $sids[0] });
155 my $s = Plack::Session->new(
161 is($s->id, $sids[0], '... got a basic session id');
163 ok(!$s->get('foo'), '... no value stored for foo in session');
166 $s->set( baz => 'gorch' );
167 } '... set the bar value successfully in session';
169 my $resp = $r->new_response;
172 $s->finalize( $resp );
173 } '... finalized session successfully';
175 is_deeply( $s->store->dump_session( $sids[0] ), { bar => 'baz', baz => 'gorch' }, '... got the session dump we expected');
177 $response_test->( $resp, $sids[0] );
181 my $r = $request_creator->({ plack_session => $sids[0] });
183 my $s = Plack::Session->new(
189 is($s->get('bar'), 'baz', '... got the bar value back successfully from session');
193 } '... expired session successfully';
195 my $resp = $r->new_response;
198 $s->finalize( $resp );
199 } '... finalized session successfully';
201 is_deeply( $s->store->dump_session( $sids[0] ), {}, '... got the session dump we expected');
203 $response_test->( $resp, $sids[0], 1 );
207 my $r = $request_creator->({ plack_session => $sids[0] });
209 my $s = Plack::Session->new(
216 isnt($s->id, $sids[0], 'expired ... got a new session id');
218 ok(!$s->get('bar'), '... no bar value stored');
220 my $resp = $r->new_response;
223 $s->finalize( $resp );
224 } '... finalized session successfully';
226 is_deeply( $s->store->dump_session( $sids[2] ), {}, '... got the session dump we expected');
228 $response_test->( $resp, $sids[2] );
232 my $r = $request_creator->({ plack_session => $sids[1] });
234 my $s = Plack::Session->new(
240 is($s->id, $sids[1], '... got a basic session id');
242 is($s->get('foo'), 'baz', '... got the foo value back successfully from session');
244 my $resp = $r->new_response;
247 $s->finalize( $resp );
248 } '... finalized session successfully';
250 is_deeply( $s->store->dump_session( $sids[1] ), { foo => 'baz' }, '... got the session dump we expected');
252 $response_test->( $resp, $sids[1] );
256 # wrong format session_id
257 my $r = $request_creator->({ plack_session => '../wrong' });
259 my $s = Plack::Session->new(
266 isnt('../wrong' => $s->id, '... regenerate session id');
268 ok(!$s->get('foo'), '... no value stored for foo in session');
271 $s->set( foo => 'baz' );
272 } '... set the value successfully';
274 is($s->get('foo'), 'baz', '... got the foo value back successfully from session');
276 my $resp = $r->new_response;
279 $s->finalize( $resp );
280 } '... finalized session successfully';
282 is_deeply( $s->store->dump_session( $s->id ), { foo => 'baz' }, '... got the session dump we expected');
284 $response_test->( $resp, $s );