From dd1da8d654bd987f60c5807f8c152618ba77db2c Mon Sep 17 00:00:00 2001 From: Sam Lau Date: Mon, 17 Jun 2024 19:31:52 +0000 Subject: [PATCH] Bug 37104: Unit tests prove t/db-dependent/Auth.t Signed-off-by: David Nind --- t/db_dependent/Auth.t | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t index 99beff8975..2e6a8503ff 100755 --- a/t/db_dependent/Auth.t +++ b/t/db_dependent/Auth.t @@ -684,7 +684,7 @@ subtest 'Check value of login_attempts in checkpw' => sub { }; subtest 'Check value of login_attempts in checkpw' => sub { - plan tests => 2; + plan tests => 3; t::lib::Mocks::mock_preference('FailedLoginAttempts', 3); my $patron = $builder->build_object({ class => 'Koha::Patrons' }); @@ -697,6 +697,10 @@ subtest 'Check value of login_attempts in checkpw' => sub { @test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); is( $test[0], -2, 'Patron returned as expired correctly' ); + ## Make our patron the anonymous patron + t::lib::Mocks::mock_preference( 'AnonymousPatron', $patron->id ); + @test = checkpw( $patron->userid, '123', undef, 'opac', 1 ); + is ($test[0], -3, 'Patron returned as anonymous patron correctly' ); }; subtest '_timeout_syspref' => sub { @@ -1075,7 +1079,7 @@ subtest 'checkpw() return values tests' => sub { subtest 'Internal check tests' => sub { - plan tests => 25; + plan tests => 29; $schema->storage->txn_begin; @@ -1132,6 +1136,14 @@ subtest 'checkpw() return values tests' => sub { is( ref( $return[1] ), 'Koha::Patron' ); is( $return[1]->id, $patron->id, 'Patron matched correctly' ); + t::lib::Mocks::mock_preference( 'AnonymousPatron', $patron->id ); + @return = checkpw( $patron->userid, $password, undef, ); + + is( scalar @return, 2, "Two results on expired password scenario" ); + is( $return[0], -3, '-3 returned' ); + is( ref( $return[1] ), 'Koha::Patron' ); + is( $return[1]->id, $patron->id, 'Patron matched correctly' ); + @return = checkpw( $unused_userid, $password, undef, ); is( scalar @return, 2, "Two results on non-existing userid scenario" ); @@ -1149,7 +1161,7 @@ subtest 'checkpw() return values tests' => sub { subtest 'CAS check (mocked) tests' => sub { - plan tests => 25; + plan tests => 29; $schema->storage->txn_begin; @@ -1216,6 +1228,13 @@ subtest 'checkpw() return values tests' => sub { is( ref( $return[1] ), 'Koha::Patron' ); is( $return[1]->id, $patron->id, 'Patron matched correctly' ); + t::lib::Mocks::mock_preference( 'AnonymousPatron', $patron->id ); + @return = checkpw( $patron->userid, $password, undef, ); + is( scalar @return, 2, "Two results on expired password scenario" ); + is( $return[0], -3, '-3 returned' ); + is( ref( $return[1] ), 'Koha::Patron' ); + is( $return[1]->id, $patron->id, 'Patron matched correctly' ); + @return = checkpw( $unused_userid, $password, $query, ); is( scalar @return, 2, "Two results on non-existing userid scenario" ); -- 2.39.2