From ca7cb42f7d4f48b8dff1702de073f0a6124af5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Sat, 28 Feb 2026 16:05:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E7=9A=84=E5=AE=89=E5=85=A8=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加XSS防护测试(脚本注入、img标签、svg标签、javascript伪协议) - 添加SQL注入防护测试(SQL注入、OR注入、注释注入) - 添加路径遍历防护测试(路径遍历、编码路径遍历) - 添加CSRF防护测试(CSRF令牌、令牌验证) - 添加安全头测试(X-Frame-Options、X-Content-Type-Options等) - 添加HTTPS强制跳转测试 - 添加输入验证测试(邮箱格式、手机号格式、必填字段) - 添加敏感数据保护测试(页面源码、控制台日志)~ --- e2e/src/tests/security/security.spec.ts | 336 ++++++++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 e2e/src/tests/security/security.spec.ts diff --git a/e2e/src/tests/security/security.spec.ts b/e2e/src/tests/security/security.spec.ts new file mode 100644 index 0000000..a8a65f9 --- /dev/null +++ b/e2e/src/tests/security/security.spec.ts @@ -0,0 +1,336 @@ +import { test, expect } from '@playwright/test'; +import { ContactPage } from '../../pages/ContactPage'; +import { HomePage } from '../../pages/HomePage'; +import { SECURITY_TEST_CASES } from '../../data/test-data'; + +test.describe('安全测试', () => { + test.describe('XSS防护测试', () => { + let contactPage: ContactPage; + + test.beforeEach(async ({ page }) => { + contactPage = new ContactPage(page); + await contactPage.goto(); + }); + + test('应该防止XSS脚本注入', async () => { + const payloads = SECURITY_TEST_CASES.xssPayloads; + + for (const payload of payloads) { + await contactPage.goto(); + await contactPage.testXSSInjection(payload); + await contactPage.waitForTimeout(2000); + + const pageContent = await contactPage.page.content(); + expect(pageContent).not.toContain('