fix(firewall): register missing security audit events
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -256,6 +256,59 @@ class FirewallServiceTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
#[TestDox('Rate-limit events retain their request and threshold audit data')]
|
||||
public function testRateLimitAudit(): void
|
||||
{
|
||||
$this->store->expects($this->once())
|
||||
->method('createLog')
|
||||
->with(self::callback(static function (FirewallLogObject $log): bool {
|
||||
$metadata = $log->getMetadata();
|
||||
return $log->getEventType() === FirewallLogObject::EVENT_RATE_LIMIT
|
||||
&& $log->getResult() === FirewallLogObject::RESULT_BLOCKED
|
||||
&& $log->getIpAddress() === '203.0.113.10'
|
||||
&& $log->getRequestPath() === '/login'
|
||||
&& $metadata['requestCount'] === 101
|
||||
&& $metadata['windowSeconds'] === 60;
|
||||
}))
|
||||
->willReturnArgument(0);
|
||||
$event = \KTXF\Event\SecurityEvent::rateLimitExceeded(
|
||||
'203.0.113.10',
|
||||
101,
|
||||
60,
|
||||
'/login'
|
||||
);
|
||||
$event->setTenantId('tenant-a');
|
||||
|
||||
$this->service->logSecurityEvent($event);
|
||||
}
|
||||
|
||||
#[TestDox('Suspicious-activity events retain request and detection metadata')]
|
||||
public function testSuspiciousActivityAudit(): void
|
||||
{
|
||||
$this->store->expects($this->once())
|
||||
->method('createLog')
|
||||
->with(self::callback(static function (FirewallLogObject $log): bool {
|
||||
return $log->getEventType() === FirewallLogObject::EVENT_SUSPICIOUS
|
||||
&& $log->getResult() === FirewallLogObject::RESULT_BLOCKED
|
||||
&& $log->getIpAddress() === '203.0.113.20'
|
||||
&& $log->getRequestPath() === '/admin'
|
||||
&& $log->getRequestMethod() === 'POST'
|
||||
&& $log->getMetadata()['detector'] === 'payload-signature';
|
||||
}))
|
||||
->willReturnArgument(0);
|
||||
$event = \KTXF\Event\SecurityEvent::create(
|
||||
\KTXF\Event\SecurityEvent::SUSPICIOUS_ACTIVITY,
|
||||
'203.0.113.20',
|
||||
null,
|
||||
['detector' => 'payload-signature']
|
||||
);
|
||||
$event->setTenantId('tenant-a')
|
||||
->setRequestPath('/admin')
|
||||
->setRequestMethod('POST');
|
||||
|
||||
$this->service->logSecurityEvent($event);
|
||||
}
|
||||
|
||||
#[TestDox('Typed tenant firewall settings drive brute-force thresholds')]
|
||||
public function testFirewallConfiguration(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user