Implements Spec 104: Provider Permission Posture. What changed - Generates permission posture findings after each tenant permission compare (queued) - Stores immutable posture snapshots as StoredReports (JSONB payload) - Adds global Finding resolved lifecycle (`resolved_at`, `resolved_reason`) with `resolve()` / `reopen()` - Adds alert pipeline event type `permission_missing` (Alerts v1) and Filament option for Alert Rules - Adds retention pruning command + daily schedule for StoredReports - Adds badge mappings for `resolved` finding status and `permission_posture` finding type UX fixes discovered during manual verification - Hide “Diff” section for non-drift findings (only drift findings show diff) - Required Permissions page: “Re-run verification” now links to Tenant view (not onboarding) - Preserve Technical Details `<details>` open state across Livewire re-renders (Alpine state) Verification - Ran `vendor/bin/sail artisan test --compact --filter=PermissionPosture` (50 tests) - Ran `vendor/bin/sail artisan test --compact --filter="FindingResolved|FindingBadge|PermissionMissingAlert"` (20 tests) - Ran `vendor/bin/sail bin pint --dirty` Filament v5 / Livewire v4 compliance - Filament v5 + Livewire v4: no Livewire v3 usage. Panel provider registration (Laravel 11+) - No new panels added. Existing panel providers remain registered via `bootstrap/providers.php`. Global search rule - No changes to global-searchable resources. Destructive actions - No new destructive Filament actions were added in this PR. Assets / deploy notes - No new Filament assets registered. Existing deploy step `php artisan filament:assets` remains unchanged. Test coverage - New/updated Pest feature tests cover generator behavior, job integration, alerting, retention pruning, and resolved lifecycle. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #127
154 lines
4.8 KiB
PHP
154 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Services\PermissionPosture\PostureScoreCalculator;
|
|
|
|
it('returns 100 when all permissions are granted', function (): void {
|
|
$calculator = new PostureScoreCalculator;
|
|
|
|
$result = $calculator->calculate([
|
|
'overall_status' => 'granted',
|
|
'permissions' => [
|
|
['key' => 'Perm.A', 'type' => 'application', 'status' => 'granted', 'features' => ['a']],
|
|
['key' => 'Perm.B', 'type' => 'application', 'status' => 'granted', 'features' => ['b']],
|
|
],
|
|
]);
|
|
|
|
expect($result)->toBe(100);
|
|
});
|
|
|
|
it('returns 86 for 12 of 14 granted', function (): void {
|
|
$calculator = new PostureScoreCalculator;
|
|
|
|
$permissions = [];
|
|
for ($i = 0; $i < 12; $i++) {
|
|
$permissions[] = ['key' => "Perm.$i", 'type' => 'application', 'status' => 'granted', 'features' => []];
|
|
}
|
|
for ($i = 12; $i < 14; $i++) {
|
|
$permissions[] = ['key' => "Perm.$i", 'type' => 'application', 'status' => 'missing', 'features' => []];
|
|
}
|
|
|
|
$result = $calculator->calculate([
|
|
'overall_status' => 'missing',
|
|
'permissions' => $permissions,
|
|
]);
|
|
|
|
expect($result)->toBe(86);
|
|
});
|
|
|
|
it('returns 0 when all permissions are missing', function (): void {
|
|
$calculator = new PostureScoreCalculator;
|
|
|
|
$result = $calculator->calculate([
|
|
'overall_status' => 'missing',
|
|
'permissions' => [
|
|
['key' => 'Perm.A', 'type' => 'application', 'status' => 'missing', 'features' => ['a']],
|
|
['key' => 'Perm.B', 'type' => 'application', 'status' => 'missing', 'features' => ['b']],
|
|
],
|
|
]);
|
|
|
|
expect($result)->toBe(0);
|
|
});
|
|
|
|
it('returns 100 when 0 permissions required', function (): void {
|
|
$calculator = new PostureScoreCalculator;
|
|
|
|
$result = $calculator->calculate([
|
|
'overall_status' => 'granted',
|
|
'permissions' => [],
|
|
]);
|
|
|
|
expect($result)->toBe(100);
|
|
});
|
|
|
|
it('returns 100 for single granted permission', function (): void {
|
|
$calculator = new PostureScoreCalculator;
|
|
|
|
$result = $calculator->calculate([
|
|
'overall_status' => 'granted',
|
|
'permissions' => [
|
|
['key' => 'Perm.A', 'type' => 'application', 'status' => 'granted', 'features' => ['a']],
|
|
],
|
|
]);
|
|
|
|
expect($result)->toBe(100);
|
|
});
|
|
|
|
it('returns 0 for single missing permission', function (): void {
|
|
$calculator = new PostureScoreCalculator;
|
|
|
|
$result = $calculator->calculate([
|
|
'overall_status' => 'missing',
|
|
'permissions' => [
|
|
['key' => 'Perm.A', 'type' => 'application', 'status' => 'missing', 'features' => ['a']],
|
|
],
|
|
]);
|
|
|
|
expect($result)->toBe(0);
|
|
});
|
|
|
|
it('rounds correctly for 1 of 3 granted (33)', function (): void {
|
|
$calculator = new PostureScoreCalculator;
|
|
|
|
$result = $calculator->calculate([
|
|
'overall_status' => 'missing',
|
|
'permissions' => [
|
|
['key' => 'A', 'type' => 'application', 'status' => 'granted', 'features' => []],
|
|
['key' => 'B', 'type' => 'application', 'status' => 'missing', 'features' => []],
|
|
['key' => 'C', 'type' => 'application', 'status' => 'missing', 'features' => []],
|
|
],
|
|
]);
|
|
|
|
expect($result)->toBe(33);
|
|
});
|
|
|
|
it('rounds correctly for 2 of 3 granted (67)', function (): void {
|
|
$calculator = new PostureScoreCalculator;
|
|
|
|
$result = $calculator->calculate([
|
|
'overall_status' => 'missing',
|
|
'permissions' => [
|
|
['key' => 'A', 'type' => 'application', 'status' => 'granted', 'features' => []],
|
|
['key' => 'B', 'type' => 'application', 'status' => 'granted', 'features' => []],
|
|
['key' => 'C', 'type' => 'application', 'status' => 'missing', 'features' => []],
|
|
],
|
|
]);
|
|
|
|
expect($result)->toBe(67);
|
|
});
|
|
|
|
it('returns integer not float', function (): void {
|
|
$calculator = new PostureScoreCalculator;
|
|
|
|
$result = $calculator->calculate([
|
|
'overall_status' => 'missing',
|
|
'permissions' => [
|
|
['key' => 'A', 'type' => 'application', 'status' => 'granted', 'features' => []],
|
|
['key' => 'B', 'type' => 'application', 'status' => 'missing', 'features' => []],
|
|
['key' => 'C', 'type' => 'application', 'status' => 'missing', 'features' => []],
|
|
],
|
|
]);
|
|
|
|
expect($result)->toBeInt();
|
|
});
|
|
|
|
it('returns 50 for 7 of 14 granted', function (): void {
|
|
$calculator = new PostureScoreCalculator;
|
|
|
|
$permissions = [];
|
|
for ($i = 0; $i < 7; $i++) {
|
|
$permissions[] = ['key' => "Perm.$i", 'type' => 'application', 'status' => 'granted', 'features' => []];
|
|
}
|
|
for ($i = 7; $i < 14; $i++) {
|
|
$permissions[] = ['key' => "Perm.$i", 'type' => 'application', 'status' => 'missing', 'features' => []];
|
|
}
|
|
|
|
$result = $calculator->calculate([
|
|
'overall_status' => 'missing',
|
|
'permissions' => $permissions,
|
|
]);
|
|
|
|
expect($result)->toBe(50);
|
|
});
|