@@ -66,6 +66,27 @@ public function test_totp_form_has_autofill_configured()
6666 $ html ->assertElementExists ('input[autocomplete="one-time-code"][name="code"] ' );
6767 }
6868
69+ public function test_totp_verification_is_rate_limited ()
70+ {
71+ [$ user , $ secret , $ loginResp ] = $ this ->startTotpLogin ();
72+ $ loginService = $ this ->app ->make (LoginService::class);
73+
74+ $ resp = $ this ->get ('/mfa/verify ' );
75+ for ($ i = 0 ; $ i < 5 ; $ i ++) {
76+ $ this ->post ('/mfa/totp/verify ' , [
77+ 'code ' => '123456 ' ,
78+ ])->assertRedirect ('/mfa/verify ' );
79+ $ this ->assertNotNull ($ loginService ->getLastLoginAttemptUser ());
80+ }
81+
82+ $ resp = $ this ->post ('/mfa/totp/verify ' , [
83+ 'code ' => '123456 ' ,
84+ ]);
85+ $ resp ->assertRedirect ('/login ' );
86+ $ this ->assertSessionError ('Too many multi-factor verification attempts. Please try again in 60 seconds. ' );
87+ $ this ->assertNull ($ loginService ->getLastLoginAttemptUser ());
88+ }
89+
6990 public function test_backup_code_verification ()
7091 {
7192 [$ user , $ codes , $ loginResp ] = $ this ->startBackupCodeLogin ();
@@ -147,6 +168,27 @@ public function test_backup_code_verification_shows_warning_when_limited_codes_r
147168 $ 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. ' );
148169 }
149170
171+ public function test_backup_code_verification_is_rate_limited ()
172+ {
173+ [$ user , $ codes , $ loginResp ] = $ this ->startBackupCodeLogin (['abc12-def45 ' , 'abc12-def46 ' ]);
174+ $ loginService = $ this ->app ->make (LoginService::class);
175+
176+ $ resp = $ this ->get ('/mfa/verify ' );
177+ for ($ i = 0 ; $ i < 5 ; $ i ++) {
178+ $ this ->post ('/mfa/backup_codes/verify ' , [
179+ 'code ' => '123456abcd ' ,
180+ ])->assertRedirect ('/mfa/verify ' );
181+ $ this ->assertNotNull ($ loginService ->getLastLoginAttemptUser ());
182+ }
183+
184+ $ resp = $ this ->post ('/mfa/backup_codes/verify ' , [
185+ 'code ' => '123456abcd ' ,
186+ ]);
187+ $ resp ->assertRedirect ('/login ' );
188+ $ this ->assertSessionError ('Too many multi-factor verification attempts. Please try again in 60 seconds. ' );
189+ $ this ->assertNull ($ loginService ->getLastLoginAttemptUser ());
190+ }
191+
150192 public function test_backup_code_form_has_autofill_configured ()
151193 {
152194 [$ user , $ codes , $ loginResp ] = $ this ->startBackupCodeLogin ();
0 commit comments