|
|
|
|
<?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.');
|
|
|
|
|
|
|
|
|
|
$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' => [
|
|
|
|
|
'vcpu' => 4,
|
|
|
|
|
'memory_mib' => 8192,
|
|
|
|
|
'disk_gib' => 80,
|
|
|
|
|
'bandwidth_mbps' => 500,
|
|
|
|
|
'network' => 'bridge:restore-wan',
|
|
|
|
|
'public_ip_cidr' => '203.0.113.19/24',
|
|
|
|
|
'public_pool_key' => str_repeat('1', 32),
|
|
|
|
|
'public_pool_cidr' => '203.0.113.0/24',
|
|
|
|
|
'gateway' => '203.0.113.1',
|
|
|
|
|
'dns_servers' => ['9.9.9.9', '149.112.112.112'],
|
|
|
|
|
'source_url' => $largeUrls[0],
|
|
|
|
|
'source_sha256' => str_repeat('2', 64),
|
|
|
|
|
'root_password' => 'must-not-survive',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$restoreCompact = $compact->invoke(null, 'backup_restore', $restorePayload);
|
|
|
|
|
$encodedRestore = json_encode($restoreCompact, JSON_THROW_ON_ERROR);
|
|
|
|
|
$assert(($restoreCompact['body'] ?? null) === [
|
|
|
|
|
'vcpu' => 4,
|
|
|
|
|
'memory_mib' => 8192,
|
|
|
|
|
'disk_gib' => 80,
|
|
|
|
|
'bandwidth_mbps' => 500,
|
|
|
|
|
'network' => 'bridge:restore-wan',
|
|
|
|
|
'public_ip_cidr' => '203.0.113.19/24',
|
|
|
|
|
'public_pool_key' => str_repeat('1', 32),
|
|
|
|
|
'public_pool_cidr' => '203.0.113.0/24',
|
|
|
|
|
'gateway' => '203.0.113.1',
|
|
|
|
|
'dns_servers' => ['9.9.9.9', '149.112.112.112'],
|
|
|
|
|
]
|
|
|
|
|
&& !str_contains($encodedRestore, 'source_url')
|
|
|
|
|
&& !str_contains($encodedRestore, 'root_password')
|
|
|
|
|
&& !str_contains($encodedRestore, 'X-Amz-Signature'),
|
|
|
|
|
'Prepared restore evidence retained an expired capability or secret.');
|
|
|
|
|
|
|
|
|
|
echo "Portable-backup prepared recovery envelope contract passed.\n";
|