From ce0fe316b81d57be382ce4139c2437d74c88f510 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 Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- 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 2da1d68352..28c1300de8 100755 --- a/t/db_dependent/Auth.t +++ b/t/db_dependent/Auth.t @@ -686,7 +686,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' }); @@ -699,6 +699,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 { @@ -1077,7 +1081,7 @@ subtest 'checkpw() return values tests' => sub { subtest 'Internal check tests' => sub { - plan tests => 25; + plan tests => 29; $schema->storage->txn_begin; @@ -1134,6 +1138,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" ); @@ -1151,7 +1163,7 @@ subtest 'checkpw() return values tests' => sub { subtest 'CAS check (mocked) tests' => sub { - plan tests => 25; + plan tests => 29; $schema->storage->txn_begin; @@ -1218,6 +1230,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.5