import { test, expect } from '@playwright/test' test.describe('安全验证 E2E 测试', () => { test.describe('TC-SEC-E2E-001: XSS 注入防护', () => { test('搜索关键词中的 XSS 脚本不应执行', async ({ page }) => { // 导航到黄历搜索页面,携带 XSS 关键词 const xssPayload = encodeURIComponent('') await page.goto(`/#/pages/almanac-search/index?keyword=${xssPayload}`) await page.waitForLoadState('networkidle') await page.waitForTimeout(1000) // 验证页面没有因为 XSS 而崩溃 const pageContent = page.locator('.page-content') await expect(pageContent).toBeVisible() // 验证没有 alert 弹窗(通过页面未崩溃间接验证) // 验证搜索输入框的值被正确转义显示 const searchInput = page.locator('input, textarea, [contenteditable]').first() const isVisible = await searchInput.isVisible().catch(() => false) if (isVisible) { const value = await searchInput.inputValue().catch(() => '') expect(value).not.toContain('