feat(firewall): audit rule lifecycle changes
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -309,6 +309,33 @@ class FirewallServiceTest extends TestCase
|
||||
$this->service->logSecurityEvent($event);
|
||||
}
|
||||
|
||||
#[TestDox('Rule lifecycle events map to recorded audit entries')]
|
||||
public function testRuleLifecycleAudit(): void
|
||||
{
|
||||
$this->currentTenant = null;
|
||||
$this->store->expects($this->once())
|
||||
->method('createLog')
|
||||
->with(self::callback(static function (FirewallLogObject $log): bool {
|
||||
return $log->getEventType() === FirewallLogObject::EVENT_RULE_DISABLED
|
||||
&& $log->getResult() === FirewallLogObject::RESULT_RECORDED
|
||||
&& $log->getRuleId() === 'rule-123'
|
||||
&& $log->getRuleScope() === FirewallRuleObject::SCOPE_SYSTEM
|
||||
&& $log->getIdentityId() === 'operator';
|
||||
}))
|
||||
->willReturnArgument(0);
|
||||
$event = new \KTXF\Event\SecurityEvent(
|
||||
\KTXF\Event\SecurityEvent::FIREWALL_RULE_DISABLED,
|
||||
[
|
||||
'ruleId' => 'rule-123',
|
||||
'ruleScope' => FirewallRuleObject::SCOPE_SYSTEM,
|
||||
'origin' => FirewallRuleManager::ORIGIN_MANUAL,
|
||||
]
|
||||
);
|
||||
$event->setIdentityId('operator');
|
||||
|
||||
$this->service->logSecurityEvent($event);
|
||||
}
|
||||
|
||||
#[TestDox('Typed tenant firewall settings drive brute-force thresholds')]
|
||||
public function testFirewallConfiguration(): void
|
||||
{
|
||||
@@ -380,17 +407,25 @@ class FirewallServiceTest extends TestCase
|
||||
->willReturnArgument(0);
|
||||
|
||||
$publishedTenants = [];
|
||||
$this->events->expects($this->exactly(2))
|
||||
$lifecycleOrigin = null;
|
||||
$this->events->expects($this->exactly(3))
|
||||
->method('dispatch')
|
||||
->willReturnCallback(static function (\KTXF\Event\Event $event) use (&$publishedTenants): void {
|
||||
->willReturnCallback(static function (\KTXF\Event\Event $event) use (
|
||||
&$publishedTenants,
|
||||
&$lifecycleOrigin
|
||||
): void {
|
||||
$publishedTenants[] = $event->getTenantId();
|
||||
if ($event->getName() === \KTXF\Event\SecurityEvent::FIREWALL_RULE_CREATED) {
|
||||
$lifecycleOrigin = $event->get('origin');
|
||||
}
|
||||
});
|
||||
|
||||
$event = \KTXF\Event\SecurityEvent::authFailure('203.0.113.10');
|
||||
$event->setTenantId('tenant-event');
|
||||
$this->service->handleAuthFailure($event);
|
||||
|
||||
self::assertSame(['tenant-event', 'tenant-event'], $publishedTenants);
|
||||
self::assertSame(['tenant-event', 'tenant-event', 'tenant-event'], $publishedTenants);
|
||||
self::assertSame(FirewallRuleManager::ORIGIN_AUTOMATIC, $lifecycleOrigin);
|
||||
}
|
||||
|
||||
#[TestDox('Authentication events without a tenant use the current tenant')]
|
||||
|
||||
Reference in New Issue
Block a user