From 73e806f902c20d08e214360889d1c55d9fc8804b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 10 Sep 2021 10:34:41 +0200 Subject: [PATCH] Bug 28772: Make validate_secret return 1|0 Not an empty string Signed-off-by: Kyle M Hall --- Koha/ApiKey.pm | 2 +- t/db_dependent/Koha/ApiKey.t | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Koha/ApiKey.pm b/Koha/ApiKey.pm index 3e907fd9cb..1131ff7a25 100644 --- a/Koha/ApiKey.pm +++ b/Koha/ApiKey.pm @@ -81,7 +81,7 @@ sub validate_secret { my $digest = Koha::AuthUtils::hash_password( $secret, $self->secret ); - return $self->secret eq $digest; + return ( $self->secret eq $digest ) ? 1 : 0; } =head3 plain_text_secret diff --git a/t/db_dependent/Koha/ApiKey.t b/t/db_dependent/Koha/ApiKey.t index 228f0961c9..d9f46fce88 100755 --- a/t/db_dependent/Koha/ApiKey.t +++ b/t/db_dependent/Koha/ApiKey.t @@ -130,8 +130,8 @@ subtest 'validate_secret() tests' => sub { my $secret = $api_key->plain_text_secret; - ok( $api_key->validate_secret( $secret ), 'Valid secret returns true' ); - ok( !$api_key->validate_secret( 'Wrong secret' ), 'Invalid secret returns false' ); + is( $api_key->validate_secret( $secret ), 1, 'Valid secret returns true' ); + is( $api_key->validate_secret( 'Wrong secret' ), 0, 'Invalid secret returns false' ); $schema->storage->txn_rollback; }; -- 2.39.2