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.
37 lines
1.1 KiB
PHTML
37 lines
1.1 KiB
PHTML
|
1 day ago
|
<?php
|
||
|
|
|
||
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||
|
|
|
||
|
|
use App\Services\Cloud\CloudLogIdentity;
|
||
|
|
|
||
|
|
$assert = static function (bool $condition, string $message): void {
|
||
|
|
if (!$condition) {
|
||
|
|
throw new RuntimeException($message);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
$uuid = '123e4567-e89b-42d3-a456-426614174000';
|
||
|
|
$stored = CloudLogIdentity::uuid($uuid);
|
||
|
|
$assert(strlen($stored) === 16
|
||
|
|
&& CloudLogIdentity::uuidKey($uuid) === str_replace('-', '', $uuid)
|
||
|
|
&& CloudLogIdentity::storedUuidKey($stored)
|
||
|
|
=== str_replace('-', '', $uuid)
|
||
|
|
&& strlen(CloudLogIdentity::sha256('telemetry')) === 32,
|
||
|
|
'Compact log identities are not lossless fixed-width values.');
|
||
|
|
|
||
|
|
try {
|
||
|
|
CloudLogIdentity::uuid('not-a-uuid');
|
||
|
|
throw new RuntimeException('Malformed UUID was accepted.');
|
||
|
|
} catch (InvalidArgumentException) {
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
CloudLogIdentity::storedUuidKey('short');
|
||
|
|
throw new RuntimeException('Malformed stored UUID was accepted.');
|
||
|
|
} catch (RuntimeException $error) {
|
||
|
|
$assert($error->getMessage() === 'Stored VM UUID is invalid',
|
||
|
|
'Stored UUID validation returned the wrong error.');
|
||
|
|
}
|
||
|
|
|
||
|
|
echo "Compact cloud log identity checks passed.\n";
|