From 51699efaf7298ee3247b2f622d0956582b051272 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 Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/api/v1/password_validation.t | 34 ++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/password_validation.t b/t/db_dependent/api/v1/password_validation.t index c37c4ff14ee..10527bc93d0 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,35 @@ 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 $json = { + identifier => $patron->userid, + 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.43.0