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

85 lines
4.6 KiB
PHTML

<?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);
}
};
$routes = $read('config/routes.php');
$controller = $read('app/Controllers/Admin/ObjectStorageController.php');
$service = $read('app/Services/Cloud/CloudObjectStorageConfig.php');
$client = $read('app/Services/Cloud/CloudObjectStorageS3Client.php');
$template = $read('resources/views/venix/admin/object_storage.tpl');
$sidebar = $read('resources/views/venix/admin/static_header.tpl');
$deployment = file_get_contents(dirname($root) . '/docs/DEPLOYMENT.md');
$validation = file_get_contents(dirname($root) . '/docs/VALIDATION.md');
$assert(str_contains($routes,
"get('/object-storage', 'App\\Controllers\\Admin\\ObjectStorageController:index')"),
'Object-storage admin page route is missing.');
foreach (['config' => 'save', 'test' => 'test', 'disable' => 'disable'] as $path => $action) {
$needle = "post('/object-storage/{$path}', 'App\\Controllers\\Admin\\ObjectStorageController:{$action}')->add(new SuperAdmin())";
$assert(str_contains($routes, $needle),
'Object-storage mutation lost SuperAdmin/CSRF middleware: ' . $action);
}
$assert(str_contains($routes,
"get('/object-storage/cleanup-debts', 'App\\Controllers\\Admin\\ObjectStorageController:cleanupDebt')")
&& str_contains($routes,
"post('/object-storage/cleanup-debts/{backup_id:[0-9]+}/retry', 'App\\Controllers\\Admin\\ObjectStorageController:retryCleanup')->add(new SuperAdmin())"),
'Object cleanup debt list or protected manual retry route is missing.');
$assert(str_contains($sidebar, 'href="/admin/object-storage"')
&& str_contains($sidebar, '<span>对象存储</span>'),
'Object-storage navigation entry is missing.');
$assert(str_contains($service, "CloudSecrets::encrypt([")
&& str_contains($service, "'object-storage-credentials'")
&& str_contains($service, "lockForUpdate()")
&& str_contains($service, "tested_revision")
&& str_contains($service, "expected_revision"),
'Object-storage encryption, revision, or readiness gate is missing.');
$headBucket = preg_match(
'/public function headBucket\(.*?\n \}/s',
$client,
$headBucketMatch
) === 1 ? $headBucketMatch[0] : '';
$assert(str_contains($headBucket, "request('HEAD'")
&& str_contains($headBucket, "'allow_redirects' => false")
&& str_contains($headBucket, "'verify' => true")
&& str_contains($headBucket, "'proxy' => ''")
&& !str_contains($headBucket, "request('PUT'")
&& !str_contains($headBucket, "request('DELETE'"),
'Connectivity test is no longer a bounded, read-only, TLS-strict HeadBucket call.');
$assert(str_contains($template, "admin_title value='对象存储'")
&& substr_count($template, 'name="access_key_id" type="password" value=""') === 1
&& substr_count($template, 'name="secret_access_key" type="password" value=""') === 1
&& !str_contains($template, '$object_storage.access_key_id')
&& !str_contains($template, '$object_storage.secret_access_key')
&& str_contains($template, 'data-can-manage=')
&& str_contains($template, 's3:ListBucket')
&& str_contains($template, '对象清理异常')
&& str_contains($template, 'os-cleanup-retry')
&& !str_contains($template, '$item.object_version_id'),
'Admin UI can expose credentials or lost its permission/test boundary.');
$assert(str_contains($controller, "'Cache-Control', 'private, no-store'")
&& str_contains($controller, 'CloudBackupService::cleanupDebt')
&& str_contains($controller, 'CloudBackupService::retryCleanup')
&& preg_match('/error_log\\([^\\n]*getMessage/', $controller) !== 1,
'Object-storage responses lost no-store or may log raw exception messages.');
$assert(is_string($deployment) && str_contains($deployment, '### 对象存储应用')
&& str_contains($deployment, '可移植备份')
&& str_contains($deployment, 'multipart 上传、读取、HEAD 和删除权限')
&& str_contains($deployment, '非当前版本和过期删除标记')
&& str_contains($deployment, '终止未完成 multipart')
&& is_string($validation) && str_contains($validation, '对象存储配置页面不得回显'),
'Deployment or validation boundaries are not documented.');
echo "Object-storage admin routes, UI, security, and documentation contract passed.\n";