From 304d0c74a30b51ac6ff9b2c45634f51d68ab30cd Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Mon, 18 Dec 2023 11:00:06 +0000 Subject: [PATCH] Bug 35204: Add unit tests prove t/db_dependent/api/v1/password_validation.t --- t/db_dependent/api/v1/password_validation.t | 33 ++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/password_validation.t b/t/db_dependent/api/v1/password_validation.t index c37c4ff14e..01fc56dcdb 100755 --- a/t/db_dependent/api/v1/password_validation.t +++ b/t/db_dependent/api/v1/password_validation.t @@ -18,13 +18,14 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Mojo; use t::lib::TestBuilder; use t::lib::Mocks; use Koha::Database; +use Koha::DateUtils qw(dt_from_string); my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; @@ -207,4 +208,34 @@ subtest 'Password validation - authorized requests tests' => sub { $schema->storage->txn_rollback; }; +subtest 'password validation - expired password' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 2**2 } # catalogue flag = 2 + } + ); + my $patron_password = 'thePassword123'; + $patron->set_password( { password => $patron_password, skip_validation => 1 } ); + my $date = dt_from_string(); + my $expiration_date = $date->subtract( days => 1 ); + $patron->password_expiration_date( $expiration_date )->store; + my $patronid = $patron->userid; + + my $json = { + identifier => $patronid, + password => $patron_password, + }; + + $t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json )->status_is(400) + ->json_is( '/error' => 'Password expired' ); + + $schema->storage->txn_rollback; +}; + + $schema->storage->txn_rollback; -- 2.37.1 (Apple Git-137.1)