|
Lines 23-28
use Test::Mojo;
Link Here
|
| 23 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
| 24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
| 25 |
|
25 |
|
|
|
26 |
use Koha::AuthUtils; |
| 27 |
|
| 26 |
my $schema = Koha::Database->new->schema; |
28 |
my $schema = Koha::Database->new->schema; |
| 27 |
my $builder = t::lib::TestBuilder->new; |
29 |
my $builder = t::lib::TestBuilder->new; |
| 28 |
|
30 |
|
|
Lines 37-47
subtest 'success tests' => sub {
Link Here
|
| 37 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
39 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
| 38 |
|
40 |
|
| 39 |
my $password = 'AbcdEFG123'; |
41 |
my $password = 'AbcdEFG123'; |
|
|
42 |
my $digest = Koha::AuthUtils::hash_password( $password ); |
| 40 |
|
43 |
|
| 41 |
my $patron = $builder->build_object( |
44 |
my $patron = $builder->build_object( |
| 42 |
{ class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); |
45 |
{ class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); |
| 43 |
$patron->set_password({ password => $password }); |
|
|
| 44 |
my $userid = $patron->userid; |
46 |
my $userid = $patron->userid; |
|
|
47 |
$patron->update_password( $userid, $digest ); |
| 45 |
|
48 |
|
| 46 |
$t->get_ok("//$userid:$password@/api/v1/patrons") |
49 |
$t->get_ok("//$userid:$password@/api/v1/patrons") |
| 47 |
->status_is( 200, 'Successful authentication and permissions check' ); |
50 |
->status_is( 200, 'Successful authentication and permissions check' ); |
|
Lines 66-78
subtest 'failure tests' => sub {
Link Here
|
| 66 |
|
69 |
|
| 67 |
my $password = 'AbcdEFG123'; |
70 |
my $password = 'AbcdEFG123'; |
| 68 |
my $bad_password = '123456789'; |
71 |
my $bad_password = '123456789'; |
|
|
72 |
my $digest = Koha::AuthUtils::hash_password( $password ); |
| 69 |
|
73 |
|
| 70 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
74 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
| 71 |
|
75 |
|
| 72 |
my $patron = $builder->build_object( |
76 |
my $patron = $builder->build_object( |
| 73 |
{ class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); |
77 |
{ class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 2**4 } } ); |
| 74 |
$patron->set_password({ password => $password }); |
|
|
| 75 |
my $userid = $patron->userid; |
78 |
my $userid = $patron->userid; |
|
|
79 |
$patron->update_password( $userid, $digest ); |
| 76 |
|
80 |
|
| 77 |
$t->get_ok("//@/api/v1/patrons") |
81 |
$t->get_ok("//@/api/v1/patrons") |
| 78 |
->status_is( 401, 'No credentials passed' ); |
82 |
->status_is( 401, 'No credentials passed' ); |
| 79 |
- |
|
|