From 378b09df80b865896cd867b1a3d2a3dc403a2247 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 6 May 2022 06:32:51 +0000 Subject: [PATCH] Bug 28998: (follow-up) Adjust the Auth.t fix Content-Type: text/plain; charset=utf-8 Move the encode_secret call where we need it (when pref is enabled and patron switches to 2FA). Mock the koha-conf encryption_key. Disable 2FA when exiting subtest. Signed-off-by: Marcel de Rooy --- t/db_dependent/Auth.t | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t index 46ad64ecff..46aa156b1d 100755 --- a/t/db_dependent/Auth.t +++ b/t/db_dependent/Auth.t @@ -151,9 +151,7 @@ subtest 'checkauth() tests' => sub { } t::lib::Mocks::mock_preference( 'TwoFactorAuthentication', 0 ); - $patron->encode_secret('one_secret'); - $patron->auth_method('password'); - $patron->store; + $patron->auth_method('password')->store; ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 'authrequired', undef, 'intranet' ); is( $userid, $patron->userid, 'Succesful login' ); is( C4::Auth::get_session($sessionID)->param('waiting-for-2FA'), undef, 'Second auth not required' ); @@ -166,13 +164,16 @@ subtest 'checkauth() tests' => sub { logout($cgi); t::lib::Mocks::mock_preference( 'TwoFactorAuthentication', 1 ); + t::lib::Mocks::mock_config('encryption_key', '1234tH1s=t&st'); $patron->auth_method('password')->store; ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 'authrequired', undef, 'intranet' ); is( $userid, $patron->userid, 'Succesful login' ); is( C4::Auth::get_session($sessionID)->param('waiting-for-2FA'), undef, 'Second auth not required' ); logout($cgi); - $patron->auth_method('two-factor')->store; + $patron->encode_secret('one_secret'); + $patron->auth_method('two-factor'); + $patron->store; ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 'authrequired', undef, 'intranet' ); is( $userid, $patron->userid, 'Succesful login' ); my $session = C4::Auth::get_session($sessionID); @@ -192,6 +193,7 @@ subtest 'checkauth() tests' => sub { is( $userid, $patron->userid, 'Succesful login' ); is( C4::Auth::get_session($sessionID)->param('waiting-for-2FA'), 0, 'Second auth no longer required if OTP token has been verified' ); + t::lib::Mocks::mock_preference( 'TwoFactorAuthentication', 0 ); }; C4::Context->_new_userenv; # For next tests -- 2.20.1