feat(firewall): add safeguarded rule creation
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -122,6 +122,23 @@ class FirewallRuleServicesTest extends TestCase
|
||||
$this->systemService()->blockIp('203.0.113.10');
|
||||
}
|
||||
|
||||
#[TestDox('Generic creation remains behind tenant and system management permissions')]
|
||||
public function testGenericCreationPermissions(): void
|
||||
{
|
||||
$this->identity->method('hasPermission')->willReturn(false);
|
||||
$this->store->expects(self::never())->method('depositRule');
|
||||
|
||||
try {
|
||||
$this->tenantService()->createRule('ip', 'block', '203.0.113.10', 'Abuse');
|
||||
self::fail('Tenant creation should have been rejected.');
|
||||
} catch (\RuntimeException $error) {
|
||||
self::assertStringContainsString(TenantFirewallRuleService::PERMISSION_MANAGE, $error->getMessage());
|
||||
}
|
||||
|
||||
$this->expectExceptionMessage(SystemFirewallRuleService::PERMISSION_MANAGE);
|
||||
$this->systemService()->createRule('ip', 'block', '203.0.113.10', 'Abuse');
|
||||
}
|
||||
|
||||
private function allow(string $permission): void
|
||||
{
|
||||
$this->identity->method('hasPermission')->with($permission)->willReturn(true);
|
||||
|
||||
Reference in New Issue
Block a user