|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Test::More tests => 4; |
| 21 |
|
| 22 |
use Test::MockModule; |
| 23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
| 25 |
|
| 26 |
use Koha::Patrons; |
| 27 |
use Koha::Patron::Allowlist; |
| 28 |
|
| 29 |
use t::lib::Mocks; |
| 30 |
|
| 31 |
subtest '_get_all_fields' => sub { |
| 32 |
my @columns = Koha::Patrons->columns; |
| 33 |
is_deeply( |
| 34 |
\@columns, |
| 35 |
[ Koha::Patron::Allowlist->_get_all_fields ], |
| 36 |
'All DB columns must be listed in _get_all_fields' |
| 37 |
); |
| 38 |
}; |
| 39 |
|
| 40 |
subtest 'Staff Allowlist' => sub { |
| 41 |
plan tests => 4; |
| 42 |
my $input = { firstname => 'test firstname', surname => 'test surname', flags => '1' }; |
| 43 |
my $allowlist = Koha::Patron::Allowlist->new({ interface => 'staff' }); |
| 44 |
warning_like { |
| 45 |
$allowlist->apply({ input => $input, }); |
| 46 |
} qr{Forbidden - Tried to modify 'flags' with '1' from}; |
| 47 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
| 48 |
is( $input->{surname}, 'test surname', 'surname preserved' ); |
| 49 |
is( $input->{flags}, undef, 'flags filtered' ); |
| 50 |
}; |
| 51 |
|
| 52 |
subtest 'Public Allowlist' => sub { |
| 53 |
plan tests => 4; |
| 54 |
my $input = { firstname => 'test firstname', surname => 'test surname', flags => '1' }; |
| 55 |
my $allowlist = Koha::Patron::Allowlist->new(); |
| 56 |
warning_like { |
| 57 |
$allowlist->apply({ input => $input, }); |
| 58 |
} qr{Forbidden - Tried to modify 'flags' with '1' from}; |
| 59 |
|
| 60 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
| 61 |
is( $input->{surname}, 'test surname', 'surname preserved' ); |
| 62 |
is( $input->{flags}, undef, 'flags filtered' ); |
| 63 |
}; |
| 64 |
|
| 65 |
subtest 'additional_deny_list' => sub { |
| 66 |
plan tests => 10; |
| 67 |
|
| 68 |
my $input = { firstname => 'test firstname', surname => 'test surname' }; |
| 69 |
my $allowlist = Koha::Patron::Allowlist->new(); |
| 70 |
|
| 71 |
$allowlist->apply({ |
| 72 |
input => $input, |
| 73 |
additional_deny_list => [], |
| 74 |
}); |
| 75 |
|
| 76 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
| 77 |
is( $input->{surname}, 'test surname', 'surname filtered' ); |
| 78 |
is( $input->{flags}, undef, 'flags filtered' ); |
| 79 |
|
| 80 |
$allowlist->apply({ |
| 81 |
input => $input, |
| 82 |
additional_deny_list => ['not_here'], |
| 83 |
}); |
| 84 |
|
| 85 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
| 86 |
is( $input->{surname}, 'test surname', 'surname filtered' ); |
| 87 |
is( $input->{flags}, undef, 'flags filtered' ); |
| 88 |
|
| 89 |
warning_like { |
| 90 |
$allowlist->apply({ |
| 91 |
input => $input, |
| 92 |
additional_deny_list => ['surname'], |
| 93 |
}); |
| 94 |
} |
| 95 |
qr{Forbidden - Tried to modify 'surname' with 'test surname' from}; |
| 96 |
|
| 97 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
| 98 |
is( $input->{surname}, undef, 'surname filtered' ); |
| 99 |
is( $input->{flags}, undef, 'flags filtered' ); |
| 100 |
|
| 101 |
}; |