Added test

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2025-04-01 17:44:44 +01:00
parent 5d265f5bfd
commit 6c47f1c07f

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Authentication;
namespace Feature\Authentication;
use App\Models\User;
use Tests\TestCase;
@ -9,6 +9,7 @@ class LoginTest extends TestCase
{
public function testLogsFailedLoginAttempt()
{
User::factory()->create(['username' => 'username_here']);
$this->withServerVariables(['REMOTE_ADDR' => '127.0.0.100'])
@ -27,6 +28,39 @@ class LoginTest extends TestCase
]);
}
public function testLoginThrottleConfigIsRespected()
{
// Why do we need this? The app should already be set up
User::factory()->create(['username' => 'username_here']);
config(['auth.passwords.users.throttle.max_attempts' => 1]);
config(['auth.passwords.users.throttle.lockout_duration' => 1]);
for ($i = 0; $i < 2; ++$i) {
$this->from('/login')
->withServerVariables(['REMOTE_ADDR' => '127.0.0.100'])
->post('/login', [
'username' => 'invalid username',
'password' => 'invalid password',
]);
}
$response = $this->from('/login')
->withServerVariables(['REMOTE_ADDR' => '127.0.0.100'])
->post('/login', [
'username' => 'invalid username',
'password' => 'invalid password',
])
->assertSessionHasErrors(['username'])
->assertStatus(302)
->assertRedirect('/login');
$this->followRedirects($response)->assertSee(trans('auth.throttle', ['minutes' => 1]));
}
public function testLogsSuccessfulLogin()
{
User::factory()->create(['username' => 'username_here']);