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.
virt/web/tests/CloudHostFabricEndpointCont...

135 lines
7.3 KiB
PHP

<?php
// Static boundary contract for the optional WireGuard underlay address.
$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);
}
};
$schema = $read('sql/cloud.sql');
$controller = $read('app/Controllers/CloudAdminController.php');
$engineClient = $read('app/Services/Cloud/CloudEngineClient.php');
$fabricService = $read('app/Services/Cloud/CloudAdminFabricService.php');
$template = $read('resources/views/venix/admin/hosts/index.tpl');
$hostClient = $read('public/cloud/admin.js');
$fabricClient = $read('public/cloud/admin-fabric.js');
$assets = $read('resources/views/venix/layout_assets.tpl');
// Host operational settings have one source of truth in the Engine profile.
// cloud_hosts remains a scheduling/index table and must not create a second,
// independently drifting copy of the endpoint.
$assert(!str_contains($schema, 'fabric_endpoint_ip'),
'cloud_hosts duplicated the Engine-owned Fabric endpoint setting.');
$assert(str_contains($controller, "'fabric_endpoint_ip',")
&& str_contains($controller,
"\$fabricEndpointIp = \$body['fabric_endpoint_ip'] ?? '';")
&& str_contains($controller, 'FILTER_VALIDATE_IP, FILTER_FLAG_IPV4')
&& str_contains($controller,
"\$body['fabric_endpoint_ip'] = \$fabricEndpointIp;")
&& !str_contains($controller,
"unset(\$body['fabric_endpoint_ip'])"),
'Host writes did not validate and forward the optional Engine-owned endpoint.');
$assert(str_contains($engineClient, "'host_fabric_endpoint_invalid'")
&& str_contains($engineClient, "'host_fabric_endpoint_not_local'")
&& str_contains($engineClient, "'fabric_endpoint_not_local'")
&& str_contains($engineClient, "'fabric_endpoint_vpc_conflict'")
&& str_contains($engineClient, "'fabric_region_conflict'")
&& str_contains($engineClient, "'vpc_fabric_endpoint_overlap'")
&& str_contains($engineClient, "'fabric_host_firewall_mode_conflict'")
&& str_contains($engineClient, "'vpc_dataplane_firewall_mode_conflict'"),
'Reviewed endpoint validation failures are not safely mapped for administrators.');
$assert(str_contains($engineClient,
"'firewalld_unsupported_requires_maintenance'")
&& str_contains($engineClient,
"'legacy_firewalld_state_requires_cleanup'")
&& str_contains($engineClient,
"'firewall_transaction_requires_recovery_or_cleanup'")
&& str_contains($engineClient,
"'legacy_firewall_evidence_invalid'")
&& !str_contains($engineClient, "'firewalld_endpoint_zone_unverified'")
&& !str_contains($engineClient,
"'firewalld_endpoint_zone_unsafe_or_drifted'"),
'Retired firewalld compatibility errors remain in the web boundary.');
$assert(str_contains($template, 'id="host-fabric-endpoint-ip"')
&& preg_match('/id="host-fabric-endpoint-ip"[^>]*maxlength="15"/', $template) === 1
&& !preg_match('/id="host-fabric-endpoint-ip"[^>]*\brequired\b/', $template)
&& str_contains($template, '留空时使用 SSH 地址中的 IPv4')
&& str_contains($template, '经公网自动组网')
&& str_contains($template, '内网 IPv4')
&& str_contains($template, '它不是 VM 公网网桥或公网地址池'),
'Host editor did not explain the optional public-now/private-later underlay.');
$assert(str_contains($hostClient,
"'host-fabric-endpoint-ip': h.fabric_endpoint_ip || ''")
&& str_contains($hostClient,
"fabric_endpoint_ip: byId('host-fabric-endpoint-ip').value.trim()"),
'Host editor does not round-trip the optional endpoint through the Engine profile.');
$assert(str_contains($fabricService, 'private const ENDPOINT_SOURCES')
&& str_contains($fabricService, "'configured'")
&& str_contains($fabricService, "'ssh_host_ipv4'")
&& str_contains($fabricService, 'self::ENDPOINT_SOURCES')
&& str_contains($fabricService, "'fabric_endpoint_source_invalid'")
&& str_contains($fabricService, "'fabric_endpoint_vpc_pool_conflict'")
&& str_contains($fabricService, "'fabric_region_conflict'")
&& str_contains($fabricService, 'CloudPrivateCidrAllocator::normalize')
&& str_contains($fabricService, "'firewall_mode'")
&& str_contains($fabricService, "'public_selector'")
&& str_contains($fabricService, "=== 'nftables'")
&& str_contains($fabricService, "=== 'native_nftables'")
&& str_contains($fabricService,
"? 'firewalld_unsupported_requires_maintenance'")
&& str_contains($fabricService,
"'endpoint_source' => \$endpointSource")
&& str_contains($fabricService,
"'endpoint_source' => \$probe['endpoint_source'] ?? null")
&& !str_contains($fabricService, "'underlay_runtime_zone'")
&& !str_contains($fabricService, "'underlay_permanent_zone'")
&& !str_contains($fabricService, "'private_key'")
&& !str_contains($fabricService, "'ssh_command'"),
'Fabric readiness does not expose a bounded effective endpoint source.');
$assert(str_contains($fabricClient, 'function endpointSource(value)')
&& str_contains($fabricClient, "value === 'configured'")
&& str_contains($fabricClient, "value === 'ssh_host_ipv4'")
&& str_contains($fabricClient,
"'来源:' + endpointSource(host.endpoint_source)")
&& str_contains($fabricClient,
"'防火墙模式:' + text(capabilities.firewall_mode)")
&& str_contains($fabricClient,
"'stock nft 服务(仅观测):' + flag(capabilities.nftables_active)")
&& str_contains($fabricClient,
"'stock nft 开机启用(仅观测):' + flag(capabilities.nftables_persistent)")
&& str_contains($fabricClient, 'fabric_endpoint_source_invalid')
&& str_contains($fabricClient, 'fabric_endpoint_vpc_pool_conflict')
&& str_contains($fabricClient, 'fabric_region_conflict')
&& str_contains($fabricClient, 'firewalld_unsupported_requires_maintenance')
&& str_contains($fabricClient, 'nftables_persistence_not_ready')
&& str_contains($fabricClient, 'nftables_persistence_evidence_invalid')
&& str_contains($fabricClient, 'legacy_firewalld_state_requires_cleanup')
&& str_contains($fabricClient,
'firewall_transaction_requires_recovery_or_cleanup')
&& str_contains($fabricClient, 'legacy_firewall_evidence_invalid')
&& !str_contains($fabricClient, 'firewalld_backend_not_nftables')
&& !str_contains($fabricClient, 'firewalld_runtime_nft_backend_unverified')
&& !str_contains($fabricClient, 'firewalld_default_zone_unsafe_or_drifted')
&& !str_contains($fabricClient, 'firewalld_source_zones_present_or_unknown')
&& !str_contains($fabricClient, 'const firewalldNft')
&& !str_contains($fabricClient, '由 firewalld 管理')
&& str_contains($fabricClient, 'firewall_competing_service_unknown')
&& str_contains($fabricClient, 'firewall_manager_conflict'),
'Fabric readiness UI does not distinguish explicit and SSH-IPv4 fallback endpoints.');
$assert(str_contains($assets, "venix_asset_version value='2026101003'"),
'Changed host/Fabric browser assets did not advance the shared cache key.');
echo "Cloud host Fabric endpoint contracts passed.\n";