Files
SupplierSystem/server/tests/opsGuardHardening.test.ts
T
Ubuntu 5fa2bbfd55
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
fix(audit-20261019): T1-T9 审计修复、存储归属与审计日志列宽
- T1 资金/库存/报价/自采 P1(BIZ-1/2/3/4/10/13/14)
- T2 主系统反向事件墓碑/改派/孤儿处理(BIZ-6/8/9)
- T3 选分公司 ticket、trust proxy、角色权限收口(SEC-2/3/4)
- T4 缺列/RLS/tenant 名单/FK/迁移执行器(DATA-1..8)
- T5 401 登出/分页/映射口径/blob/ZIP 中文名(FE-1..4/BIZ-15)
- T6 测试脚本目标守卫/config fail-fast/容器配置(OPS-2..8)
- T7 前后端测试与 lint 门禁清零
- T8 应付卡片按关联订单日(口径 A)
- T9 存储对象全链路归属校验、敏感列禁写、审计 target_id 超长修复
2026-10-19 16:16:51 +08:00

57 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { spawnSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
/**
* O-12.8 / O-12.10(2026-10-19 T6 红队复攻):
* · webpack devServer 不得再用 `allowedHosts:'all'`(DNS rebinding 可借 devServer 代理打内网);
* · 测试守卫不得把本机 3001 当"安全本地"——3001 是**主系统** API,默认拒绝,需 ALLOW_MAIN_SYSTEM=1。
*/
const serverDir = path.resolve(__dirname, '..');
function runGuard(base: string, extraEnv: Record<string, string> = {}) {
const script = `require('./scripts/test-target-guard.js').guardTestTarget({ base: ${JSON.stringify(base)}, explicit: true })`;
return spawnSync(process.execPath, ['-e', script], {
cwd: serverDir,
env: { ...process.env, ...extraEnv },
encoding: 'utf8',
});
}
describe('O-12.10:本机 3001(主系统)默认拒绝', () => {
it('http://127.0.0.1:3001/api 无 ALLOW_MAIN_SYSTEM ⇒ exit 1 且提示主系统', () => {
const result = runGuard('http://127.0.0.1:3001/api', { ALLOW_MAIN_SYSTEM: '' });
expect(result.status).toBe(1);
expect(`${result.stderr}${result.stdout}`).toMatch(/主系统/);
});
it('本系统 3022 ⇒ 放行(exit 0)', () => {
const result = runGuard('http://127.0.0.1:3022/api');
expect(result.status).toBe(0);
expect(result.stdout).toContain('[test] target: http://127.0.0.1:3022/api');
});
it('显式 ALLOW_MAIN_SYSTEM=1 才放行 3001', () => {
const result = runGuard('http://127.0.0.1:3001/api', { ALLOW_MAIN_SYSTEM: '1' });
expect(result.status).toBe(0);
});
it('远程 + ALLOW_REMOTE=1 但非 TTY ⇒ 仍 exit 1', () => {
const result = runGuard('https://www.xdjchuanhui.com/api', { ALLOW_REMOTE: '1' });
expect(result.status).toBe(1);
expect(`${result.stderr}${result.stdout}`).toMatch(/非交互环境/);
});
});
describe('O-12.8:webpack devServer allowedHosts 收紧', () => {
it("allowedHosts 为 'auto',不再是 'all'", () => {
const source = readFileSync(path.join(serverDir, '../webpack.config.js'), 'utf8');
expect(source).toContain("allowedHosts: 'auto'");
expect(source).not.toContain("allowedHosts: 'all'");
// 回环默认与 WEB_HOST 覆盖保持不变
expect(source).toContain("host: process.env.WEB_HOST || '127.0.0.1'");
});
});