Lines 30-88
use Koha::CookieManager;
Link Here
|
30 |
subtest 'new' => sub { |
30 |
subtest 'new' => sub { |
31 |
plan tests => 3; |
31 |
plan tests => 3; |
32 |
|
32 |
|
33 |
t::lib::Mocks::mock_config( Koha::CookieManager::ALLOW_LIST_VAR, 'just_one' ); |
33 |
t::lib::Mocks::mock_config( Koha::CookieManager::DENY_LIST_VAR, 'just_one' ); |
34 |
my $cmgr = Koha::CookieManager->new; |
34 |
my $cmgr = Koha::CookieManager->new; |
35 |
is( scalar keys %{$cmgr->{_remove_allowed}}, 1, 'one entry' ); |
35 |
is( scalar keys %{$cmgr->{_remove_unless}}, 1, 'one entry' ); |
36 |
is( exists $cmgr->{_secure}, 1, 'secure key found' ); |
36 |
is( exists $cmgr->{_secure}, 1, 'secure key found' ); |
37 |
|
37 |
|
38 |
t::lib::Mocks::mock_config( Koha::CookieManager::ALLOW_LIST_VAR, [ 'two', 'entries' ] ); |
38 |
t::lib::Mocks::mock_config( Koha::CookieManager::DENY_LIST_VAR, [ 'two', 'entries' ] ); |
39 |
$cmgr = Koha::CookieManager->new; |
39 |
$cmgr = Koha::CookieManager->new; |
40 |
is( scalar keys %{$cmgr->{_remove_allowed}}, 2, 'two entries' ); |
40 |
is( scalar keys %{$cmgr->{_remove_unless}}, 2, 'two entries' ); |
41 |
}; |
41 |
}; |
42 |
|
42 |
|
43 |
subtest 'clear_if_allowed' => sub { |
43 |
subtest 'clear_unless' => sub { |
44 |
plan tests => 13; |
44 |
plan tests => 15; |
45 |
|
45 |
|
46 |
t::lib::Mocks::mock_config( Koha::CookieManager::ALLOW_LIST_VAR, [ 'aap', 'noot', 'mies' ] ); |
46 |
t::lib::Mocks::mock_config( Koha::CookieManager::DENY_LIST_VAR, [ 'aap', 'noot' ] ); |
47 |
|
47 |
|
48 |
my $q = CGI->new; |
48 |
my $q = CGI->new; |
49 |
my $cmgr = Koha::CookieManager->new; |
49 |
my $cmgr = Koha::CookieManager->new; |
50 |
|
50 |
|
51 |
my $cookie1 = $q->cookie( |
51 |
my $cookie1 = $q->cookie( -name => 'aap', -value => 'aap', -expires => '+1d' ); |
52 |
-name => 'aap', |
52 |
my $cookie2 = $q->cookie( -name => 'noot', -value => 'noot' ); |
53 |
-value => 'aap', |
|
|
54 |
-expires => '+1d', |
55 |
-HttpOnly => 1, |
56 |
-secure => 1, |
57 |
); |
58 |
my $cookie2 = $q->cookie( |
59 |
-name => 'noot', |
60 |
-value => 'noot', |
61 |
-expires => '+1d', |
62 |
-HttpOnly => 1, |
63 |
-secure => 1, |
64 |
); |
65 |
my $cookie3 = $q->cookie( -name => 'wim', -value => q{wim}, -HttpOnly => 1 ); |
53 |
my $cookie3 = $q->cookie( -name => 'wim', -value => q{wim}, -HttpOnly => 1 ); |
66 |
my $cookie4 = $q->cookie( -name => 'aap', -value => q{aap2} ); |
54 |
my $cookie4 = $q->cookie( -name => 'aap', -value => q{aap2}, -HttpOnly => 1 ); |
67 |
my $list = [ $cookie1, $cookie2, $cookie3, $cookie4, 'mies', 'zus' ]; # 4 cookies, 2 names |
55 |
my $list = [ $cookie1, $cookie2, $cookie3, $cookie4, 'mies', 'zus' ]; # 4 cookies, 2 names |
68 |
|
56 |
|
69 |
# No results expected |
57 |
# No results expected |
70 |
is( @{$cmgr->clear_if_allowed}, 0, 'Empty list' ); |
58 |
is( @{$cmgr->clear_unless}, 0, 'Empty list' ); |
71 |
is( @{$cmgr->clear_if_allowed( 'scalar', [], $q )}, 0, 'Empty list for invalid arguments' ); |
59 |
is( @{$cmgr->clear_unless( { hash => 1 }, [ 'array' ], $q )}, 0, 'Empty list for invalid arguments' ); |
72 |
|
60 |
|
73 |
# Pass list, expect 4 cookies (3 cleared) |
61 |
# Pass list, expect 5 cookies (3 cleared, last aap kept) |
74 |
my @rv = @{$cmgr->clear_if_allowed( @$list )}; |
62 |
my @rv = @{$cmgr->clear_unless( @$list )}; |
75 |
is( @rv, 4, 'Four expected' ); |
63 |
is( @rv, 5, '5 expected' ); |
76 |
is( $rv[0]->name, 'aap', 'First cookie' ); |
64 |
is( $rv[0]->name, 'noot', '1st cookie' ); |
77 |
is( $rv[1]->name, 'noot', '2nd cookie' ); |
65 |
is( $rv[1]->name, 'wim', '2nd cookie' ); |
78 |
is( $rv[2]->name, 'wim', '3rd cookie' ); |
66 |
is( $rv[2]->name, 'aap', '3rd cookie' ); |
79 |
is( $rv[3]->name, 'mies', '4th cookie' ); |
67 |
is( $rv[3]->name, 'mies', '4th cookie' ); |
80 |
is( $rv[0]->value, q{}, 'aap should be empty' ); |
68 |
is( $rv[4]->name, 'zus', '5th cookie' ); |
81 |
is( $rv[1]->value, q{}, 'noot should be empty' ); |
69 |
is( $rv[0]->value, q{noot}, 'noot not empty' ); |
82 |
is( $rv[2]->value, 'wim', 'wim not empty' ); |
70 |
is( $rv[1]->value, q{}, 'wim empty' ); |
|
|
71 |
is( $rv[2]->value, q{aap2}, 'aap not empty' ); |
83 |
is( $rv[3]->value, q{}, 'mies empty' ); |
72 |
is( $rv[3]->value, q{}, 'mies empty' ); |
84 |
is( $rv[0]->httponly, 0, 'cleared aap isnt httponly' ); |
73 |
is( $rv[4]->value, q{}, 'zus empty' ); |
85 |
is( $rv[2]->httponly, 1, 'wim still httponly' ); |
74 |
is( $rv[1]->httponly, 0, 'cleared wim isnt httponly' ); |
|
|
75 |
is( $rv[2]->httponly, 1, 'aap httponly' ); |
86 |
}; |
76 |
}; |
87 |
|
77 |
|
88 |
subtest 'replace_in_list' => sub { |
78 |
subtest 'replace_in_list' => sub { |
89 |
- |
|
|