Files
Genarrative/scripts/check-pingora-canary-live-guard.mjs
T
kdletters e9c3dc1120 退役旧创作模板业务
保留 SpacetimeDB 历史表、迁移白名单与旧业务源码
切换前端 active 入口并解除旧创作页面和路由编译链
移除旧后端路由、worker 与纯业务 crate 依赖
收敛 SpacetimeDB 模块为历史数据壳
同步 Nginx、Pingora、验证门禁与架构文档
2026-07-17 22:07:52 +08:00

73 lines
1.8 KiB
JavaScript

#!/usr/bin/env node
import { spawnSync } from 'node:child_process';
const CANARY_LIVE_SCRIPT = 'scripts/check-pingora-canary-live.mjs';
const failures = [];
main();
if (failures.length > 0) {
console.error('[check:pingora-canary-live-guard] FAILED');
for (const failure of failures) {
console.error(`- ${failure}`);
}
process.exit(1);
}
console.log('[check:pingora-canary-live-guard] OK');
function main() {
assertRejectsControlCharacter('--base-url', [
'--base-url',
'http://127.0.0.1\n--fake-flag',
]);
assertRejectsControlCharacter('--prefix', [
'--base-url',
'http://127.0.0.1',
'--prefix',
'/__genarrative_pingora_canary\nX-Injected: yes',
]);
assertRejectsControlCharacter('--host', [
'--base-url',
'http://127.0.0.1',
'--host',
'example.com\nX-Injected: yes',
]);
assertRejectsControlCharacter('--path', [
'--base-url',
'http://127.0.0.1',
'--path',
'/api/assets/history\nX-Injected: yes',
]);
assertRejectsControlCharacter('--timeout-ms', [
'--base-url',
'http://127.0.0.1',
'--timeout-ms',
'5000\n1',
]);
}
function assertRejectsControlCharacter(label, args) {
const result = spawnSync('node', [CANARY_LIVE_SCRIPT, ...args], {
cwd: process.cwd(),
encoding: 'utf8',
env: process.env,
});
if ((result.status ?? 0) === 0) {
failures.push(`${label} 带控制字符时必须在发起 canary 请求前失败。`);
return;
}
assertIncludes(
`${result.stdout}\n${result.stderr}`,
`${label} 不能包含换行或 NUL 字符`,
`${label} 带控制字符时必须给出明确错误。`,
);
}
function assertIncludes(value, expected, reason) {
if (!String(value).includes(expected)) {
failures.push(`${reason} 缺少: ${expected}`);
}
}