Bug 29924: Add tests for API Basic auth behavior

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Tomas Cohen Arazi 2022-04-25 11:05:15 -03:00 committed by Fridolin Somers
parent 5ca99ca594
commit 4e2cfbe75e
1 changed files with 13 additions and 1 deletions

View File

@ -23,6 +23,8 @@ use Test::Mojo;
use t::lib::TestBuilder;
use t::lib::Mocks;
use Koha::DateUtils qw( dt_from_string );
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
@ -77,7 +79,7 @@ subtest 'success tests' => sub {
subtest 'failure tests' => sub {
plan tests => 8;
plan tests => 13;
$schema->storage->txn_begin;
@ -91,6 +93,16 @@ subtest 'failure tests' => sub {
$patron->set_password({ password => $password });
my $userid = $patron->userid;
$t->get_ok("//$userid:$password@/api/v1/patrons")
->status_is( 200, 'All good' );
# expire patron's password
$patron->password_expiration_date( dt_from_string->subtract( days => 1 ) )->store;
$t->get_ok("//$userid:$password@/api/v1/patrons")
->status_is( 403 )
->json_is( '/error' => 'Password has expired', 'Password expired' );
$t->get_ok("//@/api/v1/patrons")
->status_is( 401, 'No credentials passed' );