## 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
82 lines
2.9 KiB
PHP
82 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\BackupScheduleResource\Pages\EditBackupSchedule;
|
|
use App\Filament\Resources\BackupScheduleResource\RelationManagers\BackupScheduleOperationRunsRelationManager;
|
|
use App\Models\BackupSchedule;
|
|
use App\Models\OperationRun;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
function makeBackupScheduleForTenant(\App\Models\Tenant $tenant, string $name): BackupSchedule
|
|
{
|
|
return BackupSchedule::query()->create([
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'name' => $name,
|
|
'is_enabled' => true,
|
|
'timezone' => 'UTC',
|
|
'frequency' => 'daily',
|
|
'time_of_day' => '01:00:00',
|
|
'days_of_week' => null,
|
|
'policy_types' => ['deviceConfiguration'],
|
|
'include_foundations' => true,
|
|
'retention_keep_last' => 30,
|
|
]);
|
|
}
|
|
|
|
it('shows only operation runs belonging to the owner backup schedule', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$scheduleA = makeBackupScheduleForTenant($tenant, 'Schedule A');
|
|
$scheduleB = makeBackupScheduleForTenant($tenant, 'Schedule B');
|
|
|
|
$runA = OperationRun::factory()->forTenant($tenant)->create([
|
|
'type' => 'backup_schedule_run',
|
|
'context' => ['backup_schedule_id' => (int) $scheduleA->getKey()],
|
|
]);
|
|
$runB = OperationRun::factory()->forTenant($tenant)->create([
|
|
'type' => 'backup_schedule_run',
|
|
'context' => ['backup_schedule_id' => (int) $scheduleB->getKey()],
|
|
]);
|
|
|
|
Livewire::test(BackupScheduleOperationRunsRelationManager::class, [
|
|
'ownerRecord' => $scheduleA,
|
|
'pageClass' => EditBackupSchedule::class,
|
|
])
|
|
->assertCanSeeTableRecords([$runA])
|
|
->assertCanNotSeeTableRecords([$runB]);
|
|
});
|
|
|
|
it('returns 404 when a forged same-tenant run key is mounted on the wrong schedule relation manager', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$scheduleA = makeBackupScheduleForTenant($tenant, 'Schedule A');
|
|
$scheduleB = makeBackupScheduleForTenant($tenant, 'Schedule B');
|
|
|
|
$foreignRun = OperationRun::factory()->forTenant($tenant)->create([
|
|
'type' => 'backup_schedule_run',
|
|
'context' => ['backup_schedule_id' => (int) $scheduleB->getKey()],
|
|
]);
|
|
|
|
$component = Livewire::test(BackupScheduleOperationRunsRelationManager::class, [
|
|
'ownerRecord' => $scheduleA,
|
|
'pageClass' => EditBackupSchedule::class,
|
|
]);
|
|
|
|
expect(fn () => $component->instance()->mountTableAction('view', (string) $foreignRun->getKey()))
|
|
->toThrow(NotFoundHttpException::class);
|
|
});
|