capture wtf garbage from login failures

This commit is contained in:
Spine
2025-10-01 09:34:01 +02:00
parent de779923e0
commit b19dfa460f
4 changed files with 44 additions and 1 deletions
+16
View File
@@ -3,6 +3,7 @@
namespace Gazelle;
use PHPUnit\Framework\TestCase;
use GazelleUnitTest\Helper;
class UserCreateTest extends TestCase {
protected User $user;
@@ -60,6 +61,11 @@ class UserCreateTest extends TestCase {
$login = new Login();
$watch = new LoginWatch($login->requestContext()->remoteAddr());
$watch->clearAttempts();
$this->assertEquals(
$login->requestContext()->remoteAddr(),
$watch->ipaddr(),
'user-login-watch-ipaddr'
);
$this->assertNull(
$login->login($this->user->username(), 'not-the-password!', $watch),
@@ -82,6 +88,9 @@ class UserCreateTest extends TestCase {
);
$this->assertEquals(2, $watch->nrAttempts(), 'user-create-two-login-attempts');
$this->assertEquals(60, (int)$watch->bannedEpoch() - time(), 'user-login-ban-epoch');
$this->assertTrue(Helper::futureDate($watch->bannedUntil(), 70), 'user-login-temporary-ban');
$this->assertEquals(0, $watch->clearPriorBan(), 'user-login-clear-ban');
$this->user->setField('Enabled', Enum\UserStatus::enabled->value)->modify();
$enabledUser = $login->login($this->user->username(), 'password', $watch);
@@ -89,6 +98,8 @@ class UserCreateTest extends TestCase {
$this->assertEquals(0, $watch->nrAttempts(), 'user-create-two-login-cleared');
// check the table if this fails
$this->assertEquals(0, $watch->nrBans(), 'user-create-two-login-banned');
$this->assertEquals($this->user->username(), $watch->capture(), 'user-login-capture');
$this->assertGreaterThanOrEqual(0, $watch->activeTotal(), 'user-login-watch-total-sql');
$relogin = new Login();
$watch->clearAttempts();
@@ -104,6 +115,11 @@ class UserCreateTest extends TestCase {
$warning->subject(),
'user-login-pm-subject'
);
$this->assertEquals(
0,
$watch->setClear([], $this->user),
'user-login-watch-no-clear',
);
$this->assertEquals(
1,
$watch->setClear([$watch->id()], $this->user),