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.
83 lines
4.3 KiB
PHP
83 lines
4.3 KiB
PHP
<?php
|
|
|
|
// Static contract coverage for the administrator Fabric boundary. This test
|
|
// deliberately does not boot the application or call a host: the engine is
|
|
// reached only through the PHP HMAC client at runtime.
|
|
$root = dirname(__DIR__);
|
|
$read = static function (string $relative) use ($root): string {
|
|
$value = file_get_contents($root . '/' . $relative);
|
|
if (!is_string($value)) {
|
|
throw new RuntimeException('Unable to read ' . $relative);
|
|
}
|
|
return $value;
|
|
};
|
|
$assert = static function ($condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$routes = $read('config/routes.php');
|
|
$cloudRoutes = $read('config/routes_cloud.php');
|
|
$middleware = $read('app/Middleware/CloudApi.php');
|
|
$client = $read('app/Services/Cloud/CloudEngineClient.php');
|
|
$controller = $read('app/Controllers/CloudAdminFabricController.php');
|
|
$service = $read('app/Services/Cloud/CloudAdminFabricService.php');
|
|
$page = $read('app/Controllers/Admin/CloudPageController.php');
|
|
$template = $read('resources/views/venix/admin/cloud/fabric.tpl');
|
|
$script = $read('public/cloud/admin-fabric.js');
|
|
$header = $read('resources/views/venix/admin/static_header.tpl');
|
|
|
|
$assert(str_contains($routes, "\$this->get('/fabric', 'App\\Controllers\\Admin\\CloudPageController:fabric')")
|
|
&& str_contains($header, 'href="/admin/fabric"')
|
|
&& str_contains($page, "fetch('admin/cloud/fabric.tpl')"),
|
|
'Fabric administrator page route, navigation or renderer is missing.');
|
|
$assert(str_contains($cloudRoutes, "\$this->post('/admin/fabric/apply'")
|
|
&& str_contains($cloudRoutes, "\$this->get('/admin/fabric'")
|
|
&& str_contains($cloudRoutes, "\$this->get('/admin/fabric/{fabric_id:")
|
|
&& str_contains($cloudRoutes, "\$this->post('/admin/fabric/{fabric_id:")
|
|
&& strpos($cloudRoutes, "\$this->post('/admin/fabric/apply'") < strpos($cloudRoutes, "\$this->get('/admin/fabric/{fabric_id:"),
|
|
'Fabric API routes or static apply ordering is incomplete.');
|
|
$assert(str_contains($middleware, "/api/v1/admin/fabric(?:/|$)")
|
|
&& str_contains($client, "function fabricStatuses")
|
|
&& str_contains($client, "function fabricApply")
|
|
&& str_contains($client, "function fabricReconcile")
|
|
&& str_contains($client, "safeFabricErrorMessage"),
|
|
'Fabric API must use the database-only PHP boundary and bounded engine client.');
|
|
$assert(str_contains($controller, 'CloudAccess::manage')
|
|
&& str_contains($controller, 'CloudInput::object')
|
|
&& str_contains($controller, "body !== '{}'"),
|
|
'Fabric controller lost the super-admin, typed-body or empty reconcile guards.');
|
|
$assert(str_contains($service, 'CloudInput::only')
|
|
&& str_contains($service, "'schema_version', 'fabric_id', 'region', 'overlay_cidr'")
|
|
&& str_contains($service, "'revision', 'listen_port', 'nodes'")
|
|
&& str_contains($service, "'listen_port' => self::port(")
|
|
&& str_contains($service, 'next_stage_allowed')
|
|
&& str_contains($service, 'observed_plan_digest')
|
|
&& str_contains($service, 'handshakes')
|
|
&& str_contains($service, 'host_name'),
|
|
'Fabric service must project typed plans, host capabilities and desired/observed evidence.');
|
|
$assert(!str_contains($service, "'private_key'")
|
|
&& !str_contains($service, "'ssh_command'")
|
|
&& !str_contains($service, "'raw_output'"),
|
|
'Fabric admin projection must not accept or expose private credentials or raw commands.');
|
|
$assert(str_contains($template, 'Fabric 拓扑')
|
|
&& str_contains($template, '参与宿主机与能力探测')
|
|
&& str_contains($template, 'Peer')
|
|
&& str_contains($template, 'Route')
|
|
&& str_contains($template, 'Handshake')
|
|
&& str_contains($template, 'desired / observed')
|
|
&& str_contains($template, 'apply')
|
|
&& str_contains($template, 'reconcile')
|
|
&& str_contains($template, '地区到 Fabric 映射'),
|
|
'Fabric page is missing one of the required topology, evidence or mapping sections.');
|
|
$assert(str_contains($script, '/api/v1/admin/fabric')
|
|
&& str_contains($script, 'X-CSRF-Token')
|
|
&& str_contains($script, 'fabric.listen_port || fabric.nodes[0].listen_port')
|
|
&& str_contains($script, 'next_stage_allowed')
|
|
&& str_contains($script, 'textContent')
|
|
&& !str_contains($script, '/internal/v1/'),
|
|
'Fabric browser module must use the PHP API, CSRF and safe DOM rendering.');
|
|
|
|
echo "Administrator Fabric page and API boundary contracts passed.\n";
|