'https://cdn.example.net/image.qcow2']), new Response(200, [ 'Content-Length' => (string) strlen($body), 'Content-Encoding' => 'identity', ], $body), ])); $stack->push(Middleware::history($history)); $resolver = static fn (string $host): array => match ($host) { 'images.example.com' => ['93.184.216.34'], 'cdn.example.net' => ['1.1.1.1'], default => [], }; $fetcher = new CloudTemplateRemoteFetcher( new Client(['handler' => $stack]), $resolver ); $file = $fetcher->fetch( 'https://images.example.com/debian-13.qcow2', $digest ); try { $assert($file['size_bytes'] === strlen($body) && $file['sha256'] === $digest && hash_file('sha256', $file['path']) === $digest && count($history) === 2 && (string) $history[1]['request']->getUri() === 'https://cdn.example.net/image.qcow2', 'Remote template acquisition lost redirect, size or digest identity.'); } finally { @unlink($file['path']); } $blocked = false; try { (new CloudTemplateRemoteFetcher( new Client(['handler' => HandlerStack::create(new MockHandler([]))]), static fn (string $host): array => ['10.0.0.10'] ))->fetch('https://internal.example/image.qcow2'); } catch (CloudError $error) { $blocked = $error->httpStatus === 422; } $assert($blocked, 'Remote template acquisition accepted a private target.'); echo "Remote cloud-template acquisition contract passed.\n";