9, 'is_admin' => false, 'is_super_admin' => false, 'can_manage' => true, 'session_id' => str_repeat('a', 64)]; $body = '{"session_id":"example"}'; $path = '/api/internal/cloud/session-introspection?a=1%2F2'; $headers = CloudEngineClient::headers('POST', $path, $body, $actor, 1800000000, 'PythonUrlSafeNonce_ab-CD_123456789'); $named = ['timestamp' => $headers['X-Cloud-Timestamp'], 'nonce' => $headers['X-Cloud-Nonce'], 'actor' => $headers['X-Cloud-Actor'], 'signature' => $headers['X-Cloud-Signature']]; $assert(CloudInternalController::validSignature('POST', $path, $body, $named, str_repeat('k', 32), 1800000000), 'Signed request rejected.'); foreach ([['POST', $path . '0', $body, 1800000000], ['GET', $path, $body, 1800000000], ['POST', $path, $body . ' ', 1800000000], ['POST', $path, $body, 1800000061]] as [$method, $target, $raw, $now]) { $assert(!CloudInternalController::validSignature($method, $target, $raw, $named, str_repeat('k', 32), $now), 'Tampered or stale signature accepted.'); } $digest = hash('sha256', $body); $assert(CloudEngineClient::canonicalDigest('POST', $path, $digest, '1800000000', $named['nonce'], $named['actor']) === CloudEngineClient::canonical('POST', $path, $body, '1800000000', $named['nonce'], $named['actor']), 'Upload digest contract differs.'); $assert(CloudWorkerService::disposition(['status' => 'failed'], true) === 'uncertain', 'Unknown creation failure must not refund.'); $assert(CloudWorkerService::disposition(['status' => 'failed', 'safe_to_refund' => false], true) === 'uncertain', 'Explicitly unsafe creation failure must not refund.'); $assert(CloudWorkerService::disposition(['status' => 'failed', 'safe_to_refund' => true], true) === 'failed', 'Confirmed absent creation must refund.'); $assert(CloudWorkerService::disposition([ 'status' => 'succeeded', 'error_code' => 'reinstall_cleanup_pending', 'result' => ['reinstall_committed' => true, 'cleanup_pending' => true], ], false, 'reinstall') === 'uncertain', 'A committed reinstall with pending cleanup was reported as success.'); $assert(CloudWorkerService::disposition([ 'status' => 'succeeded', 'result' => ['vm' => ['state' => 'running']], ], false, 'reinstall') === 'succeeded', 'A normal reinstall was changed to uncertain.'); $assert(CloudWorkerService::disposition([ 'status' => 'succeeded', 'result' => ['warning' => '旧存储卷 /srv/old.qcow2 删除失败'], ], false, 'reinstall') === 'uncertain', 'A legacy successful reinstall warning was still treated as success.'); $assert(CloudWorkerService::disposition([ 'status' => 'failed', 'error_code' => 'reinstall_cleanup_pending', 'result' => ['reinstall_committed' => true, 'cleanup_pending' => true], ], false, 'reinstall') === 'uncertain', 'A failed envelope with a committed reinstall marker was replayable.'); $assert(CloudOperationErrorCatalog::workerSummary('reinstall', 'uncertain', [ 'result' => ['warning' => '旧存储卷 /srv/old.qcow2 删除失败'], ]) === 'reinstall_cleanup_pending', 'Legacy reinstall cleanup warning lost its reviewed uncertainty code.'); foreach (['shortA1!', 'longwithoutupper1!', 'ALLUPPERCASE!123', 'LongWithoutSymbol123', 'NoDigitsLong!Aa', "StrongPassword!1\n", 'Strong Password!123', 'StrongPassword!123含中文', str_repeat('a', 126) . 'A1!'] as $bad) { try { CloudInput::password($bad); throw new RuntimeException('Weak guest password accepted.'); } catch (CloudError $expected) {} } $alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%*-_=+?'; $assert(CloudInput::ROOT_PASSWORD_ALPHABET === $alphabet && CloudInput::ROOT_PASSWORD_LENGTH === 32 && CloudInput::ROOT_PASSWORD_MIN_LENGTH === 12 && CloudInput::ROOT_PASSWORD_MAX_LENGTH === 128, 'PHP/Python guest password contract drifted.'); $generated = []; for ($index = 0; $index < 50; $index++) { $password = CloudInput::password(null); $generated[] = $password; $assert(strlen($password) === 32 && strspn($password, $alphabet) === 32 && preg_match('/[A-Z]/', $password) === 1 && preg_match('/[a-z]/', $password) === 1 && preg_match('/[0-9]/', $password) === 1 && preg_match('/[^A-Za-z0-9]/', $password) === 1, 'Generated guest password violates the uniform 32-character policy.'); } $assert(count(array_unique($generated)) === 50 && count(array_unique(array_map(static fn ($value) => substr($value, 0, 4), $generated))) > 1, 'Generated guest passwords repeat or retain a fixed prefix.'); $assert(strlen(CloudInput::password('Aa1!' . str_repeat('x', 124))) === 128, 'Guest manual password bounds wrong.'); $assert(CloudInput::publicIpCidr('203.0.113.10/24') === '203.0.113.10/24' && CloudInput::publicIpCidr('198.51.100.2/32') === '198.51.100.2/32', 'Network-change IPv4 CIDR validation rejected a valid public address.'); foreach (['203.0.113.10', '203.0.113.10/0', '203.0.113.10/33', '2001:db8::10/64', '203.0.113.999/24', '203.0.113.10/24/1'] as $badCidr) { try { CloudInput::publicIpCidr($badCidr); throw new RuntimeException('Invalid network-change CIDR accepted: ' . $badCidr); } catch (CloudError $expected) { $assert($expected->httpStatus === 422, 'Invalid network-change CIDR returned an unexpected status.'); } } $controllerSource = file_get_contents(dirname(__DIR__) . '/app/Controllers/CloudAdminInstanceController.php'); $routesSource = file_get_contents(dirname(__DIR__) . '/config/routes_cloud.php'); $workerSource = file_get_contents(dirname(__DIR__) . '/app/Services/Cloud/CloudWorkerService.php'); $adminInstanceTemplate = file_get_contents(dirname(__DIR__) . '/resources/views/venix/admin/cloud/instances.tpl'); $adminInstanceScript = file_get_contents(dirname(__DIR__) . '/public/cloud/admin-instances.js'); $assert(is_string($controllerSource) && str_contains($controllerSource, "CloudAccess::manage($actor)") && str_contains($controllerSource, "'network_change'") && str_contains($controllerSource, "'/network'") && is_string($routesSource) && str_contains($routesSource, "/admin/instances/{id:[0-9]+}/network-options") && is_string($workerSource) && str_contains($workerSource, "\$job->kind === 'network_change'") && str_contains($workerSource, "引擎成功结果缺少已确认的公网 IP"), 'Administrator network-change route lost its super-admin queue or post-engine confirmation contract.'); $assert(is_string($adminInstanceTemplate) && str_contains($adminInstanceTemplate, '{if $admin_can_manage|default:false}') && str_contains($adminInstanceTemplate, 'admin-instance-network-controls') && str_contains($adminInstanceTemplate, 'name="public_ip_cidr"') && str_contains($adminInstanceTemplate, ' 'test', 'generated_password' => 'never-save', 'nested' => ['private_key' => 'secret', 'name' => 'safe']]); $assert($safe === ['uuid' => 'test', 'nested' => ['name' => 'safe']], 'Secret entered durable job output.'); echo "Cloud money, password, HMAC and ambiguity checks passed.\n"; }