['8.8.8.103', '2001:4860:4860::8888', '8.8.8.103'], ]); $assert($resolver->resolve('agent.example.test') === ['2001:4860:4860::8888', '8.8.8.103'], 'The static resolver did not normalize, de-duplicate and sort explicit addresses.'); $assert($resolver->resolve('AGENT.EXAMPLE.TEST.') === $resolver->resolve('agent.example.test'), 'DNS-name case or the root dot changed the allowlist lookup.'); $assert($resolver->resolve('missing.example.test') === [] && $resolver->resolve('agent/example.test') === [], 'Unknown or malformed hosts were not failed closed.'); foreach ([ ['agent.example.test' => []], ['agent.example.test' => ['127.0.0.1']], ['agent.example.test' => ['192.0.2.10']], ['bad host' => ['8.8.8.8']], ['agent.example.test' => ['8.8.8.8'], 'AGENT.EXAMPLE.TEST.' => ['8.8.4.4']], ] as $invalidAllowlist) { try { new CloudAgentStaticHostResolver($invalidAllowlist); throw new RuntimeException('Unsafe Agent address allowlist was accepted.'); } catch (InvalidArgumentException $expected) { $assert($expected->getMessage() !== '', 'Allowlist rejection did not include a reason.'); } } $settings = [ 'cloud_agent_secret_dir' => '/run/virt-cloud/agents', 'cloud_agent_address_allowlist' => ['agent.example.test' => ['8.8.8.103']], 'cloud_agent_timeout' => '12.5', ]; $testClientFactory = static function (...$arguments): mixed { // The factory contract is tested before Composer/Guzzle is installed; // actual transport construction is covered by CloudAgentClient tests. return null; }; $testFingerprint = static fn (string $path): string => str_repeat('a', 64); $testPathValidator = static fn (string $path, bool $privateKey = false): bool => true; $assembled = CloudAgentHostClientResolverFactory::create( $settings, null, $testClientFactory, $testFingerprint, $testPathValidator, ); $assert($assembled instanceof CloudAgentHostClientResolver, 'The Agent resolver factory did not return the typed resolver.'); $reflection = new ReflectionClass($assembled); $hostProperty = $reflection->getProperty('hostResolver'); $hostProperty->setAccessible(true); $secretProperty = $reflection->getProperty('secrets'); $secretProperty->setAccessible(true); $configuredHostResolver = $hostProperty->getValue($assembled); $configuredSecrets = $secretProperty->getValue($assembled); $assert($configuredHostResolver instanceof CloudAgentStaticHostResolver && $configuredHostResolver->resolve('agent.example.test') === ['8.8.8.103'], 'Factory configuration did not install the explicit host resolver.'); $assert($configuredSecrets instanceof CloudAgentFileSecretResolver, 'Factory configuration did not install the file-backed secret resolver.'); $GLOBALS['System_Config'] = [ 'cloud_agent_secret_dir' => '/run/virt-cloud/agents', 'cloud_agent_address_allowlist' => ['agent.example.test' => ['8.8.8.103']], 'cloud_agent_timeout' => 11, ]; $fromConfig = CloudAgentHostClientResolverFactory::fromConfig( null, null, $testClientFactory, $testFingerprint, $testPathValidator, ); $configReflection = new ReflectionClass($fromConfig); $configHostProperty = $configReflection->getProperty('hostResolver'); $configHostProperty->setAccessible(true); $configHost = $configHostProperty->getValue($fromConfig); $assert($configHost instanceof CloudAgentStaticHostResolver && $configHost->resolve('agent.example.test') === ['8.8.8.103'], 'fromConfig() did not read the explicit address allowlist.'); $source = file_get_contents(dirname(__DIR__) . '/app/Services/Cloud/CloudAgentStaticHostResolver.php'); $factorySource = file_get_contents(dirname(__DIR__) . '/app/Services/Cloud/CloudAgentHostClientResolverFactory.php'); $assert(is_string($source) && is_string($factorySource) && !str_contains($source, 'gethostbyname') && !str_contains($source, 'dns_get_record') && !str_contains($source, 'getaddrinfo') && !str_contains($source, 'ssh') && !str_contains($source, 'Python') && str_contains($factorySource, 'CloudAgentFileSecretResolver') && str_contains($factorySource, 'CloudAgentStaticHostResolver') && !str_contains($factorySource, 'CloudEngineClient') && !str_contains($factorySource, 'ssh'), 'The Agent assembly boundary introduced ambient DNS or a legacy transport fallback.'); fwrite(STDOUT, "Cloud Agent static resolver contract passed.\n");