fix(security): emit authentication success events

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-06 00:08:58 -04:00
parent 5b3e8f6588
commit b14bd302a3
8 changed files with 183 additions and 52 deletions
@@ -6,6 +6,7 @@ namespace KTXT\Unit\Event;
use KTXC\Security\Event\AuthenticationSucceededEvent;
use KTXC\Security\Event\SecurityEventSeverity;
use KTXC\Security\Event\SecurityRequestEventInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;
@@ -17,35 +18,24 @@ final class AuthenticationSucceededEventTest extends TestCase
public function constructsTypedState(): void
{
$event = new AuthenticationSucceededEvent(
'203.0.113.10',
'user-a',
'tenant-a',
'device-a',
);
self::assertSame(AuthenticationSucceededEvent::class, $event->getName());
self::assertSame('203.0.113.10', $event->getIpAddress());
self::assertSame('user-a', $event->getUserId());
self::assertSame('tenant-a', $event->getTenantId());
self::assertSame('device-a', $event->getDeviceFingerprint());
self::assertSame(['userId' => 'user-a'], $event->getData());
self::assertSame(SecurityEventSeverity::INFO, $event->getSeverity());
self::assertNotInstanceOf(SecurityRequestEventInterface::class, $event);
}
#[Test]
#[TestDox('Successful authentication requires an IP address and user ID')]
#[TestDox('Successful authentication requires a user ID')]
public function rejectsIncompleteAuthenticationContext(): void
{
foreach ([
['', 'user-a'],
['203.0.113.10', ''],
] as $arguments) {
try {
new AuthenticationSucceededEvent(...$arguments);
self::fail('Incomplete successful-authentication context was accepted.');
} catch (\InvalidArgumentException) {
$this->addToAssertionCount(1);
}
}
$this->expectException(\InvalidArgumentException::class);
new AuthenticationSucceededEvent('');
}
}