|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
$root = dirname(__DIR__);
|
|
|
|
|
$read = static function (string $path) use ($root): string {
|
|
|
|
|
$value = file_get_contents($root . '/' . $path);
|
|
|
|
|
if (!is_string($value)) {
|
|
|
|
|
throw new RuntimeException('Unable to read ' . $path);
|
|
|
|
|
}
|
|
|
|
|
return $value;
|
|
|
|
|
};
|
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
|
|
|
if (!$condition) {
|
|
|
|
|
throw new RuntimeException($message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$routes = $read('config/routes_cloud.php');
|
|
|
|
|
$controller = $read('app/Controllers/CloudAdminTrafficPoolController.php');
|
|
|
|
|
$middleware = $read('app/Middleware/CloudApi.php');
|
|
|
|
|
$service = $read('app/Services/Cloud/CloudAdminTrafficPoolService.php');
|
|
|
|
|
$binding = $read('app/Services/Cloud/CloudTrafficPoolPeriodBinding.php');
|
|
|
|
|
|
|
|
|
|
$assert(str_contains($routes,
|
|
|
|
|
"'/admin/traffic-pool-groups'")
|
|
|
|
|
&& str_contains($routes,
|
|
|
|
|
"'/admin/traffic-pool-groups/{id:[1-9][0-9]*}'")
|
|
|
|
|
&& str_contains($routes,
|
|
|
|
|
"'/admin/traffic-pool-groups/{id:[1-9][0-9]*}/lines'")
|
|
|
|
|
&& substr_count($routes, 'CloudAdminTrafficPoolController:') >= 3,
|
|
|
|
|
'Administrator traffic-pool routes are incomplete.');
|
|
|
|
|
$assert(str_contains($middleware,
|
|
|
|
|
'#^/api/v1/admin/traffic-pool-groups(?:/[1-9][0-9]*(?:/(?:lines|readiness))?)?$#D'),
|
|
|
|
|
'Administrator traffic-pool database routes must not require an Agent session.');
|
|
|
|
|
$assert(!preg_match(
|
|
|
|
|
"/delete\([^\n]*traffic-pool-groups|map\(\[[^\]]*DELETE[^\]]*\][^\n]*traffic-pool-groups/i",
|
|
|
|
|
$routes
|
|
|
|
|
),
|
|
|
|
|
'Traffic-pool groups must not expose a destructive delete route.');
|
|
|
|
|
|
|
|
|
|
$assert(str_contains($controller, 'CloudAccess::manage($actor)')
|
|
|
|
|
&& str_contains($controller, "'Cache-Control', 'private, no-store'")
|
|
|
|
|
&& str_contains($controller, "CloudInput::only(\$body")
|
|
|
|
|
&& str_contains($controller, "['code', 'name']")
|
|
|
|
|
&& str_contains($controller, "['name', 'mode', 'expected_revision']")
|
|
|
|
|
&& str_contains($controller, "['line_ids', 'expected_revision']"),
|
|
|
|
|
'Administrator traffic-pool writes are not permissioned or allow-listed.');
|
|
|
|
|
|
|
|
|
|
foreach (['page', 'create', 'update', 'replaceLines', 'readiness'] as $method) {
|
|
|
|
|
$assert(str_contains($service,
|
|
|
|
|
'public static function ' . $method . '('),
|
|
|
|
|
'Missing administrator traffic-pool service method: ' . $method);
|
|
|
|
|
}
|
|
|
|
|
$assert(str_contains($service, "'disabled'")
|
|
|
|
|
&& str_contains($service, "'shadow'")
|
|
|
|
|
&& str_contains($service, "'enforced'")
|
|
|
|
|
&& preg_match('/enforced.{0,240}(?:cannot|禁止|不允许|409)/s', $service),
|
|
|
|
|
'Traffic-pool mode changes do not visibly enforce the one-way state machine.');
|
|
|
|
|
$assert(str_contains($service, "'ready'")
|
|
|
|
|
&& str_contains($service, "'blockers'")
|
|
|
|
|
&& str_contains($service, 'CloudTrafficPoolAccounting::verifyProjection(')
|
|
|
|
|
&& str_contains($service, 'CloudTrafficScanFailure')
|
|
|
|
|
&& str_contains($service, 'CloudInstanceNetworkPolicyState')
|
|
|
|
|
&& str_contains($service, 'CloudJob'),
|
|
|
|
|
'Enforced-mode readiness omits accounting, scan, policy, or job fences.');
|
|
|
|
|
|
|
|
|
|
$lineOrder = strpos($service, "->orderBy('id')");
|
|
|
|
|
$lineLock = $lineOrder === false ? false
|
|
|
|
|
: strpos($service, '->lockForUpdate()', $lineOrder);
|
|
|
|
|
$groupLock = $lineLock === false ? false
|
|
|
|
|
: strpos($service, 'CloudTrafficPoolGroup::where(', $lineLock);
|
|
|
|
|
$assert($lineOrder !== false && $lineLock !== false
|
|
|
|
|
&& $groupLock !== false
|
|
|
|
|
&& strpos($service, '->lockForUpdate()', $groupLock) !== false,
|
|
|
|
|
'Administrator mappings no longer lock ordered lines before the group.');
|
|
|
|
|
$assert(!preg_match(
|
|
|
|
|
'/CloudTrafficPool::[\s\S]{0,180}->lockForUpdate\(\)/',
|
|
|
|
|
$service
|
|
|
|
|
),
|
|
|
|
|
'Administrator configuration crossed into the accounting pool lock domain.');
|
|
|
|
|
$assert(str_contains($service, 'traffic_pool_group_id')
|
|
|
|
|
&& str_contains($service, 'CloudServicePeriod')
|
|
|
|
|
&& str_contains($service, 'CloudInstanceNetworkRestriction'),
|
|
|
|
|
'Line remapping and mode rollback do not fence frozen period/policy use.');
|
|
|
|
|
|
|
|
|
|
$assert(preg_match(
|
|
|
|
|
'/CloudNetworkLine::where\([\s\S]{0,220}->lockForUpdate\(\)[\s\S]{0,400}CloudTrafficPoolGroup::where\([\s\S]{0,220}->lockForUpdate\(\)/',
|
|
|
|
|
$binding
|
|
|
|
|
) === 1,
|
|
|
|
|
'Purchase snapshot and administrator mappings lack a shared line-to-group lock.');
|
|
|
|
|
|
|
|
|
|
echo "Cloud administrator traffic-pool contract passed.\n";
|