## Summary - tighten workspace RBAC and panel access boundaries - remove non-owner workspace membership management capability from workspace role mapping - add focused boundary coverage for admin panel, managed environments, providers, review packs, operation runs, finding exceptions, and workspace role capabilities - include spec artifacts for feature 309 ## Testing - cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Auth/WorkspaceFirstManagedEnvironmentAccessTest.php tests/Feature/Rbac/RoleMatrix/ManagerAccessTest.php tests/Feature/Rbac/WorkspaceMembershipsRelationManagerUiEnforcementTest.php tests/Feature/Rbac/AdminPanelAccessBoundaryTest.php tests/Feature/Rbac/FindingExceptionLifecycleAccessBoundaryTest.php tests/Feature/Rbac/ManagedEnvironmentAccessBoundaryTest.php tests/Feature/Rbac/OperationRunAccessBoundaryTest.php tests/Feature/Rbac/ProviderConnectionAccessBoundaryTest.php tests/Feature/Rbac/ReviewPackAccessBoundaryTest.php tests/Feature/Rbac/SystemPanelAccessBoundaryTest.php tests/Feature/Rbac/WorkspaceRoleCapabilityBoundaryTest.php tests/Unit/Auth/CapabilityResolverTest.php tests/Unit/Auth/WorkspaceRoleCapabilityMapTest.php - cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #364
91 lines
3.1 KiB
PHP
91 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Models\ManagedEnvironmentMembership;
|
|
use App\Models\OperationRun;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Models\WorkspaceMembership;
|
|
use App\Services\Auth\ManagedEnvironmentAccessScopeResolver;
|
|
use App\Support\Auth\WorkspaceRole;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
it('denies cross-workspace operation runs as not found', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => WorkspaceRole::Readonly->value,
|
|
]);
|
|
|
|
$run = OperationRun::factory()->tenantlessForWorkspace($otherWorkspace)->create([
|
|
'type' => 'environment.review.compose',
|
|
]);
|
|
|
|
$response = Gate::forUser($user)->inspect('view', $run);
|
|
|
|
expect($response->denied())->toBeTrue()
|
|
->and($response->status())->toBe(404);
|
|
});
|
|
|
|
it('denies same-workspace wrong-environment operation runs as not found', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
$allowedTenant = ManagedEnvironment::factory()->active()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
]);
|
|
$deniedTenant = ManagedEnvironment::factory()->active()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
]);
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => WorkspaceRole::Operator->value,
|
|
]);
|
|
ManagedEnvironmentMembership::query()->create([
|
|
'managed_environment_id' => (int) $allowedTenant->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => WorkspaceRole::Operator->value,
|
|
'source' => 'manual',
|
|
]);
|
|
app(ManagedEnvironmentAccessScopeResolver::class)->clearCache();
|
|
|
|
$run = OperationRun::factory()->forTenant($deniedTenant)->create([
|
|
'type' => 'provider.connection.check',
|
|
]);
|
|
|
|
$response = Gate::forUser($user)->inspect('view', $run);
|
|
|
|
expect($response->denied())->toBeTrue()
|
|
->and($response->status())->toBe(404);
|
|
});
|
|
|
|
it('keeps in-scope operation capability denials distinct from scope boundaries', function (): void {
|
|
$workspace = Workspace::factory()->create();
|
|
$tenant = ManagedEnvironment::factory()->active()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
]);
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => WorkspaceRole::Readonly->value,
|
|
]);
|
|
|
|
$run = OperationRun::factory()->forTenant($tenant)->create([
|
|
'type' => 'inventory.sync',
|
|
]);
|
|
|
|
$response = Gate::forUser($user)->inspect('view', $run);
|
|
|
|
expect($response->denied())->toBeTrue()
|
|
->and($response->status())->not->toBe(404);
|
|
});
|