test(docs): 完成管理员VPC控制面验收

go
codex 3 weeks ago
parent 63098f3a6e
commit 427fef29cc

@ -147,4 +147,6 @@ jq empty deploy/*.json.example
VPC 还必须在至少两台同地区非生产宿主机上保持 firewalld 运行并验收:专用 guest/transport zone 与双向 policy 的 runtime、permanent 定义完全一致;VPC bridge 和所选传输接口只绑定到各自专用 zone;同一 VPC 的同机与跨宿主机实例可进行任意 IP 协议双向通信;伪造源地址、跨 VPC、VPC 到其他宿主机出口以及 VPC 到宿主机 INPUT 仍被拒绝。测试期间不得通过停用 firewalld、加入 `trusted`、打开全局 forward 或添加宽泛 direct/rich rule 获得假通过。删除最后一个本地 VPC 投影后,Agent 必须只解除受管接口绑定,不删除或覆盖宿主机其他 firewalld 配置;永久配置应能在后续 firewalld reload 后恢复同一边界。
管理员 VPC 控制面还要分别在桌面和窄屏视口验收概览、全站网络、地址池抽屉和详情抽屉。首屏必须由服务端直接提供摘要、地区就绪状态和网络目录,不能用全页等待替代;浏览器只在后台重新核对一次。地区“可创建”必须与用户创建接口复用同一个资格判定。地址池创建使用稳定 `request_key`,编辑使用 `expected_revision`,已有占用时 CIDR 与分配前缀保持锁定。VPC 详情只展示实例端口、宿主机投影、批次和原任务链接;失败或未知效果只能进入原 operation 的任务详情核对,不能在控制面直接重发、强制收敛或解除资源栅栏。只读管理员不得获得地址池 mutation 控件。
未完成真实宿主机验收时只能报告“静态与本机测试通过”,不能宣称生产发布完成。

@ -0,0 +1,154 @@
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
set_error_handler(static function (int $severity, string $message,
string $file, int $line): bool {
if ((error_reporting() & $severity)
&& ($severity & (E_WARNING | E_USER_WARNING | E_DEPRECATED))) {
throw new ErrorException($message, 0, $severity, $file, $line);
}
return false;
});
$now = time();
$network = [
'id' => 31, 'vpc_key' => str_repeat('a', 32), 'name' => '生产私网',
'user_id' => 42, 'owner_name' => '演示客户',
'owner_email' => 'd***@example.test',
'owner_url' => '/admin/user/42/edit', 'region_id' => 7,
'region_name' => '香港', 'region_code' => 'hkg',
'cidr' => '10.64.0.0/24', 'gateway' => '10.64.0.1',
'desired_revision' => 8, 'state' => 'degraded',
'raw_state' => 'active',
'display' => ['label' => '需要处理', 'tone' => 'danger'],
'port_count' => 3, 'host_summary' => ['total' => 2, 'ready' => 1],
'active_batch' => ['job_id' => 91], 'updated_at' => $now - 30,
];
$page = [
'overview' => [
'feature' => ['enabled' => true, 'settings_url' => '/admin/config'],
'summary' => ['total' => 4, 'active' => 3, 'changing' => 0,
'degraded' => 1, 'ports' => 9, 'active_batches' => 1],
'regions' => [[
'id' => 7, 'code' => 'hkg', 'name' => '香港',
'country_code' => 'HK', 'status' => 'active',
'pools_total' => 1, 'pools_active' => 1, 'capacity' => 256,
'used' => 4, 'available' => 252, 'hosts_total' => 2,
'hosts_schedulable' => 2, 'hosts_ready' => 2,
'ready' => true, 'blockers' => [],
]],
'attention' => [$network], 'updated_at' => $now,
],
'networks' => [
'items' => [$network],
'filters' => ['q' => '', 'state' => '', 'region_id' => 0,
'page' => 1, 'per_page' => 20],
'pagination' => ['page' => 1, 'per_page' => 20, 'total' => 1,
'total_pages' => 1, 'from' => 1, 'to' => 1],
],
'pools' => [
'feature_enabled' => true,
'regions' => [['id' => 7, 'name' => '香港', 'code' => 'hkg']],
'items' => [[
'id' => 12, 'pool_key' => str_repeat('b', 32),
'region_id' => 7, 'region_name' => '香港',
'name' => '香港私网池', 'cidr' => '10.64.0.0/16',
'allocation_prefix' => 24, 'state' => 'active',
'revision' => 2, 'capacity' => 256, 'used' => 4,
'available' => 252, 'address_locked' => true,
]],
],
];
$smarty = new Smarty();
$compileDir = sys_get_temp_dir() . '/admin-vpc-view-'
. bin2hex(random_bytes(6));
mkdir($compileDir);
$smarty->setCompileDir($compileDir);
$smarty->setTemplateDir(dirname(__DIR__) . '/resources/views/venix');
$smarty->assign('config', ['appName' => 'Venix Test']);
$smarty->assign('cdn', '');
$smarty->assign('user', (object) ['isLogin' => false]);
$smarty->assign('admin_csrf_token', 'fixture-not-a-real-token');
$render = static function (?array $payload, string $error = '',
bool $canManage = true) use ($smarty): string {
$smarty->assign('admin_can_manage', $canManage);
$smarty->assign('admin_vpc_page', $payload);
$smarty->assign('admin_vpc_error', $error);
$smarty->assign('admin_vpc_view', 'overview');
$smarty->assign('admin_vpc_bootstrap_json', json_encode($payload,
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
| JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE));
return $smarty->fetch('admin/cloud/vpc.tpl');
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$html = $render($page);
if (in_array('--fixture', $argv ?? [], true)) {
echo $html;
exit;
}
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML('<?xml encoding="UTF-8">' . $html);
$xpath = new DOMXPath($dom);
$assert($xpath->query('//*[@data-admin-vpc]')->length === 1
&& $xpath->query('//*[@role="tab"]')->length === 3
&& $xpath->query('//*[contains(@class,"admin-vpc-summary-card")]')
->length === 6,
'The administrator VPC workspace did not render its primary navigation.');
$assert($xpath->query('//*[@id="admin-vpc-regions"]//article')->length === 1
&& $xpath->query('//*[@id="admin-vpc-attention-body"]/tr')->length === 1
&& $xpath->query('//*[@id="admin-vpc-network-body"]/tr')->length === 1,
'VPC readiness and network data must be useful before JavaScript runs.');
$assert(str_contains($dom->textContent, '生产私网')
&& str_contains($dom->textContent, '10.64.0.0/24')
&& str_contains($dom->textContent, 'VPC 控制面已读取')
&& $xpath->query('//*[@data-vpc-detail="31"]')->length === 1,
'The first paint omitted the VPC identity, CIDR or detail entry point.');
$readOnly = $render($page, '', false);
$dom->loadHTML('<?xml encoding="UTF-8">' . $readOnly);
$xpath = new DOMXPath($dom);
$assert($xpath->query('//*[@id="admin-vpc-pool-new" and @disabled]')->length
=== 1
&& $xpath->query('//*[@id="admin-vpc-pool-form"]//*[@disabled]')->length
>= 6,
'Read-only administrators received an enabled address-pool mutation.');
$unsafe = $page;
$unsafe['networks']['items'][0]['name'] =
'</script><img src=x onerror=alert(1)>';
$unsafe['overview']['attention'][0]['owner_name'] =
'<script>window.bad=1</script>';
$unsafe['overview']['regions'][0]['name'] = '" onmouseover="alert(2)';
$unsafeHtml = $render($unsafe);
$dom->loadHTML('<?xml encoding="UTF-8">' . $unsafeHtml);
$xpath = new DOMXPath($dom);
$assert($xpath->query('//*[@onerror or @onmouseover]')->length === 0
&& !str_contains($unsafeHtml, '<script>window.bad=1</script>')
&& str_contains($dom->textContent,
'</script><img src=x onerror=alert(1)>'),
'Untrusted VPC names became executable markup.');
$failed = $render(null, 'VPC 控制面暂不可用,请重试');
$assert(str_contains($failed, 'VPC 控制面暂不可用,请重试')
&& !str_contains($failed, '生产私网'),
'An unavailable control plane was disguised as a successful response.');
$javascript = file_get_contents(dirname(__DIR__)
. '/public/cloud/admin-vpc.js');
$assert(!str_contains($javascript, 'setInterval(')
&& str_contains($javascript, 'renderDetail(payload)')
&& str_contains($javascript, 'pool.address_locked')
&& str_contains($javascript, 'focusJob?.url'),
'The browser UI lost its bounded refresh, locked-pool or exact-task contract.');
echo "Administrator VPC first paint, permissions and escaping passed.\n";
Loading…
Cancel
Save