Merge pull request #7 from tokuhirom/master
[catagits/Web-Session.git] / t / 015_cookie_options_mw.t
CommitLineData
442b79a8 1use strict;
2use Plack::Test;
3use Plack::Middleware::Session;
4use Test::More;
5use HTTP::Request::Common;
6use HTTP::Cookies;
7
8my $app = sub {
9 my $env = shift;
10
11 $env->{'psgix.session'}->{counter} = 1;
12
c42534a7 13 my $path = $env->{PATH_INFO} =~ /with_path/ ? "/foo" : undef;
14 $env->{'psgix.session.options'}{path} = $path;
442b79a8 15 $env->{'psgix.session.options'}{domain} = '.example.com';
16 $env->{'psgix.session.options'}{httponly} = 1;
17
18 return [ 200, [], [ "Hi" ] ];
19};
20
21$app = Plack::Middleware::Session->wrap($app);
22
23test_psgi $app, sub {
24 my $cb = shift;
25
26 my $res = $cb->(GET "http://localhost/");
c42534a7 27 like $res->header('Set-Cookie'), qr/plack_session=\w+; domain=.example.com; HttpOnly/;
28
29 $res = $cb->(GET "http://localhost/with_path");
442b79a8 30 like $res->header('Set-Cookie'), qr/plack_session=\w+; domain=.example.com; path=\/foo; HttpOnly/;
31};
32
33done_testing;
34