## Summary - introduce a shared tenant-owned query and record-resolution canon for first-slice Filament resources - harden direct views, row actions, bulk actions, relation managers, and workspace-admin canonical viewers against wrong-tenant access - add registry-backed rollout metadata, search posture handling, architectural guards, and focused Pest coverage for scope parity and 404/403 semantics ## Included - Spec 150 package under `specs/150-tenant-owned-query-canon-and-wrong-tenant-guards/` - shared support classes: `TenantOwnedModelFamilies`, `TenantOwnedQueryScope`, `TenantOwnedRecordResolver` - shared Filament concern: `InteractsWithTenantOwnedRecords` - resource/page/policy hardening across findings, policies, policy versions, backup schedules, backup sets, restore runs, inventory items, and Entra groups - additional regression coverage for canonical tenant state, wrong-tenant record resolution, relation-manager congruence, and action-surface guardrails ## Validation - `vendor/bin/sail artisan test --compact` passed - full suite result: `2733 passed, 8 skipped` - formatting applied with `vendor/bin/sail bin pint --dirty --format agent` ## Notes - Livewire v4.0+ compliant via existing Filament v5 stack - provider registration remains in `bootstrap/providers.php` - globally searchable first-slice posture: Entra groups scoped; policies and policy versions explicitly disabled - destructive actions continue to use confirmation and policy authorization - no new Filament assets added; existing deployment flow remains unchanged, including `php artisan filament:assets` when registered assets are used Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #180
106 lines
3.9 KiB
PHP
106 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\EntraGroupResource;
|
|
use App\Filament\Resources\OperationRunResource;
|
|
use App\Filament\Resources\PolicyResource;
|
|
use App\Filament\Resources\PolicyVersionResource;
|
|
use App\Filament\Resources\TenantResource;
|
|
use App\Models\EntraGroup;
|
|
use App\Models\Policy;
|
|
use App\Models\PolicyVersion;
|
|
use App\Models\Tenant;
|
|
use App\Support\WorkspaceIsolation\TenantOwnedModelFamilies;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
function adminGlobalSearchTitles($results): array
|
|
{
|
|
return collect($results)->map(fn ($result): string => (string) $result->title)->all();
|
|
}
|
|
|
|
it('does not collapse administratively discoverable tenant results because remembered tenant context is selector-ineligible', function (): void {
|
|
$activeTenant = Tenant::factory()->active()->create(['name' => 'Search Safety Active']);
|
|
[$user, $activeTenant] = createUserWithTenant(tenant: $activeTenant, role: 'owner');
|
|
|
|
$onboardingTenant = Tenant::factory()->onboarding()->create([
|
|
'workspace_id' => (int) $activeTenant->workspace_id,
|
|
'name' => 'Search Safety Onboarding',
|
|
]);
|
|
|
|
createUserWithTenant(tenant: $onboardingTenant, user: $user, role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
|
|
|
|
$this->actingAs($user);
|
|
|
|
Filament::setCurrentPanel('admin');
|
|
Filament::setTenant(null, true);
|
|
Filament::bootCurrentPanel();
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, (int) $activeTenant->workspace_id);
|
|
session()->put(WorkspaceContext::LAST_TENANT_IDS_SESSION_KEY, [
|
|
(string) $activeTenant->workspace_id => (int) $onboardingTenant->getKey(),
|
|
]);
|
|
|
|
expect(adminGlobalSearchTitles(TenantResource::getGlobalSearchResults('Search Safety')))
|
|
->toEqualCanonicalizing([
|
|
'Search Safety Active',
|
|
'Search Safety Onboarding',
|
|
]);
|
|
});
|
|
|
|
it('keeps operation runs out of admin global search regardless of remembered context state', function (): void {
|
|
expect(OperationRunResource::canGloballySearch())->toBeFalse();
|
|
});
|
|
|
|
it('keeps representative first-slice admin global-search behavior aligned to the family registry postures', function (): void {
|
|
$tenantA = Tenant::factory()->create();
|
|
[$user, $tenantA] = createUserWithTenant(tenant: $tenantA, role: 'owner');
|
|
|
|
$tenantB = Tenant::factory()->create([
|
|
'workspace_id' => (int) $tenantA->workspace_id,
|
|
]);
|
|
|
|
createUserWithTenant(tenant: $tenantB, user: $user, role: 'owner');
|
|
|
|
EntraGroup::factory()->for($tenantA)->create([
|
|
'display_name' => 'Registry Search Group',
|
|
]);
|
|
|
|
EntraGroup::factory()->for($tenantB)->create([
|
|
'display_name' => 'Registry Search Group',
|
|
]);
|
|
|
|
$policy = Policy::factory()->for($tenantA)->create([
|
|
'display_name' => 'Registry Search Policy',
|
|
]);
|
|
|
|
PolicyVersion::factory()->for($tenantA)->for($policy)->create([
|
|
'version_number' => 77,
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
|
|
Filament::setCurrentPanel('admin');
|
|
Filament::setTenant(null, true);
|
|
Filament::bootCurrentPanel();
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, (int) $tenantA->workspace_id);
|
|
session()->put(WorkspaceContext::LAST_TENANT_IDS_SESSION_KEY, [
|
|
(string) $tenantA->workspace_id => (int) $tenantA->getKey(),
|
|
]);
|
|
|
|
expect(TenantOwnedModelFamilies::searchPostureForModel(EntraGroup::class))->toBe('scoped');
|
|
expect(TenantOwnedModelFamilies::searchPostureForModel(Policy::class))->toBe('disabled');
|
|
expect(TenantOwnedModelFamilies::searchPostureForModel(PolicyVersion::class))->toBe('disabled');
|
|
|
|
expect(adminGlobalSearchTitles(EntraGroupResource::getGlobalSearchResults('Registry Search')))
|
|
->toBe(['Registry Search Group']);
|
|
|
|
expect(PolicyResource::getGlobalSearchResults('Registry Search Policy'))->toHaveCount(0);
|
|
expect(PolicyVersionResource::getGlobalSearchResults('77'))->toHaveCount(0);
|
|
});
|