[ 'user_id' => $user->id, 'email' => $user->email, 'remember' => false, 'step' => PendingLoginService::STEP_2FA, 'attempts' => $attempts, 'expires_at' => now()->addSeconds(PendingLoginService::TTL_SECONDS)->getTimestamp(), ], ]; } it('applies throttle middleware to the 2FA verify route', function () { $route = collect(Route::getRoutes())->first(function ($r) { return $r->uri() === 'login/2fa' && in_array('POST', $r->methods()); }); expect($route)->not->toBeNull(); $hasThrottle = collect($route->gatherMiddleware()) ->contains(fn ($m) => is_string($m) && str_starts_with($m, 'throttle')); expect($hasThrottle)->toBeTrue(); }); it('audit-logs a failed 2FA verification', function () { $google2fa = new Google2FA; $secret = $google2fa->generateSecretKey(); $user = User::factory()->create(['2fa_secret' => $secret, '2fa_enabled' => true]); $user->refresh(); // A wrong 6-digit code against an active pending 2FA login. $this->withSession(pending2faSession($user)) ->post('/login/2fa', ['code' => '000000']); expect( AccountLog::where('user_id', $user->id) ->where('action', 'auth.2fa.failed') ->exists() )->toBeTrue(); });