Lines 16-22
Link Here
|
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
use Test::More tests => 4; |
19 |
use Test::More tests => 5; |
20 |
|
20 |
|
21 |
use C4::Context; |
21 |
use C4::Context; |
22 |
use Koha::AuthUtils; |
22 |
use Koha::AuthUtils; |
Lines 52-61
SKIP: {
Link Here
|
52 |
$driver->get($mainpage); |
52 |
$driver->get($mainpage); |
53 |
like( $driver->get_title, qr(Log in to Koha), 'Hitting the main page should redirect to the login form'); |
53 |
like( $driver->get_title, qr(Log in to Koha), 'Hitting the main page should redirect to the login form'); |
54 |
|
54 |
|
|
|
55 |
C4::Context->set_preference('TwoFactorAuthentication', 'disabled'); |
56 |
|
55 |
fill_login_form($s); |
57 |
fill_login_form($s); |
56 |
like( $driver->get_title, qr(Koha staff interface), 'Patron with flags superlibrarian should be able to login' ); |
58 |
like( $driver->get_title, qr(Koha staff interface), 'Patron with flags superlibrarian should be able to login' ); |
57 |
|
59 |
|
58 |
C4::Context->set_preference('TwoFactorAuthentication', 'disabled'); |
|
|
59 |
$driver->get($s->base_url . q|members/two_factor_auth.pl|); |
60 |
$driver->get($s->base_url . q|members/two_factor_auth.pl|); |
60 |
like( $driver->get_title, qr(Error 404), 'Must be redirected to 404 is the pref is off' ); |
61 |
like( $driver->get_title, qr(Error 404), 'Must be redirected to 404 is the pref is off' ); |
61 |
|
62 |
|
Lines 229-234
SKIP: {
Link Here
|
229 |
#); |
230 |
#); |
230 |
}; |
231 |
}; |
231 |
|
232 |
|
|
|
233 |
subtest "Enforce 2FA setup on first login" => sub { |
234 |
plan tests => 7; |
235 |
|
236 |
C4::Context->set_preference( 'TwoFactorAuthentication', 'enforced' ); |
237 |
|
238 |
# Make sure the send won't fail because of invalid email addresses |
239 |
$patron->library->set( |
240 |
{ |
241 |
branchemail => 'from@example.org', |
242 |
branchreturnpath => undef, |
243 |
branchreplyto => undef, |
244 |
} |
245 |
)->store; |
246 |
$patron->auth_method('password'); |
247 |
$patron->email(undef); |
248 |
$patron->store; |
249 |
|
250 |
my $mainpage = $s->base_url . q|mainpage.pl|; |
251 |
$driver->get( $mainpage . q|?logout.x=1| ); |
252 |
like( |
253 |
$driver->get_title, |
254 |
qr(Log in to Koha), |
255 |
'Must be on the first auth screen' |
256 |
); |
257 |
fill_login_form($s); |
258 |
like( |
259 |
$driver->get_title, |
260 |
qr(Two-factor authentication setup), |
261 |
'Must be on the 2FA auth setup screen' |
262 |
); |
263 |
|
264 |
$s->wait_for_ajax; # There is an ajax request to populate the qr_code and the secret |
265 |
|
266 |
isnt( $driver->find_element('//*[@id="qr_code"]')->get_attribute("src"), "" ); |
267 |
my $secret32 = $driver->find_element('//*[@id="secret32"]')->get_value; |
268 |
|
269 |
my $auth = Koha::Auth::TwoFactorAuth->new( |
270 |
{ patron => $patron, secret32 => $secret32 } ); |
271 |
my $pin_code = $auth->code; |
272 |
|
273 |
$driver->find_element('//*[@id="pin_code"]')->send_keys("wrong code"); |
274 |
$driver->find_element('//*[@id="register-2FA"]')->click; |
275 |
$s->wait_for_ajax; |
276 |
is( $driver->find_element('//*[@id="errors"]')->get_text, |
277 |
"Invalid PIN code" ); |
278 |
|
279 |
$driver->find_element('//*[@id="pin_code"]')->clear; |
280 |
$driver->find_element('//*[@id="pin_code"]')->send_keys($pin_code); |
281 |
$driver->find_element('//*[@id="register-2FA"]')->click; |
282 |
is( $driver->get_alert_text, |
283 |
"Two-factor authentication correctly configured. You will be redirected to the login screen." |
284 |
); |
285 |
$driver->accept_alert; |
286 |
# FIXME How to test the redirect to the mainpage here |
287 |
|
288 |
$patron = $patron->get_from_storage; |
289 |
is( $patron->auth_method, 'two-factor', ); |
290 |
isnt( $patron->secret, undef, ); |
291 |
}; |
292 |
|
232 |
subtest "Disable" => sub { |
293 |
subtest "Disable" => sub { |
233 |
plan tests => 6; |
294 |
plan tests => 6; |
234 |
|
295 |
|
235 |
- |
|
|