test(e2e): add admin safe XSS rendering verification in contact submissions
This commit is contained in:
parent
770665cfc0
commit
d62917208f
@ -124,4 +124,110 @@ test.describe('سناریوی مدیریت درخواستهای B2B و فرم
|
||||
|
||||
await expect(page.locator('span').filter({ hasText: 'کلینیک تخصصی دامپزشکی پایتخت' }).first()).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
test('راستیآزمایی رندر امن و عدم اجرای پیلود XSS در پنل ادمین (Admin Safe XSS Rendering)', async ({ page }) => {
|
||||
let adminDialogFired = false;
|
||||
page.on('dialog', () => {
|
||||
adminDialogFired = true;
|
||||
});
|
||||
|
||||
const xssSenderName = '<img src=x onerror=alert("ADMIN_XSS") /> دکتر تست';
|
||||
const xssMessageBody = '<script>alert("ADMIN_SCRIPT")</script> متن پیام تستی با پیلود مخرب';
|
||||
|
||||
await page.route('**/api/auth/admin-login*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: {
|
||||
accessToken: 'mock_e2e_admin_jwt_token',
|
||||
user: { id: 'admin-1', email: 'admin@canina.ir', role: 'SUPER_ADMIN' },
|
||||
},
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/auth/refresh*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: {
|
||||
accessToken: 'mock_e2e_admin_jwt_token',
|
||||
user: { id: 'admin-1', email: 'admin@canina.ir', role: 'SUPER_ADMIN' },
|
||||
},
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/users/profile*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
data: { id: 'admin-1', email: 'admin@canina.ir', role: 'SUPER_ADMIN' },
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/contact/submissions*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
items: [
|
||||
{
|
||||
id: 'contact-xss-1',
|
||||
name: xssSenderName,
|
||||
phone: '09121112233',
|
||||
subject: 'تست امنیت XSS در ادمین',
|
||||
message: xssMessageBody,
|
||||
status: 'PENDING',
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/contact/info*', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify([]),
|
||||
});
|
||||
});
|
||||
|
||||
// 1. لاگین ادمین
|
||||
await page.goto('/login', { waitUntil: 'domcontentloaded' });
|
||||
const emailInput = page.locator('input[type="email"]');
|
||||
const passwordInput = page.locator('input[type="password"]');
|
||||
await expect(emailInput).toBeVisible({ timeout: 10000 });
|
||||
await emailInput.fill('admin@canina.ir');
|
||||
await passwordInput.fill('Admin@123456');
|
||||
|
||||
const submitBtn = page.getByRole('button', { name: /ورود با رمز عبور|ورود به پنل|ورود/i }).first();
|
||||
await submitBtn.click();
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// 2. ورود به صفحه پیامهای تماس در پنل ادمین
|
||||
await page.goto('/contact', { waitUntil: 'domcontentloaded' });
|
||||
await expect(page).toHaveURL(/\/contact/);
|
||||
|
||||
// 3. راستیآزمایی رندر امن نام فرستنده به عنوان متن خام در جدول
|
||||
const senderCell = page.locator('td').filter({ hasText: xssSenderName }).first();
|
||||
await expect(senderCell).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// 4. باز کردن جزئیات پیام و راستیآزمایی نمایش متن پیام
|
||||
const detailsBtn = page.getByRole('button', { name: /مشاهده و پاسخ|مشاهده/i }).first();
|
||||
await expect(detailsBtn).toBeVisible({ timeout: 10000 });
|
||||
await detailsBtn.click();
|
||||
|
||||
// 5. راستیآزمایی قطعی عدم اجرای آلرت جاوااسکریپتی در پنل ادمین
|
||||
expect(adminDialogFired).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user