From 3929db6bc23d905b32d48fdd44d32166152ca842 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: Jonathan Druart --- 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 4b93813609..28b2c5f42c 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 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.5