52afd35d6f
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
69 lines
2.0 KiB
PHP
69 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXT\Unit\Event;
|
|
|
|
use KTXC\Security\Event\SecurityEvent;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use PHPUnit\Framework\Attributes\TestDox;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class SecurityEventTest extends TestCase
|
|
{
|
|
#[Test]
|
|
#[TestDox('Direct construction applies the event type default severity')]
|
|
public function appliesDefaultSeverityDuringConstruction(): void
|
|
{
|
|
self::assertSame(
|
|
SecurityEvent::SEVERITY_WARNING,
|
|
(new SecurityEvent(SecurityEvent::AUTH_FAILURE))->getSeverity(),
|
|
);
|
|
self::assertSame(
|
|
SecurityEvent::SEVERITY_ERROR,
|
|
(new SecurityEvent(SecurityEvent::RATE_LIMIT_EXCEEDED))->getSeverity(),
|
|
);
|
|
self::assertSame(
|
|
SecurityEvent::SEVERITY_CRITICAL,
|
|
(new SecurityEvent(SecurityEvent::DEVICE_BLOCKED))->getSeverity(),
|
|
);
|
|
self::assertSame(
|
|
SecurityEvent::SEVERITY_INFO,
|
|
(new SecurityEvent(SecurityEvent::FIREWALL_RULE_CREATED))->getSeverity(),
|
|
);
|
|
}
|
|
|
|
#[Test]
|
|
#[TestDox('Construction can override the event type default severity')]
|
|
public function allowsSeverityOverride(): void
|
|
{
|
|
$event = new SecurityEvent(
|
|
SecurityEvent::AUTH_FAILURE,
|
|
severity: SecurityEvent::SEVERITY_CRITICAL,
|
|
);
|
|
|
|
self::assertSame(SecurityEvent::SEVERITY_CRITICAL, $event->getSeverity());
|
|
}
|
|
|
|
#[Test]
|
|
#[TestDox('Event state exposes no mutation methods')]
|
|
public function exposesNoMutationMethods(): void
|
|
{
|
|
foreach ([
|
|
'set',
|
|
'setTenantId',
|
|
'setIdentityId',
|
|
'setIpAddress',
|
|
'setDeviceFingerprint',
|
|
'setUserAgent',
|
|
'setRequestPath',
|
|
'setRequestMethod',
|
|
'setUserId',
|
|
'setReason',
|
|
'setSeverity',
|
|
] as $method) {
|
|
self::assertFalse(method_exists(SecurityEvent::class, $method));
|
|
}
|
|
}
|
|
}
|