fix(qa): 第五轮系统性质量保障缺陷修复 + 单元/集成测试

安全/鉴权:登出清服务端 httpOnly 令牌、登录 IP 限流前置 bcrypt、停用账号
令牌在 6 个内联 role handler 失效、admin/items 存在性 oracle 认证前置、
同意偏好 sanitize fail-closed、api-crypto 按 HTTP 方法判体。

CMS:workflow 状态更新+审计收进交互式 $transaction(失败即回滚)、编辑器
richtext 走 textarea 防换行损毁、array/object 子字段按作用域读写防污染、
about/contact/erp-upgrade 补 ISR revalidate 与路由映射。

UI/a11y:AnimatedCounter 入视口前显起点、CLS 累计上报、MetricCard 动画入
effect 并卸载取消 rAF、后台状态四态映射/搜索防抖+序号守卫/媒体单 input/
吞错改横幅/表单 label-aria 关联。

新增对应判别性单测与 pagination/rate-limit/client-ip/sanitize/validate-content-data
等模块及 tests-integration 真库集成层。
This commit is contained in:
zhangxiang committed 2026-09-28 10:48:07 +08:00
1 parent 040951c0a3
commit a366bd1400
224 files changed
+8938 -5579

No files matched your search

+56
View File
@@ -149,6 +149,62 @@ describe('AdminApiClient', () => {
await expect(adminApi.request('/api/admin/models')).rejects.toThrow('模型不存在');
});
// L-1:withCrypto 会把 4xx/5xx 也加密成 { data: <encrypted> } + X-Encrypted: true,
// 解密成功后的错误信封必须按 res.ok 拒绝,且优先透出服务端自己的错误文案。
it('rejects encrypted error envelope (403) with the server message', async () => {
mockStorage['novalon_admin_token'] = 'test-token';
mockDecrypt.mockResolvedValue(JSON.stringify({ error: '无权修改该内容' }));
mockFetch.mockResolvedValueOnce(
new Response(JSON.stringify({ data: 'encrypted-error' }), {
status: 403,
headers: { 'Content-Type': 'application/json', 'X-Encrypted': 'true' },
}),
);
await expect(adminApi.updateItem('item-1', { title: 'x' })).rejects.toThrow('无权修改该内容');
expect(mockDecrypt).toHaveBeenCalledWith('encrypted-error');
});
it('rejects encrypted error envelope (400) preferring message field', async () => {
mockStorage['novalon_admin_token'] = 'test-token';
mockEncrypt.mockResolvedValue('encrypted-data');
mockDecrypt.mockResolvedValue(JSON.stringify({ message: '字段校验失败' }));
mockFetch.mockResolvedValueOnce(
new Response(JSON.stringify({ data: 'encrypted-error' }), {
status: 400,
headers: { 'Content-Type': 'application/json', 'X-Encrypted': 'true' },
}),
);
await expect(adminApi.createItem({ title: 'x' })).rejects.toThrow('字段校验失败');
});
it('falls back to status when decrypted error envelope carries no message', async () => {
mockStorage['novalon_admin_token'] = 'test-token';
mockDecrypt.mockResolvedValue(JSON.stringify({ detail: 'opaque' }));
mockFetch.mockResolvedValueOnce(
new Response(JSON.stringify({ data: 'encrypted-error' }), {
status: 403,
headers: { 'Content-Type': 'application/json', 'X-Encrypted': 'true' },
}),
);
await expect(adminApi.getItems({ page: 1 })).rejects.toThrow('请求失败 (403)');
});
it('resolves encrypted success response unchanged', async () => {
mockStorage['novalon_admin_token'] = 'test-token';
mockDecrypt.mockResolvedValue(JSON.stringify({ items: [{ id: 'a' }], total: 1 }));
mockFetch.mockResolvedValueOnce(
new Response(JSON.stringify({ data: 'encrypted-ok' }), {
status: 200,
headers: { 'Content-Type': 'application/json', 'X-Encrypted': 'true' },
}),
);
await expect(adminApi.getItems({ page: 1 })).resolves.toEqual({ items: [{ id: 'a' }], total: 1 });
});
});
// ============ 公开 API 方法测试 ============