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

+36 -2
View File
@@ -74,7 +74,7 @@ describe('TermsOfServicePage', () => {
heroTitle: 'CMS 服务条款标题',
heroDescription: 'CMS 服务条款描述',
lastUpdated: '2026-07-17',
content: '<div data-testid="cms-content"><h2>CMS 条款内容</h2></div>',
content: '<div><h2>CMS 条款内容</h2></div>',
},
version: 1,
sortOrder: 0,
@@ -90,7 +90,8 @@ describe('TermsOfServicePage', () => {
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('CMS 服务条款标题');
expect(screen.getByText('CMS 服务条款描述')).toBeInTheDocument();
expect(screen.getByTestId('cms-content')).toBeInTheDocument();
// 净化器按白名单丢弃 data-testid,故以内容而非测试钩子断言 CMS 通路生效
expect(screen.getByRole('heading', { level: 2 })).toHaveTextContent('CMS 条款内容');
});
it('should fall back to inline content when CMS is unavailable', async () => {
@@ -103,4 +104,37 @@ describe('TermsOfServicePage', () => {
expect(screen.getByText('引言')).toBeInTheDocument();
});
});
describe('存储型 XSS 净化(验收 A-3)', () => {
function mockCmsContent(content: string) {
mockedGetPublishedItems.mockResolvedValue([
{
data: { pageType: 'terms', content },
},
] as unknown as Awaited<ReturnType<typeof getPublishedItems>>);
}
it('CMS 载荷中的脚本与事件属性不出现在 DOM', async () => {
mockCmsContent(
'<p>合法条款段落</p>' +
'<script>alert("xss")</script>' +
'<img src="x" onerror="alert("xss-img")">' +
'<a href="javascript:alert("xss-href")">点我</a>' +
'<iframe src="https://evil.example.com"></iframe>'
);
const { container } = render(await TermsOfServicePage());
const html = container.innerHTML;
expect(html).not.toContain('<script');
expect(html).not.toMatch(/onerror|javascript:/);
expect(html).not.toContain('<iframe');
expect(html).toContain('合法条款段落');
});
it('净化后仍渲染管理员撰写的正常富文本', async () => {
mockCmsContent('<h2>第三条 服务内容</h2><p>我们提供 <strong>SaaS</strong> 服务。</p>');
const { container } = render(await TermsOfServicePage());
expect(container).toHaveTextContent('第三条 服务内容');
expect(container.querySelector('strong')?.textContent).toBe('SaaS');
});
});
});
+3 -2
View File
@@ -1,5 +1,6 @@
import { Metadata } from 'next';
import { getPublishedItems } from '@/lib/cms/data-server';
import { sanitizeRichText } from '@/lib/sanitize';
import { COMPANY_INFO } from '@/lib/constants';
export const metadata: Metadata = {
@@ -193,7 +194,7 @@ export default async function TermsOfServicePage() {
return (
<div className="min-h-screen bg-[var(--color-bg-primary)]">
<div className="bg-gradient-to-br from-[var(--color-brand)] via-[var(--color-brand)]/80 to-[var(--color-brand-section)] py-20">
<div className="bg-gradient-to-br from-[var(--color-brand)] via-brand/80 to-[var(--color-brand-section)] py-20">
<div className="container-wide">
<h1 className="text-4xl md:text-5xl font-bold text-white mb-4">
{heroTitle}
@@ -209,7 +210,7 @@ export default async function TermsOfServicePage() {
{cmsContent ? (
<div
className="prose prose-lg max-w-none"
dangerouslySetInnerHTML={{ __html: cmsContent }}
dangerouslySetInnerHTML={{ __html: sanitizeRichText(cmsContent) }}
/>
) : (
<TermsContent />