You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
7.0 KiB
PHP
207 lines
7.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use App\Services\Cloud\CloudOperationRecoveryIdentity;
|
|
use App\Services\Cloud\CloudWorkerService;
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$compact = new ReflectionMethod(
|
|
CloudWorkerService::class,
|
|
'compactPreparedRecoveryPayload'
|
|
);
|
|
$identityKey = CloudOperationRecoveryIdentity::payloadKey();
|
|
$identity = [
|
|
'version' => 1,
|
|
'kind' => 'backup_create',
|
|
'host_id' => 7,
|
|
'operation_id' => str_repeat('ab', 16),
|
|
'request_fingerprint' => str_repeat('c', 64),
|
|
];
|
|
$largeUrls = [];
|
|
for ($part = 1; $part <= 512; $part++) {
|
|
$largeUrls[] = 'https://storage.example.invalid/backups/object.qcow2?'
|
|
. 'partNumber=' . $part . '&X-Amz-Signature=' . str_repeat('d', 320);
|
|
}
|
|
$createPayload = [
|
|
$identityKey => $identity,
|
|
'owner_id' => 42,
|
|
'can_manage' => true,
|
|
'backup_key' => str_repeat('e', 32),
|
|
'maximum_size_bytes' => 44023414784,
|
|
'method' => 'POST',
|
|
'request_target' => '/v1/vms/uuid/backups',
|
|
'body' => [
|
|
'object_upload' => [
|
|
'part_urls' => $largeUrls,
|
|
'complete_url' => $largeUrls[0],
|
|
'abort_url' => $largeUrls[1],
|
|
'verify_url' => $largeUrls[2],
|
|
],
|
|
],
|
|
];
|
|
$encodedOriginal = json_encode($createPayload, JSON_THROW_ON_ERROR);
|
|
$assert(strlen($encodedOriginal) > 196608,
|
|
'The fixture no longer exercises the prepared-envelope size limit.');
|
|
$createCompact = $compact->invoke(null, 'backup_create', $createPayload);
|
|
$encodedCompact = json_encode($createCompact, JSON_THROW_ON_ERROR);
|
|
$assert(strlen($encodedCompact) < 4096,
|
|
'Prepared backup evidence still retains oversized capabilities.');
|
|
$assert(($createCompact[$identityKey] ?? null) === $identity
|
|
&& ($createCompact['maximum_size_bytes'] ?? null) === 44023414784
|
|
&& !isset($createCompact['body'])
|
|
&& !str_contains($encodedCompact, 'X-Amz-Signature'),
|
|
'Prepared backup evidence lost identity or retained a capability URL.');
|
|
|
|
$restorePublicNetwork = [
|
|
'contract' => 1,
|
|
'network_selector' => 'bridge:restore-wan',
|
|
'ipv4' => [
|
|
'pool_key' => str_repeat('1', 32),
|
|
'pool_cidr' => '203.0.113.0/24',
|
|
'address_cidr' => '203.0.113.19/24',
|
|
'gateway' => '203.0.113.1',
|
|
'gateway_on_link' => false,
|
|
],
|
|
'ipv6' => [
|
|
'pool_key' => str_repeat('2', 32),
|
|
'pool_cidr' => '2001:db8:100::/64',
|
|
'address_cidr' => '2001:db8:100::19/64',
|
|
'gateway' => '2001:db8:100::1',
|
|
'gateway_on_link' => true,
|
|
],
|
|
'dns_servers' => ['9.9.9.9', '2620:fe::fe'],
|
|
];
|
|
$sourceSha256 = str_repeat('3', 64);
|
|
$restorePayload = [
|
|
$identityKey => array_replace($identity, ['kind' => 'backup_restore']),
|
|
'owner_id' => 42,
|
|
'can_manage' => true,
|
|
'backup_key' => str_repeat('e', 32),
|
|
'restore_key' => str_repeat('f', 32),
|
|
'reservation_id' => 91,
|
|
'body' => [
|
|
'operation_id' => str_repeat('cd', 16),
|
|
'uuid' => '00000000-0000-4000-8000-000000000019',
|
|
'name' => 'restore-vm',
|
|
'vcpu' => 4,
|
|
'memory_mib' => 8192,
|
|
'disk_gib' => 80,
|
|
'bandwidth_mbps' => 500,
|
|
'public_network' => $restorePublicNetwork,
|
|
'backup_key' => str_repeat('e', 32),
|
|
'source_size_bytes' => 4294967296,
|
|
'debian_12_network_fix' => false,
|
|
'platform_network_policy_snapshot' => ['contract' => 1],
|
|
'source' => $largeUrls[0],
|
|
'source_url' => $largeUrls[0],
|
|
'source_sha256' => $sourceSha256,
|
|
'root_password' => 'must-not-survive',
|
|
],
|
|
];
|
|
$restoreCompact = $compact->invoke(null, 'backup_restore', $restorePayload);
|
|
$encodedRestore = json_encode($restoreCompact, JSON_THROW_ON_ERROR);
|
|
$assert(($restoreCompact['body'] ?? null) === [
|
|
'operation_id' => str_repeat('cd', 16),
|
|
'uuid' => '00000000-0000-4000-8000-000000000019',
|
|
'name' => 'restore-vm',
|
|
'vcpu' => 4,
|
|
'memory_mib' => 8192,
|
|
'disk_gib' => 80,
|
|
'bandwidth_mbps' => 500,
|
|
'public_network' => $restorePublicNetwork,
|
|
'backup_key' => str_repeat('e', 32),
|
|
'source_size_bytes' => 4294967296,
|
|
'source_sha256' => $sourceSha256,
|
|
'debian_12_network_fix' => false,
|
|
'platform_network_policy_snapshot' => ['contract' => 1],
|
|
]
|
|
&& !array_key_exists('network', $restoreCompact['body'])
|
|
&& !array_key_exists('public_ip_cidr', $restoreCompact['body'])
|
|
&& !str_contains($encodedRestore, '"source"')
|
|
&& !str_contains($encodedRestore, 'source_url')
|
|
&& !str_contains($encodedRestore, 'root_password')
|
|
&& !str_contains($encodedRestore, 'X-Amz-Signature'),
|
|
'Prepared restore evidence lost canonical dual-stack state or source hash,'
|
|
. ' or retained a retired scalar, expired capability, or secret.');
|
|
|
|
$publicNetwork = [
|
|
'attachment_key' => str_repeat('3', 32),
|
|
'network' => 'bridge:br0',
|
|
'addresses' => [
|
|
[
|
|
'address_family' => 4,
|
|
'address_cidr' => '203.0.113.29/24',
|
|
'gateway' => '203.0.113.1',
|
|
'pool_key' => str_repeat('4', 32),
|
|
'dns_servers' => ['9.9.9.9'],
|
|
],
|
|
[
|
|
'address_family' => 6,
|
|
'address_cidr' => '2001:db8:100::29/64',
|
|
'gateway' => '2001:db8:100::1',
|
|
'pool_key' => str_repeat('5', 32),
|
|
'dns_servers' => ['2620:fe::fe'],
|
|
],
|
|
],
|
|
];
|
|
$vpcPort = [
|
|
'vpc_key' => str_repeat('6', 32),
|
|
'address_cidr' => '10.0.0.29/24',
|
|
'mac_address' => '02:00:00:00:00:29',
|
|
];
|
|
$migrationPayload = [
|
|
$identityKey => array_replace(
|
|
$identity,
|
|
['kind' => 'instance_migration_transfer']
|
|
),
|
|
'owner_id' => 42,
|
|
'can_manage' => true,
|
|
'reservation_id' => 92,
|
|
'maintenance_migration_id' => 93,
|
|
'body' => [
|
|
'vcpu' => 8,
|
|
'memory_mib' => 16384,
|
|
'disk_gib' => 160,
|
|
'bandwidth_mbps' => 1000,
|
|
'public_network' => $publicNetwork,
|
|
'vpc_port' => $vpcPort,
|
|
'public_ip_cidr' => '203.0.113.29/24',
|
|
'gateway' => '203.0.113.1',
|
|
'source_url' => $largeUrls[0],
|
|
'root_password' => 'must-not-survive',
|
|
],
|
|
];
|
|
$migrationCompact = $compact->invoke(
|
|
null,
|
|
'instance_migration_transfer',
|
|
$migrationPayload
|
|
);
|
|
$encodedMigration = json_encode(
|
|
$migrationCompact,
|
|
JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES
|
|
);
|
|
$assert(($migrationCompact['body'] ?? null) === [
|
|
'vcpu' => 8,
|
|
'memory_mib' => 16384,
|
|
'disk_gib' => 160,
|
|
'bandwidth_mbps' => 1000,
|
|
'public_network' => $publicNetwork,
|
|
'vpc_port' => $vpcPort,
|
|
]
|
|
&& !str_contains($encodedMigration, 'public_ip_cidr')
|
|
&& !str_contains($encodedMigration, 'source_url')
|
|
&& !str_contains($encodedMigration, 'root_password')
|
|
&& !str_contains($encodedMigration, 'X-Amz-Signature'),
|
|
'Prepared migration evidence lost canonical dual-stack state or retained'
|
|
. ' a retired scalar field, capability, or secret.');
|
|
|
|
echo "Portable-backup prepared recovery envelope contract passed.\n";
|