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