diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-02-02 08:52:58 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-02-07 12:11:54 +0000 |
commit | b4b6679f6aac821ac31e541e0cc6f05549b130b5 (patch) | |
tree | 9d5f1ab9ab3af93672c11b8cf8998f4cf0878631 /t/app/controller/auth.t | |
parent | 3ec1e871a1a04cd1f6ce051d1a6247acf2220ac2 (diff) |
Add two-factor authentication for superusers.
Diffstat (limited to 't/app/controller/auth.t')
-rw-r--r-- | t/app/controller/auth.t | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 8d60137a2..70b970e2b 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -276,3 +276,26 @@ subtest "check logging in with token" => sub { $mech->delete_header('Authorization'); }; + +subtest "Test two-factor authentication login" => sub { + use Auth::GoogleAuth; + my $auth = Auth::GoogleAuth->new; + my $code = $auth->code; + my $wrong_code = $auth->code(undef, time() - 120); + + my $user = FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + $user->is_superuser(1); + $user->password('password'); + $user->set_extra_metadata('2fa_secret', $auth->secret32); + $user->update; + + $mech->get_ok('/auth'); + $mech->submit_form_ok( + { with_fields => { username => $test_email, password_sign_in => 'password' } }, + "sign in using form" ); + $mech->content_contains('Please generate a two-factor code'); + $mech->submit_form_ok({ with_fields => { '2fa_code' => $wrong_code } }, "provide wrong 2FA code" ); + $mech->content_contains('Try again'); + $mech->submit_form_ok({ with_fields => { '2fa_code' => $code } }, "provide correct 2FA code" ); + $mech->logged_in_ok; +}; |