|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\Authentication; |
| 4 | + |
| 5 | +use App\Models\User; |
| 6 | +use Tests\TestCase; |
| 7 | + |
| 8 | +class LoginTest extends TestCase |
| 9 | +{ |
| 10 | + public function testLogsFailedLoginAttempt() |
| 11 | + { |
| 12 | + User::factory()->create(['username' => 'username_here']); |
| 13 | + |
| 14 | + $this->withServerVariables(['REMOTE_ADDR' => '127.0.0.100']) |
| 15 | + ->post('/login', [ |
| 16 | + 'username' => 'username_here', |
| 17 | + 'password' => 'not a real password', |
| 18 | + ], [ |
| 19 | + 'User-Agent' => 'Some Custom User Agent', |
| 20 | + ]); |
| 21 | + |
| 22 | + $this->assertDatabaseHas('login_attempts', [ |
| 23 | + 'username' => 'username_here', |
| 24 | + 'remote_ip' => '127.0.0.100', |
| 25 | + 'user_agent' => 'Some Custom User Agent', |
| 26 | + 'successful' => 0, |
| 27 | + ]); |
| 28 | + } |
| 29 | + |
| 30 | + public function testLogsSuccessfulLogin() |
| 31 | + { |
| 32 | + User::factory()->create(['username' => 'username_here']); |
| 33 | + |
| 34 | + $this->withServerVariables(['REMOTE_ADDR' => '127.0.0.100']) |
| 35 | + ->post('/login', [ |
| 36 | + 'username' => 'username_here', |
| 37 | + 'password' => 'password', |
| 38 | + ], [ |
| 39 | + 'User-Agent' => 'Some Custom User Agent', |
| 40 | + ]); |
| 41 | + |
| 42 | + $this->assertDatabaseHas('login_attempts', [ |
| 43 | + 'username' => 'username_here', |
| 44 | + 'remote_ip' => '127.0.0.100', |
| 45 | + 'user_agent' => 'Some Custom User Agent', |
| 46 | + 'successful' => 1, |
| 47 | + ]); |
| 48 | + } |
| 49 | +} |
0 commit comments