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.
115 lines
3.6 KiB
PHP
115 lines
3.6 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use App\Services\Cloud\CloudPublicNetworkAddressPolicy;
|
|
use App\Services\Cloud\CloudPublicNetworkCandidateCatalog;
|
|
use App\Services\Cloud\CloudPublicNetworkCandidatePlan;
|
|
|
|
$root = dirname(__DIR__) . '/app/Services/Cloud/';
|
|
$policy = file_get_contents($root . 'CloudPublicNetworkAddressPolicy.php');
|
|
$catalog = file_get_contents(
|
|
$root . 'CloudPublicNetworkCandidateCatalog.php'
|
|
);
|
|
if (!is_string($policy) || !is_string($catalog)) {
|
|
throw new RuntimeException('Unable to read public-network policy sources.');
|
|
}
|
|
|
|
$methods = array_values(array_map(
|
|
static fn (ReflectionMethod $method): string => $method->getName(),
|
|
array_filter(
|
|
(new ReflectionClass(CloudPublicNetworkAddressPolicy::class))
|
|
->getMethods(ReflectionMethod::IS_PUBLIC),
|
|
static fn (ReflectionMethod $method): bool =>
|
|
$method->getDeclaringClass()->getName()
|
|
=== CloudPublicNetworkAddressPolicy::class
|
|
)
|
|
));
|
|
sort($methods, SORT_STRING);
|
|
if ($methods !== [
|
|
'addressSelectable',
|
|
'assertIdentity',
|
|
'assertSelectable',
|
|
'contract',
|
|
]) {
|
|
throw new RuntimeException('Address policy public seam drifted.');
|
|
}
|
|
|
|
foreach ([
|
|
'DB::',
|
|
'lockForUpdate(',
|
|
'::find(',
|
|
'->save(',
|
|
'->update(',
|
|
'->insert(',
|
|
'->delete(',
|
|
] as $forbidden) {
|
|
if (str_contains($policy, $forbidden)
|
|
|| str_contains($catalog, $forbidden)) {
|
|
throw new RuntimeException(
|
|
'Pure public-network policy/catalog performs persistence: '
|
|
. $forbidden
|
|
);
|
|
}
|
|
}
|
|
$catalogMethods = array_values(array_map(
|
|
static fn (ReflectionMethod $method): string => $method->getName(),
|
|
array_filter(
|
|
(new ReflectionClass(CloudPublicNetworkCandidateCatalog::class))
|
|
->getMethods(ReflectionMethod::IS_PUBLIC),
|
|
static fn (ReflectionMethod $method): bool =>
|
|
$method->getDeclaringClass()->getName()
|
|
=== CloudPublicNetworkCandidateCatalog::class
|
|
)
|
|
));
|
|
$expectedCatalogMethods = [
|
|
'fromLocked',
|
|
'planAllocation',
|
|
'planTransition',
|
|
];
|
|
sort($catalogMethods, SORT_STRING);
|
|
sort($expectedCatalogMethods, SORT_STRING);
|
|
$plan = new ReflectionClass(CloudPublicNetworkCandidatePlan::class);
|
|
$planMethods = array_values(array_map(
|
|
static fn (ReflectionMethod $method): string => $method->getName(),
|
|
array_filter(
|
|
$plan->getMethods(ReflectionMethod::IS_PUBLIC),
|
|
static fn (ReflectionMethod $method): bool =>
|
|
$method->getDeclaringClass()->getName()
|
|
=== CloudPublicNetworkCandidatePlan::class
|
|
)
|
|
));
|
|
sort($planMethods, SORT_STRING);
|
|
if ($catalogMethods !== $expectedCatalogMethods
|
|
|| $planMethods !== [
|
|
'__construct',
|
|
'allocationSelection',
|
|
'attachment',
|
|
'candidates',
|
|
'changedFamilies',
|
|
'pools',
|
|
]
|
|
|| !$plan->isFinal() || !$plan->isReadOnly()) {
|
|
throw new RuntimeException('Candidate catalog public seam drifted.');
|
|
}
|
|
|
|
$iterator = new RecursiveIteratorIterator(
|
|
new RecursiveDirectoryIterator($root, FilesystemIterator::SKIP_DOTS)
|
|
);
|
|
foreach ($iterator as $file) {
|
|
if (!$file->isFile() || $file->getExtension() !== 'php') {
|
|
continue;
|
|
}
|
|
$contents = file_get_contents($file->getPathname());
|
|
if (is_string($contents)
|
|
&& (str_contains($contents, 'rawAddressAllowedByPool')
|
|
|| str_contains($contents, 'rawAddressBelongsToPool'))) {
|
|
throw new RuntimeException(
|
|
'Retired duplicate address-policy helper returned: '
|
|
. $file->getFilename()
|
|
);
|
|
}
|
|
}
|
|
|
|
echo "Public-network shared address-policy contracts passed.\n";
|