From 0cdc606e403e71aa3f0f69d6fa031ba324311091 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: Wainui Witika-Park --- 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 dc6a2921d8..465f999fb8 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 439ad8718b..5a23396c49 100755 --- a/t/db_dependent/Koha/ApiKey.t +++ b/t/db_dependent/Koha/ApiKey.t @@ -122,8 +122,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.5