From c930db2665705562b0d59093348016e9db8ba3eb 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 --- 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 4b938136091..28b2c5f42ce 100644 --- a/Koha/ApiKey.pm +++ b/Koha/ApiKey.pm @@ -80,7 +80,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 228f0961c9f..d9f46fce880 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.25.1