Added Session::Cookie middleware which utilizes Cookie as both state and store.
[catagits/Web-Session.git] / t / 013_cookiestore.t
CommitLineData
d326e755 1use strict;
2use Test::More;
3use Test::Requires qw(Digest::HMAC_SHA1);
4use Plack::Test;
5use Plack::Middleware::Session::Cookie;
6use HTTP::Request::Common;
7use LWP::UserAgent;
8use HTTP::Cookies;
9
10$Plack::Test::Impl = 'Server';
11
12my $app = sub {
13 my $env = shift;
14 my $session = $env->{'psgix.session'};
15
16 my $counter = $session->get('counter') || 0;
17 if ($counter >= 2) {
18 $session->expire;
19 } else {
20 $session->set(counter => $counter + 1);
21 }
22
23 return [ 200, [], [ "counter=$counter" ] ];
24};
25
26$app = Plack::Middleware::Session::Cookie->wrap($app, secret => "foobar");
27
28my $ua = LWP::UserAgent->new;
29$ua->cookie_jar( HTTP::Cookies->new );
30
31test_psgi ua => $ua, app => $app, client => sub {
32 my $cb = shift;
33
34 my $res = $cb->(GET "/");
35 is $res->content, "counter=0";
36
37 $res = $cb->(GET "/");
38 is $res->content, "counter=1";
39
40 $res = $cb->(GET "/");
41 is $res->content, "counter=2";
42
43 my $res = $cb->(GET "/");
44 is $res->content, "counter=0";
45};
46
47done_testing;