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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Marcel de Rooy 2022-04-14 13:24:39 +00:00 committed by Fridolin Somers
parent 642d0daa7c
commit b515208fa2
3 changed files with 7 additions and 7 deletions

View File

@ -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");
}

View File

@ -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 ) {

View File

@ -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;