- ReviewPackService: generate, fingerprint dedupe, signed download URL - GenerateReviewPackJob: 12-step pipeline, ZIP assembly, failure handling - ReviewPackDownloadController: signed URL streaming with SHA-256 header - ReviewPackResource: list/view pages, generate/expire/download actions - TenantReviewPackCard: dashboard widget with 5 display states - ReviewPackPolicy: RBAC via REVIEW_PACK_VIEW/MANAGE capabilities - PruneReviewPacksCommand: retention automation + hard-delete option - ReviewPackStatusNotification: database channel, ready/failed payloads - Schedule: daily prune + entra admin roles, posture:dispatch deferred - AlertRuleResource: hide sla_due from dropdown (backward compat kept) - 59 passing tests across 7 test files (1 skipped: posture deferred) - All 36 tasks completed per tasks.md
164 lines
5.4 KiB
PHP
164 lines
5.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\AlertRuleResource;
|
|
use App\Models\AlertRule;
|
|
use App\Models\ReviewPack;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
Storage::fake('exports');
|
|
});
|
|
|
|
it('expires ready packs past retention and deletes their files', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$filePath = 'review-packs/test-expired.zip';
|
|
Storage::disk('exports')->put($filePath, 'fake content');
|
|
|
|
$pack = ReviewPack::factory()->ready()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'file_path' => $filePath,
|
|
'expires_at' => now()->subDay(),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune')
|
|
->assertSuccessful();
|
|
|
|
$pack->refresh();
|
|
expect($pack->status)->toBe(ReviewPack::STATUS_EXPIRED)
|
|
->and(Storage::disk('exports')->exists($filePath))->toBeFalse();
|
|
});
|
|
|
|
it('does not expire ready packs with future retention', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$filePath = 'review-packs/test-future.zip';
|
|
Storage::disk('exports')->put($filePath, 'fake content');
|
|
|
|
$pack = ReviewPack::factory()->ready()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'file_path' => $filePath,
|
|
'expires_at' => now()->addDays(30),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune')
|
|
->assertSuccessful();
|
|
|
|
$pack->refresh();
|
|
expect($pack->status)->toBe(ReviewPack::STATUS_READY)
|
|
->and(Storage::disk('exports')->exists($filePath))->toBeTrue();
|
|
});
|
|
|
|
it('hard-deletes expired packs past grace period', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$graceDays = config('tenantpilot.review_pack.hard_delete_grace_days', 30);
|
|
|
|
$pack = ReviewPack::factory()->expired()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'updated_at' => now()->subDays($graceDays + 5),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune --hard-delete')
|
|
->assertSuccessful();
|
|
|
|
expect(ReviewPack::query()->whereKey($pack->getKey())->exists())->toBeFalse();
|
|
});
|
|
|
|
it('keeps expired packs within grace period when hard-deleting', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$pack = ReviewPack::factory()->expired()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'updated_at' => now()->subDays(5),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune --hard-delete')
|
|
->assertSuccessful();
|
|
|
|
expect(ReviewPack::query()->whereKey($pack->getKey())->exists())->toBeTrue();
|
|
});
|
|
|
|
it('outputs correct counts', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
// 2 packs past retention → expired
|
|
ReviewPack::factory()->count(2)->ready()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'expires_at' => now()->subDays(3),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune')
|
|
->expectsOutputToContain('2 pack(s) expired, 0 pack(s) hard-deleted')
|
|
->assertSuccessful();
|
|
});
|
|
|
|
it('outputs hard-delete counts when option is passed', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$graceDays = config('tenantpilot.review_pack.hard_delete_grace_days', 30);
|
|
|
|
// 1 pack past retention → expired
|
|
ReviewPack::factory()->ready()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'expires_at' => now()->subDay(),
|
|
]);
|
|
|
|
// 1 expired pack past grace → hard-deleted
|
|
ReviewPack::factory()->expired()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'updated_at' => now()->subDays($graceDays + 10),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune --hard-delete')
|
|
->expectsOutputToContain('1 pack(s) expired, 1 pack(s) hard-deleted')
|
|
->assertSuccessful();
|
|
});
|
|
|
|
it('does not hard-delete without the flag', function (): void {
|
|
[$user, $tenant] = createUserWithTenant();
|
|
|
|
$graceDays = config('tenantpilot.review_pack.hard_delete_grace_days', 30);
|
|
|
|
$pack = ReviewPack::factory()->expired()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'workspace_id' => $tenant->workspace_id,
|
|
'initiated_by_user_id' => $user->id,
|
|
'updated_at' => now()->subDays($graceDays + 10),
|
|
]);
|
|
|
|
$this->artisan('tenantpilot:review-pack:prune')
|
|
->assertSuccessful();
|
|
|
|
expect(ReviewPack::query()->whereKey($pack->getKey())->exists())->toBeTrue();
|
|
});
|
|
|
|
it('AlertRule form no longer shows sla_due option', function (): void {
|
|
$options = AlertRuleResource::eventTypeOptions();
|
|
|
|
expect($options)->not->toHaveKey(AlertRule::EVENT_SLA_DUE)
|
|
->and($options)->toHaveKey(AlertRule::EVENT_HIGH_DRIFT)
|
|
->and($options)->toHaveKey(AlertRule::EVENT_COMPARE_FAILED)
|
|
->and($options)->toHaveKey(AlertRule::EVENT_PERMISSION_MISSING)
|
|
->and($options)->toHaveKey(AlertRule::EVENT_ENTRA_ADMIN_ROLES_HIGH);
|
|
});
|