Bugzilla – Attachment 138958 Details for
Bug 30588
Add the option to require 2FA setup on first staff login
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30588: Add selenium tests
Bug-30588-Add-selenium-tests.patch (text/plain), 4.53 KB, created by
Jonathan Druart
on 2022-08-10 08:24:44 UTC
(
hide
)
Description:
Bug 30588: Add selenium tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-08-10 08:24:44 UTC
Size:
4.53 KB
patch
obsolete
>From 1eb9d3318f1b32112865e3550341f3598be601e7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 26 Jul 2022 14:51:54 +0200 >Subject: [PATCH] Bug 30588: Add selenium tests > >Sponsored-by: Rijksmuseum, Netherlands >--- > .../intranet-tmpl/prog/en/modules/auth.tt | 1 + > t/db_dependent/selenium/authentication_2fa.t | 65 ++++++++++++++++++- > 2 files changed, 64 insertions(+), 2 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt >index 50f4d7a0872..8f8affb01fe 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt >@@ -9,6 +9,7 @@ > [% INCLUDE 'doc-head-open.inc' %] > <title> > [% IF TwoFA_prompt %]Two-factor authentication[% END %] >+ [% IF TwoFA_setup %]Two-factor authentication setup[% END %] > [% IF ( loginprompt ) %]Log in to Koha[% END %] > [% IF too_many_login_attempts %]This account has been locked. > [% ELSIF invalid_username_or_password %]Invalid username or password[% END %] >diff --git a/t/db_dependent/selenium/authentication_2fa.t b/t/db_dependent/selenium/authentication_2fa.t >index a917e191f86..81e75f2f065 100755 >--- a/t/db_dependent/selenium/authentication_2fa.t >+++ b/t/db_dependent/selenium/authentication_2fa.t >@@ -16,7 +16,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 4; >+use Test::More tests => 5; > > use C4::Context; > use Koha::AuthUtils; >@@ -52,10 +52,11 @@ SKIP: { > $driver->get($mainpage); > like( $driver->get_title, qr(Log in to Koha), 'Hitting the main page should redirect to the login form'); > >+ C4::Context->set_preference('TwoFactorAuthentication', 'disabled'); >+ > fill_login_form($s); > like( $driver->get_title, qr(Koha staff interface), 'Patron with flags superlibrarian should be able to login' ); > >- C4::Context->set_preference('TwoFactorAuthentication', 'disabled'); > $driver->get($s->base_url . q|members/two_factor_auth.pl|); > like( $driver->get_title, qr(Error 404), 'Must be redirected to 404 is the pref is off' ); > >@@ -229,6 +230,66 @@ SKIP: { > #); > }; > >+ subtest "Enforce 2FA setup on first login" => sub { >+ plan tests => 7; >+ >+ C4::Context->set_preference( 'TwoFactorAuthentication', 'enforced' ); >+ >+ # Make sure the send won't fail because of invalid email addresses >+ $patron->library->set( >+ { >+ branchemail => 'from@example.org', >+ branchreturnpath => undef, >+ branchreplyto => undef, >+ } >+ )->store; >+ $patron->auth_method('password'); >+ $patron->email(undef); >+ $patron->store; >+ >+ my $mainpage = $s->base_url . q|mainpage.pl|; >+ $driver->get( $mainpage . q|?logout.x=1| ); >+ like( >+ $driver->get_title, >+ qr(Log in to Koha), >+ 'Must be on the first auth screen' >+ ); >+ fill_login_form($s); >+ like( >+ $driver->get_title, >+ qr(Two-factor authentication setup), >+ 'Must be on the 2FA auth setup screen' >+ ); >+ >+ $s->wait_for_ajax; # There is an ajax request to populate the qr_code and the secret >+ >+ isnt( $driver->find_element('//*[@id="qr_code"]')->get_attribute("src"), "" ); >+ my $secret32 = $driver->find_element('//*[@id="secret32"]')->get_value; >+ >+ my $auth = Koha::Auth::TwoFactorAuth->new( >+ { patron => $patron, secret32 => $secret32 } ); >+ my $pin_code = $auth->code; >+ >+ $driver->find_element('//*[@id="pin_code"]')->send_keys("wrong code"); >+ $driver->find_element('//*[@id="register-2FA"]')->click; >+ $s->wait_for_ajax; >+ is( $driver->find_element('//*[@id="errors"]')->get_text, >+ "Invalid PIN code" ); >+ >+ $driver->find_element('//*[@id="pin_code"]')->clear; >+ $driver->find_element('//*[@id="pin_code"]')->send_keys($pin_code); >+ $driver->find_element('//*[@id="register-2FA"]')->click; >+ is( $driver->get_alert_text, >+ "Two-factor authentication correctly configured. You will be redirected to the login screen." >+ ); >+ $driver->accept_alert; >+ # FIXME How to test the redirect to the mainpage here >+ >+ $patron = $patron->get_from_storage; >+ is( $patron->auth_method, 'two-factor', ); >+ isnt( $patron->secret, undef, ); >+ }; >+ > subtest "Disable" => sub { > plan tests => 6; > >-- >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 30588
:
138160
|
138161
|
138162
|
138163
|
138164
|
138165
|
138166
|
138191
|
138193
|
138953
|
138954
|
138955
|
138956
|
138957
|
138958
|
138959
|
138960
|
138961
|
138962
|
140365
|
140366
|
140367
|
140368
|
140369
|
140416
|
140417
|
140418
|
140419
|
140420
|
140421
|
140422
|
140423
|
140424
|
140425
|
140426
|
140427
|
140428
|
140429
|
140430
|
141978
|
141979
|
141980
|
141981
|
141982
|
141983
|
141984
|
141985
|
141986
|
141987
|
141988
|
141989
|
141990
|
141991
|
141992
|
142344
|
142345
|
142346
|
142347
|
142348
|
142349
|
142350
|
142351
|
142352
|
142353
|
142354
|
142355
|
142356
|
142357
|
142358