From b515208fa20ba4a9c80229639dcf770783ac88d4 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 14 Apr 2022 13:24:39 +0000 Subject: [PATCH] Bug 28998: (follow-up) Apply changes to TwoFactorAuth module and script Test plan: Run t/db_dependent/Koha/Auth/TwoFactorAuth.t Walk thru cycle register - logout/login - deregister - logout/login. Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- Koha/Auth/TwoFactorAuth.pm | 2 +- members/two_factor_auth.pl | 2 +- t/db_dependent/Koha/Auth/TwoFactorAuth.t | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Koha/Auth/TwoFactorAuth.pm b/Koha/Auth/TwoFactorAuth.pm index aa4f5aca52..48b2a895ea 100644 --- a/Koha/Auth/TwoFactorAuth.pm +++ b/Koha/Auth/TwoFactorAuth.pm @@ -68,7 +68,7 @@ sub new { } elsif( $secret ) { $type = 'secret'; } elsif( $patron->secret ) { - $secret32 = $patron->secret; # saved already in base32 + $secret32 = $patron->decoded_secret; # saved already in base32 } else { Koha::Exceptions::MissingParameter->throw("No secret passed or patron has no secret"); } diff --git a/members/two_factor_auth.pl b/members/two_factor_auth.pl index 0a5278c8e6..1a8484982b 100755 --- a/members/two_factor_auth.pl +++ b/members/two_factor_auth.pl @@ -69,7 +69,7 @@ if ( $op eq 'register-2FA' ) { if ($verified) { # FIXME Generate a (new?) secret - $logged_in_user->secret($secret32); + $logged_in_user->encode_secret($secret32); $logged_in_user->auth_method('two-factor')->store; $op = 'registered'; if( $logged_in_user->notice_email_address ) { diff --git a/t/db_dependent/Koha/Auth/TwoFactorAuth.t b/t/db_dependent/Koha/Auth/TwoFactorAuth.t index 39e8a1d3fa..051c41154c 100755 --- a/t/db_dependent/Koha/Auth/TwoFactorAuth.t +++ b/t/db_dependent/Koha/Auth/TwoFactorAuth.t @@ -42,10 +42,10 @@ subtest 'new' => sub { 'Croaked on wrong encoding'; # Test passing secret or secret32 (converted to base32) - $patron->secret('nv4v65dpobpxgzldojsxiii'); # this is base32 already for 'my_top_secret!' + $patron->encode_secret('nv4v65dpobpxgzldojsxiii'); # this is base32 already for 'my_top_secret!' my $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron }); - is( $auth->secret32, $patron->secret, 'Base32 secret as expected' ); - $auth->code( $patron->secret ); # trigger conversion by passing base32 to code + is( $auth->secret32, $patron->decoded_secret, 'Base32 secret as expected' ); + $auth->code( $patron->decoded_secret ); # trigger conversion by passing base32 to code is( $auth->secret, 'my_top_secret!', 'Decoded secret fine too' ); # The other way around $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron, secret => 'my_top_secret!' }); @@ -64,7 +64,7 @@ subtest 'qr_code' => sub { t::lib::Mocks::mock_preference('TwoFactorAuthentication', 1); my $patron = $builder->build_object({ class => 'Koha::Patrons' }); - $patron->secret('you2wont2guess2it'); # this is base32 btw + $patron->encode_secret('you2wont2guess2it'); # this is base32 btw $patron->auth_method('two-factor'); $patron->store; @@ -76,7 +76,7 @@ subtest 'qr_code' => sub { $auth->clear; # Changing the secret should generate different data, right? - $patron->secret('no3really3not3cracked'); # base32 + $patron->encode_secret('no3really3not3cracked'); # base32 $patron->store; $auth = Koha::Auth::TwoFactorAuth->new({ patron => $patron }); my $img_data02 = $auth->qr_code; -- 2.39.5