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.'); 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'); $workerSource = file_get_contents(dirname(__DIR__) . '/app/Services/Cloud/CloudWorkerService.php'); $assert(is_string($controllerSource) && str_contains($controllerSource, "CloudAccess::manage($actor)") && str_contains($controllerSource, "'network_change'") && str_contains($controllerSource, "'/network'") && 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.'); $automaticName = CloudInput::generateInstanceName(); $assert(preg_match('/^vm-[abcdefghjkmnpqrstuvwxyz23456789]{6}$/D', $automaticName) === 1 && CloudInput::optionalName(null) === null && CloudInput::optionalName('') === null && CloudInput::optionalName('customer-vm') === 'customer-vm', 'Optional or generated instance-name policy drifted.'); $safe = CloudInput::safeResult(['uuid' => '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"; }