get(route('login')); $response->assertOk(); }); test('users can authenticate using the login screen', function () { $user = User::factory()->create(); $response = $this->post(route('login.store'), [ 'email' => $user->email, 'password' => 'password', ]); $response ->assertSessionHasNoErrors() ->assertRedirect(route('admin.dashboard', absolute: false)); $this->assertAuthenticated(); }); test('users can not authenticate with invalid password', function () { $user = User::factory()->create(); $response = $this->post(route('login.store'), [ 'email' => $user->email, 'password' => 'wrong-password', ]); $response->assertSessionHasErrorsIn('email'); $this->assertGuest(); }); test('the login limit per e-mail holds when each attempt claims another address', function () { $user = User::factory()->create(); for ($i = 1; $i <= 20; $i++) { $response = $this->withHeader('X-Forwarded-For', "203.0.113.$i")->post(route('login.store'), [ 'email' => $user->email, 'password' => 'wrong-password', ]); if ($i === 1) { expect($response->status())->not->toBe(429); } } $this->withHeader('X-Forwarded-For', '203.0.113.21')->post(route('login.store'), [ 'email' => $user->email, 'password' => 'password', ])->assertTooManyRequests(); $this->assertGuest(); }); test('users with two factor enabled are redirected to two factor challenge', function () { if (! Features::canManageTwoFactorAuthentication()) { $this->markTestSkipped('Two-factor authentication is not enabled.'); } Features::twoFactorAuthentication([ 'confirm' => true, 'confirmPassword' => true, ]); $user = User::factory()->withTwoFactor()->create(); $response = $this->post(route('login.store'), [ 'email' => $user->email, 'password' => 'password', ]); $response->assertRedirect(route('two-factor.login')); $this->assertGuest(); }); test('users can logout', function () { $user = User::factory()->create(); $response = $this->actingAs($user)->post(route('logout')); $response->assertRedirect(route('home')); $this->assertGuest(); });