feat(firewall): add scoped rule administration reads
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -91,6 +91,59 @@ class FirewallRuleManagerTest extends TestCase
|
||||
self::assertFalse($this->manager->remove(FirewallRuleScope::tenant('tenant-b'), 'tenant-rule'));
|
||||
}
|
||||
|
||||
#[TestDox('Rule queries retain scope, filters, and bounded pagination')]
|
||||
public function testRuleQuery(): void
|
||||
{
|
||||
$result = ['items' => [], 'total' => 0, 'limit' => 25, 'offset' => 50];
|
||||
$this->store->expects(self::once())
|
||||
->method('queryRules')
|
||||
->with(
|
||||
FirewallRuleObject::SCOPE_TENANT,
|
||||
'tenant-a',
|
||||
'disabled',
|
||||
FirewallRuleObject::TYPE_IP,
|
||||
FirewallRuleObject::ACTION_BLOCK,
|
||||
25,
|
||||
50
|
||||
)
|
||||
->willReturn($result);
|
||||
|
||||
self::assertSame($result, $this->manager->query(
|
||||
FirewallRuleScope::tenant('tenant-a'),
|
||||
'disabled',
|
||||
FirewallRuleObject::TYPE_IP,
|
||||
FirewallRuleObject::ACTION_BLOCK,
|
||||
25,
|
||||
50
|
||||
));
|
||||
}
|
||||
|
||||
#[TestDox('Rule queries reject invalid filters and excessive pages')]
|
||||
public function testRuleQueryValidation(): void
|
||||
{
|
||||
$this->store->expects(self::never())->method('queryRules');
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$this->manager->query(FirewallRuleScope::system(), 'active', null, null, 101);
|
||||
}
|
||||
|
||||
#[TestDox('Effective policy keeps system and tenant rule sets distinct')]
|
||||
public function testEffectivePolicy(): void
|
||||
{
|
||||
$system = (new FirewallRuleObject())->setScope(FirewallRuleObject::SCOPE_SYSTEM);
|
||||
$tenant = (new FirewallRuleObject())
|
||||
->setScope(FirewallRuleObject::SCOPE_TENANT)
|
||||
->setTenantId('tenant-a');
|
||||
$this->store->method('listSystemRules')->willReturn([$system]);
|
||||
$this->store->method('listRules')->with('tenant-a')->willReturn([$tenant]);
|
||||
|
||||
$policy = $this->manager->effectivePolicy('tenant-a');
|
||||
|
||||
self::assertSame([$system], $policy['system']);
|
||||
self::assertSame([$tenant], $policy['tenant']);
|
||||
self::assertSame('system_block', $policy['precedence'][0]);
|
||||
}
|
||||
|
||||
#[TestDox('Rule mutations invalidate the shared enforcement cache')]
|
||||
public function testCacheInvalidation(): void
|
||||
{
|
||||
|
||||
@@ -57,6 +57,39 @@ class FirewallRuleServicesTest extends TestCase
|
||||
$this->systemService()->blockIp('203.0.113.10');
|
||||
}
|
||||
|
||||
#[TestDox('Read operations require their scope-specific permission')]
|
||||
public function testReadPermissions(): void
|
||||
{
|
||||
$this->identity->method('hasPermission')->willReturn(false);
|
||||
$this->store->expects(self::never())->method('queryRules');
|
||||
|
||||
try {
|
||||
$this->tenantService()->queryRules();
|
||||
self::fail('Tenant read should have been rejected.');
|
||||
} catch (\RuntimeException $error) {
|
||||
self::assertStringContainsString(TenantFirewallRuleService::PERMISSION_READ, $error->getMessage());
|
||||
}
|
||||
|
||||
$this->expectExceptionMessage(SystemFirewallRuleService::PERMISSION_READ);
|
||||
$this->systemService()->queryRules();
|
||||
}
|
||||
|
||||
#[TestDox('Tenant reads derive ownership and effective policy from context')]
|
||||
public function testTenantReads(): void
|
||||
{
|
||||
$this->allow(TenantFirewallRuleService::PERMISSION_READ);
|
||||
$this->tenant->method('requireIdentifier')->willReturn('tenant-a');
|
||||
$this->store->expects(self::once())
|
||||
->method('queryRules')
|
||||
->with(FirewallRuleObject::SCOPE_TENANT, 'tenant-a', 'active', null, null, 50, 0)
|
||||
->willReturn(['items' => [], 'total' => 0, 'limit' => 50, 'offset' => 0]);
|
||||
$this->store->method('listSystemRules')->willReturn([]);
|
||||
$this->store->method('listRules')->with('tenant-a')->willReturn([]);
|
||||
|
||||
self::assertSame(0, $this->tenantService()->queryRules()['total']);
|
||||
self::assertSame([], $this->tenantService()->effectivePolicy()['system']);
|
||||
}
|
||||
|
||||
#[TestDox('Tenant management derives scope from tenant context')]
|
||||
public function testTenantScope(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user