Bugzilla – Attachment 132149 Details for
Bug 28786
Two-factor authentication for staff client - TOTP
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28786: Add tests for checkauth
Bug-28786-Add-tests-for-checkauth.patch (text/plain), 5.17 KB, created by
Jonathan Druart
on 2022-03-24 13:30:30 UTC
(
hide
)
Description:
Bug 28786: Add tests for checkauth
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-03-24 13:30:30 UTC
Size:
5.17 KB
patch
obsolete
>From 3cda72a4e1f5537c3fd57d72476d51a23d33496b Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 13 Sep 2021 23:19:24 +0200 >Subject: [PATCH] Bug 28786: Add tests for checkauth > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > t/db_dependent/Auth.t | 83 ++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 82 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t >index a6fbc448e38..4c29f2c1fb6 100755 >--- a/t/db_dependent/Auth.t >+++ b/t/db_dependent/Auth.t >@@ -20,6 +20,7 @@ use C4::Members; > use Koha::AuthUtils qw/hash_password/; > use Koha::Database; > use Koha::Patrons; >+use Koha::Auth::TwoFactorAuth; > > BEGIN { > use_ok('C4::Auth', qw( checkauth haspermission track_login_daily checkpw get_template_and_user checkpw_hash )); >@@ -38,7 +39,7 @@ $schema->storage->txn_begin; > > subtest 'checkauth() tests' => sub { > >- plan tests => 4; >+ plan tests => 5; > > my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } }); > >@@ -108,6 +109,86 @@ subtest 'checkauth() tests' => sub { > is( $userid, undef, 'If librarian user is used and password with GET, they should not be logged in' ); > }; > >+ subtest 'Two-factor authentication' => sub { >+ >+ my $patron = $builder->build_object( >+ { class => 'Koha::Patrons', value => { flags => 1 } } ); >+ my $password = 'password'; >+ $patron->set_password( { password => $password } ); >+ $cgi = Test::MockObject->new(); >+ >+ my $otp_token; >+ our ( $logout, $sessionID, $verified ); >+ $cgi->mock( >+ 'param', >+ sub { >+ my ( $self, $param ) = @_; >+ if ( $param eq 'userid' ) { return $patron->userid; } >+ elsif ( $param eq 'password' ) { return $password; } >+ elsif ( $param eq 'otp_token' ) { return $otp_token; } >+ elsif ( $param eq 'logout.x' ) { return $logout; } >+ else { return; } >+ } >+ ); >+ $cgi->mock( 'request_method', sub { return 'POST' } ); >+ $cgi->mock( 'cookie', sub { return $sessionID } ); >+ >+ my $two_factor_auth = Test::MockModule->new( 'Koha::Auth::TwoFactorAuth' ); >+ $two_factor_auth->mock( 'verify', sub {$verified} ); >+ >+ my ( $userid, $cookie, $flags ); >+ ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 'authrequired', undef, 'intranet' ); >+ >+ sub logout { >+ my $cgi = shift; >+ $logout = 1; >+ undef $sessionID; >+ C4::Auth::checkauth( $cgi, 'authrequired', undef, 'intranet' ); >+ $logout = 0; >+ } >+ >+ t::lib::Mocks::mock_preference( 'TwoFactorAuthentication', 0 ); >+ $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; >+ ( $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); >+ >+ t::lib::Mocks::mock_preference( 'TwoFactorAuthentication', 1 ); >+ $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; >+ ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 'authrequired', undef, 'intranet' ); >+ is( $userid, $patron->userid, 'Succesful login' ); >+ my $session = C4::Auth::get_session($sessionID); >+ is( C4::Auth::get_session($sessionID)->param('waiting-for-2FA'), 1, 'Second auth required' ); >+ >+ # Wrong OTP token >+ $otp_token = "wrong"; >+ $verified = 0; >+ $patron->auth_method('two-factor')->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'), 1, 'Second auth still required after wrong OTP token' ); >+ >+ $otp_token = "good"; >+ $verified = 1; >+ ( $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'), 0, 'Second auth no longer required if OTP token has been verified' ); >+ >+ }; >+ > C4::Context->_new_userenv; # For next tests > > }; >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 28786
:
123375
|
123376
|
123377
|
123378
|
123379
|
123380
|
123381
|
123397
|
123398
|
123399
|
123400
|
123401
|
123402
|
123403
|
124569
|
124770
|
124771
|
124844
|
124845
|
124846
|
124847
|
128841
|
128842
|
129383
|
129384
|
129474
|
129521
|
129557
|
129558
|
129559
|
129560
|
129561
|
129562
|
129563
|
129564
|
129565
|
129566
|
129567
|
129568
|
129569
|
129654
|
129655
|
129656
|
129657
|
129658
|
129659
|
129660
|
129661
|
129662
|
129665
|
131940
|
131941
|
131942
|
131943
|
131944
|
131945
|
131946
|
131947
|
131948
|
131949
|
131950
|
131951
|
131952
|
131953
|
131954
|
131955
|
131956
|
131957
|
131958
|
132142
|
132143
|
132144
|
132145
|
132146
|
132147
|
132148
| 132149 |
132150
|
132153
|
132154
|
132155
|
132156
|
132157
|
133222
|
133516
|
133522
|
133531
|
133533
|
133541
|
133548
|
133643
|
133686