Add tests around loggin login attempts
This commit is contained in:
parent
2d3514bbf8
commit
b8b0e3200e
1 changed files with 49 additions and 0 deletions
49
tests/Feature/Authentication/LoginTest.php
Normal file
49
tests/Feature/Authentication/LoginTest.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Authentication;
|
||||
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
public function testLogsFailedLoginAttempt()
|
||||
{
|
||||
User::factory()->create(['username' => 'username_here']);
|
||||
|
||||
$this->withServerVariables(['REMOTE_ADDR' => '127.0.0.100'])
|
||||
->post('/login', [
|
||||
'username' => 'username_here',
|
||||
'password' => 'not a real password',
|
||||
], [
|
||||
'User-Agent' => 'Some Custom User Agent',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('login_attempts', [
|
||||
'username' => 'username_here',
|
||||
'remote_ip' => '127.0.0.100',
|
||||
'user_agent' => 'Some Custom User Agent',
|
||||
'successful' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testLogsSuccessfulLogin()
|
||||
{
|
||||
User::factory()->create(['username' => 'username_here']);
|
||||
|
||||
$this->withServerVariables(['REMOTE_ADDR' => '127.0.0.100'])
|
||||
->post('/login', [
|
||||
'username' => 'username_here',
|
||||
'password' => 'password',
|
||||
], [
|
||||
'User-Agent' => 'Some Custom User Agent',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('login_attempts', [
|
||||
'username' => 'username_here',
|
||||
'remote_ip' => '127.0.0.100',
|
||||
'user_agent' => 'Some Custom User Agent',
|
||||
'successful' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue