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/CloudObjectStorageOperation...

82 lines
3.9 KiB
PHP

<?php
$root = dirname(__DIR__);
$read = static function (string $path) use ($root): string {
$contents = file_get_contents($root . '/' . $path);
if ($contents === false) {
throw new RuntimeException('Unable to read ' . $path);
}
return $contents;
};
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$method = static function (string $source, string $name, string $next) use ($assert): string {
$pattern = '/public static function ' . preg_quote($name, '/')
. '\\b[\\s\\S]*?(?=\\n public static function '
. preg_quote($next, '/') . '\\b)/';
$assert(preg_match($pattern, $source, $match) === 1,
'Unable to isolate ' . $name . ' contract.');
return $match[0];
};
$routes = $read('config/routes.php');
$config = $read('app/Services/Cloud/CloudObjectStorageConfig.php');
$backups = $read('app/Services/Cloud/CloudBackupService.php');
foreach (['config' => 'save', 'test' => 'test', 'disable' => 'disable'] as $path => $action) {
$assert(str_contains($routes,
"post('/object-storage/{$path}', 'App\\Controllers\\Admin\\ObjectStorageController:{$action}')->add(new SuperAdmin())"),
'Object-storage mutation route lost its SuperAdmin gate: ' . $action);
}
$assert(str_contains($routes,
"post('/object-storage/cleanup-debts/{backup_id:[0-9]+}/retry', 'App\\Controllers\\Admin\\ObjectStorageController:retryCleanup')->add(new SuperAdmin())"),
'Cleanup-debt retry lost its SuperAdmin gate.');
$publicState = preg_match(
'/private static function publicState\\(array \\$raw\\): array[\\s\\S]*?(?=\\n private static function )/',
$config,
$publicStateMatch
) === 1 ? $publicStateMatch[0] : '';
$assert($publicState !== ''
&& str_contains($publicState, "'credentials_configured'")
&& str_contains($publicState, "'tested_revision'")
&& !str_contains($publicState, "'sealed_credentials' =>")
&& !str_contains($publicState, "'access_key_id' =>")
&& !str_contains($publicState, "'secret_access_key' =>"),
'Browser-visible object-storage state may expose credentials or lost readiness metadata.');
$save = $method($config, 'save', 'testAndEnable');
$test = $method($config, 'testAndEnable', 'disable');
$disable = $method($config, 'disable', 'runtime');
$assert(str_contains($save, "'expected_revision'")
&& str_contains($save, 'lockForUpdate()')
&& str_contains($save, 'invalidateReadiness()'),
'Saving object storage must remain revision-locked and invalidate readiness.');
$assert(str_contains($test, 'headBucket(')
&& str_contains($test, "self::set('tested_revision', (string) \$expected)")
&& str_contains($test, "self::set('enabled', 'true')"),
'Connection validation must remain read-only and enable the tested revision only.');
$assert(str_contains($disable, 'lockForUpdate()')
&& str_contains($disable, "self::set('enabled', 'false')")
&& !str_contains($disable, "self::set('sealed_credentials'"),
'Disabling object storage must preserve encrypted credentials.');
$cleanupDebt = $method($backups, 'cleanupDebt', 'retryCleanup');
$retryCleanup = $method($backups, 'retryCleanup', 'create');
$assert(str_contains($cleanupDebt, "'next_check_at'")
&& str_contains($cleanupDebt, "'attention_at'")
&& str_contains($cleanupDebt, "'can_retry'")
&& !str_contains($cleanupDebt, "'object_key'")
&& !str_contains($cleanupDebt, "'object_version_id'"),
'Cleanup-debt view must expose scheduling metadata without remote object identity.');
$assert(str_contains($retryCleanup, 'inspectObject(')
&& str_contains($retryCleanup, "'delete_uncertain'")
&& str_contains($retryCleanup, 'manual_retry_awaiting_stable_probe')
&& !str_contains($retryCleanup, 'deleteObject('),
'Manual cleanup retry must restart stable inspection without replaying DELETE.');
echo "Object-storage operations and cleanup safety contract passed.\n";