- 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 超长修复
41 lines
2.9 KiB
TypeScript
41 lines
2.9 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
||
import { join } from 'node:path';
|
||
import { describe, expect, it } from 'vitest';
|
||
import { assertStorageKeyOwned, buildSignedStoragePathForCtx } from '../src/services/storageObjectOwnership';
|
||
import { mapCustomerInvoiceListRow } from '../src/services/customerInvoiceWriteService';
|
||
import { mapSupplierInvoiceListRow } from '../src/services/supplierInvoiceWriteService';
|
||
|
||
/** T9 全链路归属:前缀授权、无 branchCode fail-closed、list mint 不跨租户、写入口有断言。 */
|
||
describe('T9 SEC-5 全链路归属', () => {
|
||
it('前缀 key:同分支通过、跨分支 403、无 branchCode 403、super_admin 放行', async () => {
|
||
await expect(assertStorageKeyOwned('invoices', 'BR001/supplier-invoices/a.pdf', { branchCode: 'BR001' })).resolves.toBe('BR001/supplier-invoices/a.pdf');
|
||
await expect(assertStorageKeyOwned('invoices', 'BR002/supplier-invoices/a.pdf', { branchCode: 'BR001' })).rejects.toMatchObject({ status: 403 });
|
||
await expect(assertStorageKeyOwned('invoices', 'BR001/a.pdf', { branchCode: null })).rejects.toMatchObject({ status: 403 });
|
||
await expect(assertStorageKeyOwned('invoices', 'BR002/a.pdf', { branchCode: 'BR001', isSuperAdmin: true })).resolves.toBe('BR002/a.pdf');
|
||
await expect(assertStorageKeyOwned('invoices', '../etc/passwd', { branchCode: 'BR001' })).rejects.toMatchObject({ status: 403 });
|
||
});
|
||
|
||
it('B1/B2:archive/<branch>/ 签名归属(同分支 200、跨分支 403)', () => {
|
||
expect(buildSignedStoragePathForCtx({ branchCode: 'BR001' }, 'invoices', 'archive/BR001/2026-10.tar.gz')).toContain('/api/storage/invoices/public/');
|
||
expect(() => buildSignedStoragePathForCtx({ branchCode: 'BR001' }, 'invoices', 'archive/BR002/2026-10.tar.gz')).toThrow();
|
||
expect(() => buildSignedStoragePathForCtx({ branchCode: 'BR001' }, 'invoices', 'BR002/free-cost/x.jpg')).toThrow();
|
||
expect(() => buildSignedStoragePathForCtx({ branchCode: null }, 'invoices', 'BR001/x.jpg')).toThrow();
|
||
});
|
||
|
||
it('list mint 只为本分支 key 签 URL(跨租户 forged invoice_url 不返回签名)', () => {
|
||
const base = { id: '1', invoice_url: 'BR002/supplier-invoices/a.pdf' };
|
||
expect(mapSupplierInvoiceListRow(base, 'BR001').signed_url).toBeNull();
|
||
expect(mapCustomerInvoiceListRow({ ...base, invoice_url: 'BR001/a.pdf' }, 'BR001').signed_url).not.toBeNull();
|
||
});
|
||
|
||
it('写入口/读图入口均有归属断言(源码契约)', () => {
|
||
const finance = readFileSync(join(__dirname, '../src/modules/workflow/routes/financeRoutes.ts'), 'utf8');
|
||
expect(finance).toContain('assertOwnedStoragePath(ctx');
|
||
expect(finance).toContain('assertOwnedStoragePaths(ctx');
|
||
expect(finance).toContain("assertOwnedStoragePath(ctx, 'invoices', req.body?.invoice_url)");
|
||
expect(finance).toContain('req.body?.voucher_urls');
|
||
const fn = readFileSync(join(__dirname, '../src/routes/functions.ts'), 'utf8');
|
||
expect(fn).toContain("assertStorageKeyOwned('invoices', storedPath");
|
||
});
|
||
});
|