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('