1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
use 5.008001;
use strict;
use warnings;
use Test::More 0.96;
use Test::Deep '!blessed';
use Test::Requires 'Mozilla::PublicSuffix';
use HTTP::CookieJar;
my @cases = (
{
label => "host is public suffix",
request => "http://com.au/",
cookies => ["SID=31d4d96e407aad42; Domain=com.au"],
store => {
'com.au' => {
'/' => {
SID => {
name => "SID",
value => "31d4d96e407aad42",
creation_time => ignore(),
last_access_time => ignore(),
domain => "com.au",
hostonly => 1,
path => "/",
}
}
},
},
},
{
label => "host is suffix of public suffix",
request => "http://au/",
cookies => ["SID=31d4d96e407aad42; Domain=au"],
store => {
'au' => {
'/' => {
SID => {
name => "SID",
value => "31d4d96e407aad42",
creation_time => ignore(),
last_access_time => ignore(),
domain => "au",
hostonly => 1,
path => "/",
}
}
},
},
},
{
label => "host is unrecognized single level",
request => "http://localhost/",
cookies => ["SID=31d4d96e407aad42; Domain=localhost"],
store => {
'localhost' => {
'/' => {
SID => {
name => "SID",
value => "31d4d96e407aad42",
creation_time => ignore(),
last_access_time => ignore(),
domain => "localhost",
hostonly => 1,
path => "/",
}
}
},
},
},
{
label => "cookie is public suffix",
request => "http://example.com.au/",
cookies => ["SID=31d4d96e407aad42; Domain=com.au"],
store => {},
},
{
label => "cookie is suffix of public suffix",
request => "http://example.com.au/",
cookies => ["SID=31d4d96e407aad42; Domain=au"],
store => {},
},
);
for my $c (@cases) {
my $jar = HTTP::CookieJar->new;
for my $cookie ( @{ $c->{cookies} } ) {
$jar->add( $c->{request}, $cookie );
}
cmp_deeply $jar->{store}, $c->{store}, $c->{label} or diag explain $jar->{store};
}
done_testing;
#
# This file is part of HTTP-CookieJar
#
# This software is Copyright (c) 2013 by David Golden.
#
# This is free software, licensed under:
#
# The Apache License, Version 2.0, January 2004
#
|