From 31450d8f2f07738e349c8c600f49275966f61fa5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 22 Apr 2022 12:24:17 +0200 Subject: [PATCH] Bug 29894: Add Selenium tests for disable 2FA Signed-off-by: Jonathan Druart Signed-off-by: Fridolin Somers --- t/db_dependent/selenium/authentication_2fa.t | 36 +++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/selenium/authentication_2fa.t b/t/db_dependent/selenium/authentication_2fa.t index 8e14a185f8..ceda62fcff 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 . use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use C4::Context; use Koha::AuthUtils; @@ -147,6 +147,40 @@ SKIP: { } }; + subtest "Disable" => sub { + plan tests => 4; + + my $mainpage = $s->base_url . q|mainpage.pl|; + $driver->get( $mainpage . q|?logout.x=1| ); + fill_login_form($s); + my $auth = Koha::Auth::TwoFactorAuth->new( { patron => $patron } ); + my $code = $auth->code(); + $auth->clear; + $driver->find_element('//form[@id="loginform"]//input[@id="otp_token"]') + ->send_keys($code); + $driver->find_element('//input[@type="submit"]')->click; + + $driver->get( $s->base_url . q|members/two_factor_auth.pl| ); + + is( + $driver->find_element('//div[@class="two-factor-status"]')->get_text(), + 'Status: Enabled', + '2FA is enabled' + ); + + $driver->find_element('//form[@id="two-factor-auth"]//input[@type="submit"]')->click; + + is( + $driver->find_element('//div[@class="two-factor-status"]')->get_text(), + 'Status: Disabled', + '2FA has been disabled' + ); + + $patron = $patron->get_from_storage; + is( $patron->secret, undef, "Secret has been cleared" ); + is( $patron->auth_method(), 'password', 'auth_method has been reset to "password"' ); + }; + $driver->quit(); }; -- 2.39.5