feat(firewall): add operational status reads
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -9,11 +9,14 @@ use KTXC\Context\TenantContextInterface;
|
||||
use KTXC\Controllers\FirewallController;
|
||||
use KTXC\Service\FirewallRuleCache;
|
||||
use KTXC\Service\FirewallRuleManager;
|
||||
use KTXC\Service\FirewallStatusService;
|
||||
use KTXC\Service\FirewallLogService;
|
||||
use KTXC\Service\SystemFirewallLogService;
|
||||
use KTXC\Service\SystemFirewallRuleService;
|
||||
use KTXC\Service\SystemFirewallStatusService;
|
||||
use KTXC\Service\TenantFirewallLogService;
|
||||
use KTXC\Service\TenantFirewallRuleService;
|
||||
use KTXC\Service\TenantFirewallStatusService;
|
||||
use KTXC\Stores\FirewallStore;
|
||||
use KTXF\Event\EventDispatcherInterface;
|
||||
use KTXF\Routing\Attributes\AuthenticatedRoute;
|
||||
@@ -43,7 +46,9 @@ final class FirewallControllerTest extends TestCase
|
||||
new TenantFirewallRuleService($manager, $tenant, $identity),
|
||||
new SystemFirewallRuleService($manager, $identity),
|
||||
new TenantFirewallLogService(new FirewallLogService($this->store), $tenant, $identity),
|
||||
new SystemFirewallLogService(new FirewallLogService($this->store), $identity)
|
||||
new SystemFirewallLogService(new FirewallLogService($this->store), $identity),
|
||||
new TenantFirewallStatusService(new FirewallStatusService($this->store), $tenant, $identity),
|
||||
new SystemFirewallStatusService(new FirewallStatusService($this->store), $identity)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -72,6 +77,18 @@ final class FirewallControllerTest extends TestCase
|
||||
self::assertSame(400, $this->controller->systemRules(limit: '101')->getStatusCode());
|
||||
}
|
||||
|
||||
#[TestDox('Metric endpoints return scoped counts and stable validation errors')]
|
||||
public function testMetrics(): void
|
||||
{
|
||||
$this->store->method('countBlockedRequests')->willReturn(4);
|
||||
|
||||
$response = $this->controller->tenantMetrics();
|
||||
$data = json_decode($response->getContent(), true, flags: JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertSame(4, $data['blockedRequests']);
|
||||
self::assertSame(400, $this->controller->systemMetrics(since: 'not-a-date')->getStatusCode());
|
||||
}
|
||||
|
||||
#[TestDox('Every rule endpoint declares its scope-specific read permission')]
|
||||
public function testRoutePermissions(): void
|
||||
{
|
||||
@@ -83,6 +100,10 @@ final class FirewallControllerTest extends TestCase
|
||||
'systemRule' => SystemFirewallRuleService::PERMISSION_READ,
|
||||
'tenantLogs' => TenantFirewallLogService::PERMISSION_READ,
|
||||
'systemLogs' => SystemFirewallLogService::PERMISSION_READ,
|
||||
'tenantMetrics' => TenantFirewallLogService::PERMISSION_READ,
|
||||
'tenantConfiguration' => TenantFirewallStatusService::PERMISSION_SETTINGS_READ,
|
||||
'systemMetrics' => SystemFirewallLogService::PERMISSION_READ,
|
||||
'maintenanceStatus' => SystemFirewallStatusService::PERMISSION_MAINTENANCE_READ,
|
||||
];
|
||||
|
||||
foreach ($expected as $method => $permission) {
|
||||
|
||||
Reference in New Issue
Block a user