refactor(security): type firewall policy events
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -16,6 +16,9 @@ use KTXC\Security\Event\FirewallRuleDisabledEvent;
|
||||
use KTXC\Security\Event\FirewallRuleEnabledEvent;
|
||||
use KTXC\Security\Event\FirewallRuleExtendedEvent;
|
||||
use KTXC\Security\Event\FirewallRuleRemovedEvent;
|
||||
use KTXC\Security\Event\DeviceBlockedEvent;
|
||||
use KTXC\Security\Event\IpAllowedEvent;
|
||||
use KTXC\Security\Event\IpBlockedEvent;
|
||||
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
|
||||
use PHPUnit\Framework\Attributes\TestDox;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
@@ -301,6 +304,42 @@ class FirewallRuleManagerTest extends TestCase
|
||||
self::assertSame(FirewallRuleManager::ORIGIN_MANUAL, $audit->get('origin'));
|
||||
self::assertSame('admin-a', $audit->getIdentityId());
|
||||
self::assertNotNull($audit->get('expiresAt'));
|
||||
self::assertInstanceOf(IpBlockedEvent::class, $events[IpBlockedEvent::class]);
|
||||
self::assertSame('203.0.113.10', $events[IpBlockedEvent::class]->getIpAddress());
|
||||
}
|
||||
|
||||
#[TestDox('IP allowance and device blocking publish dedicated policy events')]
|
||||
public function testSubjectPolicyEvents(): void
|
||||
{
|
||||
$this->store->method('findExactIpRule')->willReturn(null);
|
||||
$this->store->method('depositRule')->willReturnCallback(
|
||||
static function (FirewallRuleObject $rule): FirewallRuleObject {
|
||||
static $sequence = 0;
|
||||
return $rule->setId('policy-rule-' . ++$sequence);
|
||||
}
|
||||
);
|
||||
$events = [];
|
||||
$this->events->expects($this->exactly(4))
|
||||
->method('dispatch')
|
||||
->willReturnCallback(static function (\KTXF\Event\Event $event) use (&$events): void {
|
||||
$events[] = $event;
|
||||
});
|
||||
|
||||
$this->manager->allowIp(
|
||||
FirewallRuleScope::tenant('tenant-a'),
|
||||
'203.0.113.11',
|
||||
'Trusted service',
|
||||
'admin-a',
|
||||
);
|
||||
$this->manager->blockDevice(
|
||||
FirewallRuleScope::tenant('tenant-a'),
|
||||
'device-a',
|
||||
'Compromised device',
|
||||
'admin-a',
|
||||
);
|
||||
|
||||
self::assertCount(1, array_filter($events, static fn($event): bool => $event instanceof IpAllowedEvent));
|
||||
self::assertCount(1, array_filter($events, static fn($event): bool => $event instanceof DeviceBlockedEvent));
|
||||
}
|
||||
|
||||
#[TestDox('Manual lifecycle changes persist state, reasons, actors, and extension history')]
|
||||
|
||||
Reference in New Issue
Block a user