You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudServiceCompensationAdm...

70 lines
2.8 KiB
PHTML

<?php
declare(strict_types=1);
$root = dirname(__DIR__);
$controller = file_get_contents(
$root . '/app/Controllers/CloudAdminServiceCompensationController.php'
);
$service = file_get_contents(
$root . '/app/Services/Cloud/CloudServiceCompensationService.php'
);
$routes = file_get_contents($root . '/config/routes_cloud.php');
$middleware = file_get_contents($root . '/app/Middleware/CloudApi.php');
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
foreach ([':index', ':preview', ':create', ':detail'] as $action) {
$assert(str_contains(
$routes,
'CloudAdminServiceCompensationController' . $action
), 'Service compensation route is missing: ' . $action);
}
$previewRoute = strpos(
$routes,
"'/admin/service-compensations/preview'"
);
$detailRoute = strpos(
$routes,
"'/admin/service-compensations/{compensation_key:[0-9a-f]{32}}'"
);
$assert($previewRoute !== false && $detailRoute !== false
&& $previewRoute < $detailRoute,
'Static compensation preview route is shadowed by a dynamic route.');
$assert(str_contains(
$middleware,
'#^/api/v1/admin/service-compensations(?:/|$)#D'
), 'Database-only compensation APIs create unnecessary cloud sessions.');
$assert(str_contains($controller, "if (!(\$actor['is_admin'] ?? false))")
&& str_contains($controller, 'CloudAccess::manage($actor)')
&& str_contains(
$controller,
"preg_match('/^[A-Za-z0-9._:-]{16,128}\$/D', \$key)"
), 'Compensation API lost administrator, manage or idempotency checks.');
$assert(str_contains(
$controller,
"CloudInput::only(\$body, ['scope_type', 'scope_id'])"
) && str_contains($controller, "'compensation_seconds'")
&& str_contains($controller, "'audience_digest'")
&& !str_contains($controller, "'emails'")
&& !str_contains($controller, "'user_ids'")
&& !str_contains($controller, "'instance_ids'"),
'Compensation API no longer owns a strict server-derived audience.');
$assert(str_contains(
$controller,
'(new CloudServiceCompensationService())->create('
) && !str_contains($controller, 'ExecutionService')
&& !str_contains($controller, '->tick('),
'HTTP create synchronously executes compensation work.');
$assert(str_contains($controller, 'private static function mask(')
&& str_contains($controller, "'***@'")
&& !str_contains($controller, 'sealed_payload')
&& !str_contains($service, "'sealed_payload'"),
'Read-only compensation detail leaks recipient or sealed data.');
$assert(substr_count($controller, "'private, no-store'") === 1,
'Compensation API responses do not share private no-store caching.');
echo "Service compensation administrator API contracts passed.\n";