1# -*- Mode: Perl; -*-
2
3=head1 NAME
4
58_auth_01_cookies.t - Testing of the CGI::Ex::Auth cookies.
6
7=cut
8
9use strict;
10use Test::More tests => 4;
11
12use CGI::Ex::Auth;
13
14{
15    package Fake::CGI::Ex;
16
17    my $cookie;
18
19    sub new         { bless {}, shift }
20    sub set_cookie  { shift; $cookie = shift }
21    sub get_cookies { +{} }
22
23    sub FAKE_reset  { undef $cookie }
24    sub FAKE_cookie { $cookie }
25}
26
27my $cgix = Fake::CGI::Ex->new;
28my $auth = CGI::Ex::Auth->new({cgix => $cgix});
29
30$auth->set_cookie({
31    name    => 'foo',
32    value   => 'bar',
33});
34is_deeply($cgix->FAKE_cookie, {
35    -name   => 'foo',
36    -path   => '/',
37    -value  => 'bar',
38}, 'set_cookie works') or diag explain $cgix->FAKE_cookie;
39$cgix->FAKE_reset;
40
41$auth->set_cookie({
42    domain  => 'example.com',
43    name    => 'foo',
44    path    => '/baz',
45    secure  => 1,
46    value   => 'bar',
47});
48is_deeply($cgix->FAKE_cookie, {
49    -domain => 'example.com',
50    -name   => 'foo',
51    -path   => '/baz',
52    -secure => 1,
53    -value  => 'bar',
54}, 'set_cookie with more args works') or diag explain $cgix->FAKE_cookie;
55$cgix->FAKE_reset;
56
57$auth->set_cookie({
58    name        => 'foo',
59    value       => 'bar',
60    samesite    => 'strict',
61});
62is_deeply($cgix->FAKE_cookie, {
63    -name       => 'foo',
64    -path       => '/',
65    -samesite   => 'strict',
66    -value      => 'bar',
67}, 'set_cookie with samesite arg works') or diag explain $cgix->FAKE_cookie;
68$cgix->FAKE_reset;
69
70my $auth2 = CGI::Ex::Auth->new({cgix => $cgix, cookie_samesite => 'lax'});
71$auth2->set_cookie({
72    name    => 'foo',
73    value   => 'bar',
74});
75is_deeply($cgix->FAKE_cookie, {
76    -name       => 'foo',
77    -path       => '/',
78    -samesite   => 'lax',
79    -value      => 'bar',
80}, 'set_cookie with cookie_samesite works') or diag explain $cgix->FAKE_cookie;
81$cgix->FAKE_reset;
82
83