]> BookStack Code Mirror - bookstack/commitdiff
MFA: Copied autocomplete changes from totp to backup codes
authorDan Brown <redacted>
Sun, 10 Mar 2024 18:31:01 +0000 (18:31 +0000)
committerDan Brown <redacted>
Sun, 10 Mar 2024 18:31:01 +0000 (18:31 +0000)
Also added tests to cover.
Related to #4849

resources/views/mfa/parts/verify-backup_codes.blade.php
tests/Auth/MfaVerificationTest.php

index 0e5b8208642a87116633e073a6886b06b4b3b73b..3e28f71c6dbf90a86f3e786e391c1cd5697ce74d 100644 (file)
@@ -2,10 +2,11 @@
 
 <p class="small mb-m">{{ trans('auth.mfa_verify_backup_code_desc') }}</p>
 
-<form action="{{ url('/mfa/backup_codes/verify') }}" method="post">
+<form action="{{ url('/mfa/backup_codes/verify') }}" method="post" autocomplete="off">
     {{ csrf_field() }}
     <input type="text"
            name="code"
+           autocomplete="one-time-code"
            placeholder="{{ trans('auth.mfa_verify_backup_code_enter_here') }}"
            class="input-fill-width {{ $errors->has('code') ? 'neg' : '' }}">
     @if($errors->has('code'))
index 2fa272e331cd6bd5e56ee7a170456e566231fd25..76c59bc748b0a9ef2e79359e9239a31b8610ab24 100644 (file)
@@ -57,6 +57,15 @@ class MfaVerificationTest extends TestCase
         $this->assertNull(auth()->user());
     }
 
+    public function test_totp_form_has_autofill_configured()
+    {
+        [$user, $secret, $loginResp] = $this->startTotpLogin();
+        $html = $this->withHtml($this->get('/mfa/verify'));
+
+        $html->assertElementExists('form[autocomplete="off"][action$="/verify"]');
+        $html->assertElementExists('input[autocomplete="one-time-code"][name="code"]');
+    }
+
     public function test_backup_code_verification()
     {
         [$user, $codes, $loginResp] = $this->startBackupCodeLogin();
@@ -138,6 +147,15 @@ class MfaVerificationTest extends TestCase
         $resp->assertSeeText('You have less than 5 backup codes remaining, Please generate and store a new set before you run out of codes to prevent being locked out of your account.');
     }
 
+    public function test_backup_code_form_has_autofill_configured()
+    {
+        [$user, $codes, $loginResp] = $this->startBackupCodeLogin();
+        $html = $this->withHtml($this->get('/mfa/verify'));
+
+        $html->assertElementExists('form[autocomplete="off"][action$="/verify"]');
+        $html->assertElementExists('input[autocomplete="one-time-code"][name="code"]');
+    }
+
     public function test_both_mfa_options_available_if_set_on_profile()
     {
         $user = $this->users->editor();