@@ -106,7 +106,9 @@ public function testMissingTurnstileResponseFailsValidationWhenAtThreshold(): vo
106106 $ user = $ this ->getTestUser ();
107107 $ this ->setLoginAttempts ($ user , self ::CAPTCHA_THRESHOLD );
108108
109- $ this ->postLogin (); // no cf-turnstile-response
109+ $ this ->postLogin ([
110+ "login_attempts " => self ::CAPTCHA_THRESHOLD ,
111+ ]); // no cf-turnstile-response
110112
111113 $ this ->assertTrue (
112114 $ this ->sessionHasValidationError ('cf-turnstile-response ' ),
@@ -138,34 +140,17 @@ public function testLoginAtThresholdWithValidTokenPassesValidation(): void
138140
139141 $ this ->fakeTurnstilePass ();
140142
141- $ this ->postLogin (['cf-turnstile-response ' => 'dummy-token-accepted-by-mock ' ]);
143+ $ this ->postLogin ([
144+ 'cf-turnstile-response ' => 'dummy-token-accepted-by-mock ' ,
145+ 'login_attempts ' => 1
146+ ]);
142147
143148 $ this ->assertFalse (
144149 $ this ->sessionHasValidationError ('cf-turnstile-response ' ),
145150 'A valid Turnstile token must clear the captcha validation rule '
146151 );
147152 }
148153
149- // -------------------------------------------------------------------------
150- // 3. Server-side login-attempt lookup: user exists vs. does not exist
151- // -------------------------------------------------------------------------
152-
153- public function testLoginAttemptsLoadedFromExistingUserRecord (): void
154- {
155- $ user = $ this ->getTestUser ();
156- $ this ->setLoginAttempts ($ user , self ::CAPTCHA_THRESHOLD );
157-
158- // Omit cf-turnstile-response. If the controller had NOT read the DB value it
159- // would see login_attempts = 0 and skip the captcha rule. The error proves
160- // the persisted attempt count was used.
161- $ this ->postLogin ();
162-
163- $ this ->assertTrue (
164- $ this ->sessionHasValidationError ('cf-turnstile-response ' ),
165- 'Expected captcha required error, which proves login_failed_attempt was read from DB '
166- );
167- }
168-
169154 public function testLoginAttemptsDefaultToZeroForUnknownUsername (): void
170155 {
171156 // No user with this email → auth_service->getUserByUsername() returns null
@@ -216,7 +201,10 @@ public function testExpiredTurnstileTokenFailsValidation(): void
216201 // Cloudflare API returns success=false (expired / already-used token)
217202 $ this ->fakeTurnstileFail ();
218203
219- $ this ->postLogin (['cf-turnstile-response ' => 'expired-or-invalid-token ' ]);
204+ $ this ->postLogin ([
205+ 'cf-turnstile-response ' => 'expired-or-invalid-token ' ,
206+ 'login_attempts ' => self ::CAPTCHA_THRESHOLD
207+ ]);
220208
221209 $ this ->assertTrue (
222210 $ this ->sessionHasValidationError ('cf-turnstile-response ' ),
@@ -230,7 +218,10 @@ public function testUnsolvedCaptchaEmptyTokenFailsValidation(): void
230218 $ this ->setLoginAttempts ($ user , self ::CAPTCHA_THRESHOLD );
231219
232220 // Empty string triggers the 'required' rule before any Cloudflare call
233- $ this ->postLogin (['cf-turnstile-response ' => '' ]);
221+ $ this ->postLogin ([
222+ 'cf-turnstile-response ' => '' ,
223+ 'login_attempts ' => self ::CAPTCHA_THRESHOLD
224+ ]);
234225
235226 $ this ->assertTrue (
236227 $ this ->sessionHasValidationError ('cf-turnstile-response ' ),
0 commit comments