get(route('login')); $response->assertOk(); } public function test_users_can_authenticate_using_the_login_screen() { $user = User::factory()->create(); $response = $this->post(route('login.store'), [ 'email' => $user->email, 'password' => 'password', ]); $this->assertAuthenticated(); $response->assertRedirect(route('dashboard', absolute: false)); } public function test_users_with_two_factor_enabled_are_redirected_to_two_factor_challenge() { $this->skipUnlessFortifyHas(Features::twoFactorAuthentication()); Features::twoFactorAuthentication([ 'confirm' => true, 'confirmPassword' => true, ]); $user = User::factory()->withTwoFactor()->create(); $response = $this->post(route('login'), [ 'email' => $user->email, 'password' => 'password', ]); $response->assertRedirect(route('two-factor.login')); $response->assertSessionHas('login.id', $user->id); $this->assertGuest(); } public function test_users_can_not_authenticate_with_invalid_password() { $user = User::factory()->create(); $this->post(route('login.store'), [ 'email' => $user->email, 'password' => 'wrong-password', ]); $this->assertGuest(); } public function test_users_can_logout() { $user = User::factory()->create(); $response = $this->actingAs($user)->post(route('logout')); $response->assertRedirect(route('home')); $this->assertGuest(); } public function test_users_are_rate_limited() { $user = User::factory()->create(); RateLimiter::increment(md5('login'.implode('|', [$user->email, '127.0.0.1'])), amount: 5); $response = $this->post(route('login.store'), [ 'email' => $user->email, 'password' => 'wrong-password', ]); $response->assertTooManyRequests(); } }