Test Types
Security Tests
Automated security scanning for vulnerabilities like SQL injection, XSS, and authentication bypass.
Security Vulnerabilities Detected
SQL Injection
Malicious SQL in user inputs
XSS (Cross-Site Scripting)
Script injection in rendered content
Authentication Bypass
Unauthorized access to protected routes
CSRF
Cross-site request forgery
Example Security Test
test_sql_injection.spec.ts
1import { test, expect } from '@playwright/test';2 3test.describe('SQL Injection Tests', () => {4 const sqlPayloads = [5 "' OR '1'='1",6 "'; DROP TABLE users; --",7 "' UNION SELECT * FROM users --",8 "1; SELECT * FROM information_schema.tables",9 ];10 11 for (const payload of sqlPayloads) {12 test(`should reject SQL injection: ${payload.slice(0, 20)}...`, async ({ page }) => {13 await page.goto('/search');14 15 // Attempt SQL injection in search field16 await page.fill('[name="query"]', payload);17 await page.click('[type="submit"]');18 19 // Should not expose database errors20 const content = await page.content();21 expect(content).not.toContain('SQL syntax');22 expect(content).not.toContain('mysql_');23 expect(content).not.toContain('pg_');24 25 // Should sanitize or reject the input26 await expect(page.locator('.error')).not.toContainText('database');27 });28 }29});XSS Test Example
test_xss_prevention.spec.ts
1import { test, expect } from '@playwright/test';2 3test.describe('XSS Prevention Tests', () => {4 const xssPayloads = [5 '<script>alert("XSS")</script>',6 '<img src=x onerror=alert("XSS")>',7 '"><script>alert("XSS")</script>',8 "javascript:alert('XSS')",9 ];10 11 test('should sanitize user input in comments', async ({ page }) => {12 await page.goto('/comments');13 14 for (const payload of xssPayloads) {15 await page.fill('[name="comment"]', payload);16 await page.click('[type="submit"]');17 18 // Script should not execute19 const alertTriggered = await page.evaluate(() => {20 return (window as any).__xssTriggered || false;21 });22 expect(alertTriggered).toBe(false);23 24 // Content should be escaped25 const html = await page.content();26 expect(html).not.toContain('<script>alert');27 }28 });29});Generate Security Tests
bash
1curl -X POST http://localhost:3000/api/brain/generate-test \2 -H "Content-Type: application/json" \3 -d '{4 "type": "security",5 "target": "Login form SQL injection and XSS vulnerabilities"6 }'