| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
-
- namespace Tests\Feature\Auth;
-
- use App\Models\User;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Support\Facades\RateLimiter;
- use Laravel\Fortify\Features;
- use Tests\TestCase;
-
- class AuthenticationTest extends TestCase
- {
- use RefreshDatabase;
-
- public function test_login_screen_can_be_rendered()
- {
- $response = $this->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();
- }
- }
|