From 84eb0e2c21ae3e443de8f548e4fe826b8de1848e Mon Sep 17 00:00:00 2001 From: Sebastian Krupinski Date: Wed, 5 Aug 2026 23:59:49 -0400 Subject: [PATCH] refactor(security): replace generic event with severity enum Signed-off-by: Sebastian Krupinski --- core/lib/Module/Module.php | 1 - core/lib/Security/Event/AccessDeniedEvent.php | 4 +- .../Event/AuthenticationFailedEvent.php | 4 +- .../Event/AuthenticationSucceededEvent.php | 4 +- .../Event/BruteForceDetectedEvent.php | 4 +- .../lib/Security/Event/DeviceBlockedEvent.php | 4 +- core/lib/Security/Event/FirewallIpEvent.php | 4 +- core/lib/Security/Event/FirewallRuleEvent.php | 4 +- .../Event/FirewallSettingsUpdatedEvent.php | 4 +- core/lib/Security/Event/IpBlockedEvent.php | 2 +- .../Security/Event/RateLimitExceededEvent.php | 4 +- core/lib/Security/Event/SecurityEvent.php | 141 ------------------ .../Security/Event/SecurityEventInterface.php | 2 +- .../Security/Event/SecurityEventSeverity.php | 14 ++ .../Event/SuspiciousActivityEvent.php | 4 +- core/lib/Service/FirewallService.php | 4 +- .../php/Unit/Event/AccessDeniedEventTest.php | 4 +- .../Event/AuthenticationFailedEventTest.php | 4 +- .../AuthenticationSucceededEventTest.php | 4 +- .../Event/BruteForceDetectedEventTest.php | 4 +- .../Unit/Event/FirewallPolicyEventTest.php | 10 +- .../php/Unit/Event/FirewallRuleEventTest.php | 4 +- .../Unit/Event/RateLimitExceededEventTest.php | 4 +- .../Unit/Event/SecurityEventSeverityTest.php | 24 +++ tests/php/Unit/Event/SecurityEventTest.php | 60 -------- .../Event/SuspiciousActivityEventTest.php | 4 +- tests/php/Unit/Module/CoreModuleTest.php | 1 - 27 files changed, 80 insertions(+), 247 deletions(-) delete mode 100644 core/lib/Security/Event/SecurityEvent.php create mode 100644 core/lib/Security/Event/SecurityEventSeverity.php create mode 100644 tests/php/Unit/Event/SecurityEventSeverityTest.php delete mode 100644 tests/php/Unit/Event/SecurityEventTest.php diff --git a/core/lib/Module/Module.php b/core/lib/Module/Module.php index d9b2f73..685265f 100644 --- a/core/lib/Module/Module.php +++ b/core/lib/Module/Module.php @@ -23,7 +23,6 @@ use KTXC\Security\Event\FirewallRuleRemovedEvent; use KTXC\Security\Event\FirewallSettingsUpdatedEvent; use KTXC\Security\Event\RateLimitExceededEvent; use KTXC\Security\Event\SuspiciousActivityEvent; -use KTXC\Security\Event\SecurityEvent; use KTXF\Event\DeliveryMode; use KTXF\Event\EventListenerRegistrarInterface; use KTXF\Module\ModuleBrowserInterface; diff --git a/core/lib/Security/Event/AccessDeniedEvent.php b/core/lib/Security/Event/AccessDeniedEvent.php index f4cc81f..6283d98 100644 --- a/core/lib/Security/Event/AccessDeniedEvent.php +++ b/core/lib/Security/Event/AccessDeniedEvent.php @@ -81,8 +81,8 @@ final class AccessDeniedEvent extends Event implements SecurityRequestEventInter return $this->reason; } - public function getSeverity(): int + public function getSeverity(): SecurityEventSeverity { - return SecurityEvent::SEVERITY_WARNING; + return SecurityEventSeverity::WARNING; } } diff --git a/core/lib/Security/Event/AuthenticationFailedEvent.php b/core/lib/Security/Event/AuthenticationFailedEvent.php index a177f70..8471645 100644 --- a/core/lib/Security/Event/AuthenticationFailedEvent.php +++ b/core/lib/Security/Event/AuthenticationFailedEvent.php @@ -32,8 +32,8 @@ final class AuthenticationFailedEvent extends Event implements SecurityEventInte return $this->reason; } - public function getSeverity(): int + public function getSeverity(): SecurityEventSeverity { - return SecurityEvent::SEVERITY_WARNING; + return SecurityEventSeverity::WARNING; } } diff --git a/core/lib/Security/Event/AuthenticationSucceededEvent.php b/core/lib/Security/Event/AuthenticationSucceededEvent.php index f191d44..bf229c0 100644 --- a/core/lib/Security/Event/AuthenticationSucceededEvent.php +++ b/core/lib/Security/Event/AuthenticationSucceededEvent.php @@ -63,8 +63,8 @@ final class AuthenticationSucceededEvent extends Event implements SecurityReques return null; } - public function getSeverity(): int + public function getSeverity(): SecurityEventSeverity { - return SecurityEvent::SEVERITY_INFO; + return SecurityEventSeverity::INFO; } } diff --git a/core/lib/Security/Event/BruteForceDetectedEvent.php b/core/lib/Security/Event/BruteForceDetectedEvent.php index 9c9fddb..df1a4d7 100644 --- a/core/lib/Security/Event/BruteForceDetectedEvent.php +++ b/core/lib/Security/Event/BruteForceDetectedEvent.php @@ -84,8 +84,8 @@ final class BruteForceDetectedEvent extends Event implements SecurityRequestEven return $this->reason; } - public function getSeverity(): int + public function getSeverity(): SecurityEventSeverity { - return SecurityEvent::SEVERITY_CRITICAL; + return SecurityEventSeverity::CRITICAL; } } diff --git a/core/lib/Security/Event/DeviceBlockedEvent.php b/core/lib/Security/Event/DeviceBlockedEvent.php index 724bf58..c840d86 100644 --- a/core/lib/Security/Event/DeviceBlockedEvent.php +++ b/core/lib/Security/Event/DeviceBlockedEvent.php @@ -59,8 +59,8 @@ final class DeviceBlockedEvent extends Event implements SecurityRequestEventInte return $this->reason; } - public function getSeverity(): int + public function getSeverity(): SecurityEventSeverity { - return SecurityEvent::SEVERITY_CRITICAL; + return SecurityEventSeverity::CRITICAL; } } diff --git a/core/lib/Security/Event/FirewallIpEvent.php b/core/lib/Security/Event/FirewallIpEvent.php index a155398..bc013a3 100644 --- a/core/lib/Security/Event/FirewallIpEvent.php +++ b/core/lib/Security/Event/FirewallIpEvent.php @@ -8,7 +8,7 @@ use KTXF\Event\Event; abstract class FirewallIpEvent extends Event implements SecurityRequestEventInterface { - protected const SEVERITY = SecurityEvent::SEVERITY_INFO; + protected const SecurityEventSeverity SEVERITY = SecurityEventSeverity::INFO; final public function __construct( private readonly string $ipAddress, @@ -61,7 +61,7 @@ abstract class FirewallIpEvent extends Event implements SecurityRequestEventInte return $this->reason; } - public function getSeverity(): int + public function getSeverity(): SecurityEventSeverity { return static::SEVERITY; } diff --git a/core/lib/Security/Event/FirewallRuleEvent.php b/core/lib/Security/Event/FirewallRuleEvent.php index 74e96c3..e5bd31b 100644 --- a/core/lib/Security/Event/FirewallRuleEvent.php +++ b/core/lib/Security/Event/FirewallRuleEvent.php @@ -151,8 +151,8 @@ abstract class FirewallRuleEvent extends Event implements SecurityEventInterface return $this->reason; } - public function getSeverity(): int + public function getSeverity(): SecurityEventSeverity { - return SecurityEvent::SEVERITY_INFO; + return SecurityEventSeverity::INFO; } } diff --git a/core/lib/Security/Event/FirewallSettingsUpdatedEvent.php b/core/lib/Security/Event/FirewallSettingsUpdatedEvent.php index 58d897c..f2f1795 100644 --- a/core/lib/Security/Event/FirewallSettingsUpdatedEvent.php +++ b/core/lib/Security/Event/FirewallSettingsUpdatedEvent.php @@ -69,8 +69,8 @@ final class FirewallSettingsUpdatedEvent extends Event implements SecurityEventI return $this->changeReason; } - public function getSeverity(): int + public function getSeverity(): SecurityEventSeverity { - return SecurityEvent::SEVERITY_INFO; + return SecurityEventSeverity::INFO; } } diff --git a/core/lib/Security/Event/IpBlockedEvent.php b/core/lib/Security/Event/IpBlockedEvent.php index a4558b0..34e9623 100644 --- a/core/lib/Security/Event/IpBlockedEvent.php +++ b/core/lib/Security/Event/IpBlockedEvent.php @@ -6,5 +6,5 @@ namespace KTXC\Security\Event; final class IpBlockedEvent extends FirewallIpEvent { - protected const SEVERITY = SecurityEvent::SEVERITY_CRITICAL; + protected const SecurityEventSeverity SEVERITY = SecurityEventSeverity::CRITICAL; } diff --git a/core/lib/Security/Event/RateLimitExceededEvent.php b/core/lib/Security/Event/RateLimitExceededEvent.php index e89a7ec..3679f18 100644 --- a/core/lib/Security/Event/RateLimitExceededEvent.php +++ b/core/lib/Security/Event/RateLimitExceededEvent.php @@ -97,8 +97,8 @@ final class RateLimitExceededEvent extends Event implements SecurityRequestEvent return $this->reason; } - public function getSeverity(): int + public function getSeverity(): SecurityEventSeverity { - return SecurityEvent::SEVERITY_ERROR; + return SecurityEventSeverity::ERROR; } } diff --git a/core/lib/Security/Event/SecurityEvent.php b/core/lib/Security/Event/SecurityEvent.php deleted file mode 100644 index 624835f..0000000 --- a/core/lib/Security/Event/SecurityEvent.php +++ /dev/null @@ -1,141 +0,0 @@ -severity = $severity ?? self::getSeverityForEvent($name); - } - - /** - * Create a security event with common parameters - */ - public static function create( - string $name, - ?string $ipAddress = null, - ?string $deviceFingerprint = null, - array $data = [], - ?string $tenantId = null, - ?string $identityId = null, - ?string $userAgent = null, - ?string $requestPath = null, - ?string $requestMethod = null, - ?string $userId = null, - ?string $reason = null, - ?int $severity = null, - ): self { - return new self( - $name, - $data, - $tenantId, - $identityId, - $ipAddress, - $deviceFingerprint, - $userAgent, - $requestPath, - $requestMethod, - $userId, - $reason, - $severity, - ); - } - - /** - * Get default severity for event types - */ - private static function getSeverityForEvent(string $eventName): int - { - return match ($eventName) { - self::ACCESS_GRANTED, - self::TOKEN_REFRESH => self::SEVERITY_INFO, - - self::AUTH_LOGOUT, - self::TOKEN_REVOKED => self::SEVERITY_WARNING, - - default => self::SEVERITY_INFO, - }; - } - - // Getters and setters - - public function getIpAddress(): ?string - { - return $this->ipAddress; - } - - public function getDeviceFingerprint(): ?string - { - return $this->deviceFingerprint; - } - - public function getUserAgent(): ?string - { - return $this->userAgent; - } - - public function getRequestPath(): ?string - { - return $this->requestPath; - } - - public function getRequestMethod(): ?string - { - return $this->requestMethod; - } - - public function getUserId(): ?string - { - return $this->userId; - } - - public function getReason(): ?string - { - return $this->reason; - } - - public function getSeverity(): int - { - return $this->severity; - } - -} diff --git a/core/lib/Security/Event/SecurityEventInterface.php b/core/lib/Security/Event/SecurityEventInterface.php index 62fbde7..32b7b23 100644 --- a/core/lib/Security/Event/SecurityEventInterface.php +++ b/core/lib/Security/Event/SecurityEventInterface.php @@ -22,5 +22,5 @@ interface SecurityEventInterface public function getReason(): ?string; - public function getSeverity(): int; + public function getSeverity(): SecurityEventSeverity; } diff --git a/core/lib/Security/Event/SecurityEventSeverity.php b/core/lib/Security/Event/SecurityEventSeverity.php new file mode 100644 index 0000000..1702cfc --- /dev/null +++ b/core/lib/Security/Event/SecurityEventSeverity.php @@ -0,0 +1,14 @@ +reason; } - public function getSeverity(): int + public function getSeverity(): SecurityEventSeverity { - return SecurityEvent::SEVERITY_ERROR; + return SecurityEventSeverity::ERROR; } } diff --git a/core/lib/Service/FirewallService.php b/core/lib/Service/FirewallService.php index a1bf4dc..2cfbb96 100644 --- a/core/lib/Service/FirewallService.php +++ b/core/lib/Service/FirewallService.php @@ -22,7 +22,6 @@ use KTXC\Security\Event\FirewallRuleRemovedEvent; use KTXC\Security\Event\FirewallSettingsUpdatedEvent; use KTXC\Security\Event\RateLimitExceededEvent; use KTXC\Security\Event\SuspiciousActivityEvent; -use KTXC\Security\Event\SecurityEvent; use KTXC\Security\Event\SecurityEventInterface; use KTXC\Security\Event\SecurityRequestEventInterface; use KTXF\Event\EventDispatcherInterface; @@ -311,8 +310,7 @@ class FirewallService private function mapEventToResult(SecurityEventInterface $event): string { return match ($event->getName()) { - AuthenticationSucceededEvent::class, - SecurityEvent::ACCESS_GRANTED => FirewallLogObject::RESULT_ALLOWED, + AuthenticationSucceededEvent::class => FirewallLogObject::RESULT_ALLOWED, FirewallRuleCreatedEvent::class, FirewallRuleExtendedEvent::class, FirewallRuleEnabledEvent::class, diff --git a/tests/php/Unit/Event/AccessDeniedEventTest.php b/tests/php/Unit/Event/AccessDeniedEventTest.php index d4111c3..7501794 100644 --- a/tests/php/Unit/Event/AccessDeniedEventTest.php +++ b/tests/php/Unit/Event/AccessDeniedEventTest.php @@ -6,7 +6,7 @@ namespace KTXT\Unit\Event; use KTXC\Models\Firewall\FirewallRuleObject; use KTXC\Security\Event\AccessDeniedEvent; -use KTXC\Security\Event\SecurityEvent; +use KTXC\Security\Event\SecurityEventSeverity; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; @@ -35,7 +35,7 @@ final class AccessDeniedEventTest extends TestCase self::assertSame('Blocked by policy', $event->getReason()); self::assertSame('tenant-a', $event->getTenantId()); self::assertSame('identity-a', $event->getIdentityId()); - self::assertSame(SecurityEvent::SEVERITY_WARNING, $event->getSeverity()); + self::assertSame(SecurityEventSeverity::WARNING, $event->getSeverity()); } #[Test] diff --git a/tests/php/Unit/Event/AuthenticationFailedEventTest.php b/tests/php/Unit/Event/AuthenticationFailedEventTest.php index 8ed687f..c2cc408 100644 --- a/tests/php/Unit/Event/AuthenticationFailedEventTest.php +++ b/tests/php/Unit/Event/AuthenticationFailedEventTest.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace KTXT\Unit\Event; use KTXC\Security\Event\AuthenticationFailedEvent; -use KTXC\Security\Event\SecurityEvent; +use KTXC\Security\Event\SecurityEventSeverity; use KTXC\Security\Event\SecurityRequestEventInterface; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestDox; @@ -29,7 +29,7 @@ final class AuthenticationFailedEventTest extends TestCase self::assertSame('Invalid credentials', $event->getReason()); self::assertSame('tenant-a', $event->getTenantId()); self::assertSame('identity-a', $event->getIdentityId()); - self::assertSame(SecurityEvent::SEVERITY_WARNING, $event->getSeverity()); + self::assertSame(SecurityEventSeverity::WARNING, $event->getSeverity()); self::assertNotInstanceOf(SecurityRequestEventInterface::class, $event); } } diff --git a/tests/php/Unit/Event/AuthenticationSucceededEventTest.php b/tests/php/Unit/Event/AuthenticationSucceededEventTest.php index 0f57f93..0e26bcc 100644 --- a/tests/php/Unit/Event/AuthenticationSucceededEventTest.php +++ b/tests/php/Unit/Event/AuthenticationSucceededEventTest.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace KTXT\Unit\Event; use KTXC\Security\Event\AuthenticationSucceededEvent; -use KTXC\Security\Event\SecurityEvent; +use KTXC\Security\Event\SecurityEventSeverity; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; @@ -29,7 +29,7 @@ final class AuthenticationSucceededEventTest extends TestCase self::assertSame('tenant-a', $event->getTenantId()); self::assertSame('device-a', $event->getDeviceFingerprint()); self::assertSame(['userId' => 'user-a'], $event->getData()); - self::assertSame(SecurityEvent::SEVERITY_INFO, $event->getSeverity()); + self::assertSame(SecurityEventSeverity::INFO, $event->getSeverity()); } #[Test] diff --git a/tests/php/Unit/Event/BruteForceDetectedEventTest.php b/tests/php/Unit/Event/BruteForceDetectedEventTest.php index 44eb024..589cee5 100644 --- a/tests/php/Unit/Event/BruteForceDetectedEventTest.php +++ b/tests/php/Unit/Event/BruteForceDetectedEventTest.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace KTXT\Unit\Event; use KTXC\Security\Event\BruteForceDetectedEvent; -use KTXC\Security\Event\SecurityEvent; +use KTXC\Security\Event\SecurityEventSeverity; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; @@ -33,7 +33,7 @@ final class BruteForceDetectedEventTest extends TestCase ['failureCount' => 5, 'windowSeconds' => 300], $event->getData(), ); - self::assertSame(SecurityEvent::SEVERITY_CRITICAL, $event->getSeverity()); + self::assertSame(SecurityEventSeverity::CRITICAL, $event->getSeverity()); } #[Test] diff --git a/tests/php/Unit/Event/FirewallPolicyEventTest.php b/tests/php/Unit/Event/FirewallPolicyEventTest.php index b8ab310..28fb8eb 100644 --- a/tests/php/Unit/Event/FirewallPolicyEventTest.php +++ b/tests/php/Unit/Event/FirewallPolicyEventTest.php @@ -8,7 +8,7 @@ use KTXC\Security\Event\DeviceBlockedEvent; use KTXC\Security\Event\FirewallSettingsUpdatedEvent; use KTXC\Security\Event\IpAllowedEvent; use KTXC\Security\Event\IpBlockedEvent; -use KTXC\Security\Event\SecurityEvent; +use KTXC\Security\Event\SecurityEventSeverity; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; @@ -26,13 +26,13 @@ final class FirewallPolicyEventTest extends TestCase self::assertSame(IpBlockedEvent::class, $blocked->getName()); self::assertSame('203.0.113.10', $blocked->getIpAddress()); self::assertSame('Repeated abuse', $blocked->getReason()); - self::assertSame(SecurityEvent::SEVERITY_CRITICAL, $blocked->getSeverity()); + self::assertSame(SecurityEventSeverity::CRITICAL, $blocked->getSeverity()); self::assertSame(IpAllowedEvent::class, $allowed->getName()); self::assertSame('203.0.113.11', $allowed->getIpAddress()); - self::assertSame(SecurityEvent::SEVERITY_INFO, $allowed->getSeverity()); + self::assertSame(SecurityEventSeverity::INFO, $allowed->getSeverity()); self::assertSame(DeviceBlockedEvent::class, $device->getName()); self::assertSame('device-a', $device->getDeviceFingerprint()); - self::assertSame(SecurityEvent::SEVERITY_CRITICAL, $device->getSeverity()); + self::assertSame(SecurityEventSeverity::CRITICAL, $device->getSeverity()); } #[Test] @@ -54,7 +54,7 @@ final class FirewallPolicyEventTest extends TestCase self::assertSame('tenant-a', $event->getTenantId()); self::assertSame('operator-a', $event->getIdentityId()); self::assertSame('manual', $event->getChangeOrigin()); - self::assertSame(SecurityEvent::SEVERITY_INFO, $event->getSeverity()); + self::assertSame(SecurityEventSeverity::INFO, $event->getSeverity()); } #[Test] diff --git a/tests/php/Unit/Event/FirewallRuleEventTest.php b/tests/php/Unit/Event/FirewallRuleEventTest.php index 62fcead..2910982 100644 --- a/tests/php/Unit/Event/FirewallRuleEventTest.php +++ b/tests/php/Unit/Event/FirewallRuleEventTest.php @@ -10,7 +10,7 @@ use KTXC\Security\Event\FirewallRuleDisabledEvent; use KTXC\Security\Event\FirewallRuleEnabledEvent; use KTXC\Security\Event\FirewallRuleExtendedEvent; use KTXC\Security\Event\FirewallRuleRemovedEvent; -use KTXC\Security\Event\SecurityEvent; +use KTXC\Security\Event\SecurityEventSeverity; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; @@ -54,7 +54,7 @@ final class FirewallRuleEventTest extends TestCase self::assertSame('operator-a', $event->getIdentityId()); self::assertSame(5, $event->get('failureCount')); self::assertSame('Continue monitoring', $event->get('changeReason')); - self::assertSame(SecurityEvent::SEVERITY_INFO, $event->getSeverity()); + self::assertSame(SecurityEventSeverity::INFO, $event->getSeverity()); } #[Test] diff --git a/tests/php/Unit/Event/RateLimitExceededEventTest.php b/tests/php/Unit/Event/RateLimitExceededEventTest.php index a82dfdd..dc43b1d 100644 --- a/tests/php/Unit/Event/RateLimitExceededEventTest.php +++ b/tests/php/Unit/Event/RateLimitExceededEventTest.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace KTXT\Unit\Event; use KTXC\Security\Event\RateLimitExceededEvent; -use KTXC\Security\Event\SecurityEvent; +use KTXC\Security\Event\SecurityEventSeverity; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; @@ -32,7 +32,7 @@ final class RateLimitExceededEventTest extends TestCase self::assertSame('/login', $event->getRequestPath()); self::assertSame('tenant-a', $event->getTenantId()); self::assertSame('101 requests in 60 seconds', $event->getReason()); - self::assertSame(SecurityEvent::SEVERITY_ERROR, $event->getSeverity()); + self::assertSame(SecurityEventSeverity::ERROR, $event->getSeverity()); } #[Test] diff --git a/tests/php/Unit/Event/SecurityEventSeverityTest.php b/tests/php/Unit/Event/SecurityEventSeverityTest.php new file mode 100644 index 0000000..fe00795 --- /dev/null +++ b/tests/php/Unit/Event/SecurityEventSeverityTest.php @@ -0,0 +1,24 @@ +value); + self::assertSame(1, SecurityEventSeverity::INFO->value); + self::assertSame(2, SecurityEventSeverity::WARNING->value); + self::assertSame(3, SecurityEventSeverity::ERROR->value); + self::assertSame(4, SecurityEventSeverity::CRITICAL->value); + } +} diff --git a/tests/php/Unit/Event/SecurityEventTest.php b/tests/php/Unit/Event/SecurityEventTest.php deleted file mode 100644 index 47b086c..0000000 --- a/tests/php/Unit/Event/SecurityEventTest.php +++ /dev/null @@ -1,60 +0,0 @@ -getSeverity(), - ); - self::assertSame( - SecurityEvent::SEVERITY_INFO, - (new SecurityEvent(SecurityEvent::ACCESS_GRANTED))->getSeverity(), - ); - } - - #[Test] - #[TestDox('Construction can override the event type default severity')] - public function allowsSeverityOverride(): void - { - $event = new SecurityEvent( - SecurityEvent::AUTH_LOGOUT, - 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)); - } - } -} diff --git a/tests/php/Unit/Event/SuspiciousActivityEventTest.php b/tests/php/Unit/Event/SuspiciousActivityEventTest.php index d9efc93..da1595d 100644 --- a/tests/php/Unit/Event/SuspiciousActivityEventTest.php +++ b/tests/php/Unit/Event/SuspiciousActivityEventTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace KTXT\Unit\Event; -use KTXC\Security\Event\SecurityEvent; +use KTXC\Security\Event\SecurityEventSeverity; use KTXC\Security\Event\SuspiciousActivityEvent; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestDox; @@ -43,7 +43,7 @@ final class SuspiciousActivityEventTest extends TestCase self::assertSame('POST', $event->getRequestMethod()); self::assertSame('user-a', $event->getUserId()); self::assertSame('Matched a blocked payload signature', $event->getReason()); - self::assertSame(SecurityEvent::SEVERITY_ERROR, $event->getSeverity()); + self::assertSame(SecurityEventSeverity::ERROR, $event->getSeverity()); } #[Test] diff --git a/tests/php/Unit/Module/CoreModuleTest.php b/tests/php/Unit/Module/CoreModuleTest.php index 62e84bb..e64255f 100644 --- a/tests/php/Unit/Module/CoreModuleTest.php +++ b/tests/php/Unit/Module/CoreModuleTest.php @@ -28,7 +28,6 @@ use KTXC\Security\Event\FirewallRuleRemovedEvent; use KTXC\Security\Event\FirewallSettingsUpdatedEvent; use KTXC\Security\Event\RateLimitExceededEvent; use KTXC\Security\Event\SuspiciousActivityEvent; -use KTXC\Security\Event\SecurityEvent; use KTXF\Event\DeliveryMode; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestDox;