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 => 1; |
21 |
|
22 |
use Test::Mojo; |
23 |
|
24 |
use t::lib::TestBuilder; |
25 |
use t::lib::Mocks; |
26 |
|
27 |
use Koha::Patrons; |
28 |
|
29 |
my $schema = Koha::Database->new->schema; |
30 |
my $builder = t::lib::TestBuilder->new; |
31 |
|
32 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
33 |
|
34 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
35 |
|
36 |
subtest 'basic tests' => sub { |
37 |
|
38 |
plan tests => 12; |
39 |
|
40 |
$schema->storage->txn_begin; |
41 |
|
42 |
my $privileged_patron = $builder->build_object( |
43 |
{ |
44 |
class => 'Koha::Patrons', |
45 |
value => { flags => 1 } |
46 |
} |
47 |
); |
48 |
my $password = 'thePassword123'; |
49 |
$privileged_patron->set_password( |
50 |
{ password => $password, skip_validation => 1 } ); |
51 |
my $userid = $privileged_patron->userid; |
52 |
|
53 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
54 |
|
55 |
t::lib::Mocks::mock_preference( 'dateformat','us' ); |
56 |
|
57 |
my $new_password = 'abc'; |
58 |
|
59 |
$t->post_ok( "//$userid:$password@/api/v1/patrons/" |
60 |
. $patron->id |
61 |
. "/password/expiration" => json => |
62 |
{ expiration_date => '2021-01-01' } ) |
63 |
->status_is(200)->json_is(''); |
64 |
|
65 |
$t->post_ok( "//$userid:$password@/api/v1/patrons/" |
66 |
. $patron->id |
67 |
. "/password/expiration" => json => |
68 |
{ expiration_date => '01/13/2021' } ) |
69 |
->status_is(200)->json_is(''); |
70 |
|
71 |
$t->post_ok( "//$userid:$password@/api/v1/patrons/" |
72 |
. $patron->id |
73 |
. "/password/expiration" => json => |
74 |
{ expiration_date => '13/01/2021' } ) |
75 |
->status_is(500)->json_is({ |
76 |
error => 'Something went wrong, check Koha logs for details.', |
77 |
error_code => "internal_server_error" |
78 |
}); |
79 |
|
80 |
$privileged_patron->flags(0)->store(); |
81 |
|
82 |
$t->post_ok( "//$userid:$password@/api/v1/patrons/" |
83 |
. $patron->id |
84 |
. "/password/expiration" => json => |
85 |
{ expiration_date => '2021-01-01' } ) |
86 |
->status_is(403)->json_is({ |
87 |
error => "Authorization failure. Missing required permission(s).", |
88 |
"required_permissions" => { |
89 |
"superlibrarian" => "1" |
90 |
} |
91 |
}); |
92 |
|
93 |
|
94 |
|
95 |
$schema->storage->txn_rollback; |
96 |
}; |