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::Manager->value, ]); ManagedEnvironmentMembership::query()->create([ 'managed_environment_id' => (int) $allowedTenant->getKey(), 'user_id' => (int) $user->getKey(), 'role' => WorkspaceRole::Readonly->value, 'source' => 'manual', ]); app(CapabilityResolver::class)->clearCache(); app(ManagedEnvironmentAccessScopeResolver::class)->clearCache(); $snapshot = EvidenceSnapshot::query()->create([ 'workspace_id' => (int) $workspace->getKey(), 'managed_environment_id' => (int) $deniedTenant->getKey(), 'status' => EvidenceSnapshotStatus::Active->value, 'completeness_state' => EvidenceCompletenessState::Complete->value, 'summary' => ['finding_count' => 1], 'generated_at' => now(), ]); $review = EnvironmentReview::factory()->ready()->create([ 'workspace_id' => (int) $workspace->getKey(), 'managed_environment_id' => (int) $deniedTenant->getKey(), 'evidence_snapshot_id' => (int) $snapshot->getKey(), ]); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]) ->get(EnvironmentReviewResource::getUrl('view', ['record' => $review], panel: 'admin', tenant: $allowedTenant)) ->assertNotFound(); }); it('denies same-workspace wrong-environment evidence direct access 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::Manager->value, ]); ManagedEnvironmentMembership::query()->create([ 'managed_environment_id' => (int) $allowedTenant->getKey(), 'user_id' => (int) $user->getKey(), 'role' => WorkspaceRole::Readonly->value, 'source' => 'manual', ]); app(CapabilityResolver::class)->clearCache(); app(ManagedEnvironmentAccessScopeResolver::class)->clearCache(); $snapshot = EvidenceSnapshot::query()->create([ 'workspace_id' => (int) $workspace->getKey(), 'managed_environment_id' => (int) $deniedTenant->getKey(), 'status' => EvidenceSnapshotStatus::Active->value, 'completeness_state' => EvidenceCompletenessState::Complete->value, 'summary' => ['finding_count' => 1], 'generated_at' => now(), ]); $allowedTenant->makeCurrent(); Filament::setTenant($allowedTenant, true); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]) ->get(EvidenceSnapshotResource::getUrl('view', ['record' => $snapshot], panel: 'admin', tenant: $allowedTenant)) ->assertNotFound(); });