Bug 32066: Add unit test to Auth.t
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Thu, 3 Nov 2022 08:49:26 +0000 (08:49 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 4 Nov 2022 22:01:57 +0000 (19:01 -0300)
Test plan:
Run without next patch. Should fail.
Run with next patch. Should pass.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
https://bugs.koha-community.org/show_bug.cgi?id=31881

t/db_dependent/Auth.t

index 83e15bd..c8da8bd 100755 (executable)
@@ -153,6 +153,7 @@ subtest 'checkauth() tests' => sub {
     };
 
     subtest 'Two-factor authentication' => sub {
+        plan tests => 18;
 
         my $patron = $builder->build_object(
             { class => 'Koha::Patrons', value => { flags => 1 } } );
@@ -245,7 +246,18 @@ subtest 'checkauth() tests' => sub {
         is( $userid, $patron->userid, 'Succesful login at the OPAC' );
         is( C4::Auth::get_session($sessionID)->param('waiting-for-2FA'), undef, 'No second auth required at the OPAC' );
 
+        #
         t::lib::Mocks::mock_preference( 'TwoFactorAuthentication', 'disabled' );
+        $session = C4::Auth::get_session($sessionID);
+        $session->param('waiting-for-2FA', 1);
+        $session->flush;
+        my ($auth_status, undef ) = C4::Auth::check_cookie_auth($sessionID, undef );
+        is( $auth_status, 'ok', 'User authenticated, pref was disabled, access OK' );
+        $session->param('waiting-for-2FA', 0);
+        $session->param('waiting-for-2FA-setup', 1);
+        $session->flush;
+        ($auth_status, undef ) = C4::Auth::check_cookie_auth($sessionID, undef );
+        is( $auth_status, 'ok', 'User waiting for 2FA setup, pref was disabled, access OK' );
     };
 
     C4::Context->_new_userenv; # For next tests