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.
67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use App\Services\Cloud\CloudPublicNetworkAddressPolicy;
|
|
|
|
$root = dirname(__DIR__) . '/app/Services/Cloud/';
|
|
$policy = file_get_contents($root . 'CloudPublicNetworkAddressPolicy.php');
|
|
$allocator = file_get_contents(
|
|
$root . 'CloudPublicNetworkAllocationService.php'
|
|
);
|
|
$transition = file_get_contents(
|
|
$root . 'CloudPublicNetworkTransitionWorkflow.php'
|
|
);
|
|
if (!is_string($policy) || !is_string($allocator)
|
|
|| !is_string($transition)) {
|
|
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)) {
|
|
throw new RuntimeException(
|
|
'Pure address policy performs persistence: ' . $forbidden
|
|
);
|
|
}
|
|
}
|
|
if (!str_contains($allocator, 'CloudPublicNetworkAddressPolicy::')
|
|
|| !str_contains($transition, 'CloudPublicNetworkAddressPolicy::')
|
|
|| str_contains($allocator, 'rawAddressAllowedByPool')
|
|
|| str_contains($allocator, 'rawAddressBelongsToPool')
|
|
|| !str_contains($allocator, "'contracts' => \$contracts")
|
|
|| !str_contains($allocator, "'contracts' => \$selectedContracts")) {
|
|
throw new RuntimeException(
|
|
'Allocation and transition do not share the pure address policy.'
|
|
);
|
|
}
|
|
|
|
echo "Public-network shared address-policy contracts passed.\n";
|