422 lines
12 KiB
JavaScript
422 lines
12 KiB
JavaScript
|
|
const { test, expect } = require('@playwright/test');
|
|
require('dotenv').config();
|
|
const { login } = require('../fixtures/auth');
|
|
const { expectNoBackendError, readBody, blockedOrNotFound } = require('../fixtures/v204-helpers');
|
|
const { expectBlockedOrSafe } = require('../fixtures/assertions');
|
|
|
|
async function safeGoto(page, route) {
|
|
const resp = await page.goto(route).catch(() => null);
|
|
await page.waitForLoadState('domcontentloaded').catch(() => {});
|
|
return resp;
|
|
}
|
|
|
|
async function expectRouteAvailable(page, resp) {
|
|
await expectNoBackendError(page);
|
|
if (resp) {
|
|
expect(resp.status(), `Expected route to exist but got ${resp.status()} at ${page.url()}`).not.toBe(404);
|
|
expect(resp.status()).toBeLessThan(500);
|
|
}
|
|
}
|
|
|
|
async function expectNoSecrets(page) {
|
|
const body = await readBody(page);
|
|
expect(body).not.toMatch(/Password@123|Pass@123|smtp_password|IMAP_PASSWORD|SMTP_PASSWORD|otp\s*[:=]\s*\d{4,8}|reset_token|access_token|refresh_token/i);
|
|
}
|
|
|
|
async function expectPublicNoSensitive(page) {
|
|
await expectNoBackendError(page);
|
|
const body = await readBody(page);
|
|
expect(body).not.toMatch(/tenant_id|branch_id|internal note|audit log|smtp|password|secret|token/i);
|
|
}
|
|
|
|
async function apiCall(request, method, route) {
|
|
const url = `${process.env.BASE_URL}${route}`;
|
|
const opts = { data: { csrf_token: '', test_payload: 'uat-vapt' }, headers: { 'Content-Type': 'application/json' } };
|
|
if (method === 'GET') return await request.get(url).catch(() => null);
|
|
if (method === 'POST') return await request.post(url, opts).catch(() => null);
|
|
if (method === 'PUT') return await request.put(url, opts).catch(() => null);
|
|
if (method === 'DELETE') return await request.delete(url).catch(() => null);
|
|
if (method === 'OPTIONS') return await request.fetch(url, { method: 'OPTIONS' }).catch(() => null);
|
|
return await request.fetch(url, { method }).catch(() => null);
|
|
}
|
|
|
|
async function expectApiSafe(resp) {
|
|
expect(resp, 'API response should be available').toBeTruthy();
|
|
expect(resp.status()).toBeLessThan(500);
|
|
const text = await resp.text().catch(() => '');
|
|
expect(text).not.toMatch(/Traceback|Exception in ASGI application|OperationalError|ProgrammingError|AttributeError|UndefinedError|Password@123|Pass@123/i);
|
|
}
|
|
|
|
|
|
const cases = [
|
|
{
|
|
"variantId": "V251-EMAIL-001",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email settings page loads",
|
|
"type": "UAT",
|
|
"route": "/email/settings",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-002",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email test settings endpoint visible/safe",
|
|
"type": "UAT",
|
|
"route": "/email/settings/test",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-003",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email logs page loads",
|
|
"type": "UAT",
|
|
"route": "/email/logs",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-004",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email queue page loads",
|
|
"type": "UAT",
|
|
"route": "/email/queue",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-005",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email inbox page loads",
|
|
"type": "UAT",
|
|
"route": "/email/inbox",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-006",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email templates page loads",
|
|
"type": "UAT",
|
|
"route": "/email/templates",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-007",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email template detail invalid ID safe",
|
|
"type": "UAT",
|
|
"route": "/email/templates/999999",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-008",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email inbox invalid message detail safe",
|
|
"type": "UAT",
|
|
"route": "/email/inbox/999999",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-009",
|
|
"module": "Email Integration",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "SMTP settings CSRF-less save rejected",
|
|
"type": "VAPT",
|
|
"route": "/email/settings",
|
|
"_kind": "post",
|
|
"_method": "POST",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-010",
|
|
"module": "Email Integration",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "SMTP test CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/email/settings/test",
|
|
"_kind": "post",
|
|
"_method": "POST",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-011",
|
|
"module": "Email Integration",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Email queue process CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/email/queue/process",
|
|
"_kind": "post",
|
|
"_method": "POST",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-012",
|
|
"module": "Email Integration",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Inbox fetch CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/email/inbox/fetch",
|
|
"_kind": "post",
|
|
"_method": "POST",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-013",
|
|
"module": "Email Integration",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Inbox map-all CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/email/inbox/map-all",
|
|
"_kind": "post",
|
|
"_method": "POST",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-014",
|
|
"module": "Email Integration",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Inbox message map CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/email/inbox/999999/map",
|
|
"_kind": "post",
|
|
"_method": "POST",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-015",
|
|
"module": "Email Integration",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Email template save CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/email/templates",
|
|
"_kind": "post",
|
|
"_method": "POST",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-016",
|
|
"module": "Email Integration",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Email template update invalid ID CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/email/templates/999999",
|
|
"_kind": "post",
|
|
"_method": "POST",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-017",
|
|
"module": "Email Integration",
|
|
"role": "Staff",
|
|
"scenario": "Staff cannot access email settings",
|
|
"type": "VAPT",
|
|
"route": "/email/settings",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Staff"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-018",
|
|
"module": "Email Integration",
|
|
"role": "Client",
|
|
"scenario": "Client cannot access email logs",
|
|
"type": "VAPT",
|
|
"route": "/email/logs",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Client"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-019",
|
|
"module": "Email Integration",
|
|
"role": "Consultant",
|
|
"scenario": "Consultant cannot access email inbox",
|
|
"type": "VAPT",
|
|
"route": "/email/inbox",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Consultant"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-020",
|
|
"module": "Email Integration",
|
|
"role": "Partner",
|
|
"scenario": "Partner email queue access is blocked or safe",
|
|
"type": "VAPT",
|
|
"route": "/email/queue",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Partner"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-021",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Invalid email attachment download does not crash",
|
|
"type": "UAT",
|
|
"route": "/email/inbox/999999/attachments/999999/download",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-022",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email logs do not expose SMTP password",
|
|
"type": "VAPT",
|
|
"route": "/email/logs",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-023",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email settings page does not render SMTP password in clear text",
|
|
"type": "VAPT",
|
|
"route": "/email/settings",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-024",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email queue invalid retry action safe",
|
|
"type": "UAT",
|
|
"route": "/email/queue/999999/retry",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-025",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email queue invalid delete action safe",
|
|
"type": "UAT",
|
|
"route": "/email/queue/999999/delete",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-EMAIL-026",
|
|
"module": "Email Integration",
|
|
"role": "Firm Admin",
|
|
"scenario": "Email template preview invalid ID safe",
|
|
"type": "UAT",
|
|
"route": "/email/templates/999999/preview",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "email-integration.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
}
|
|
];
|
|
|
|
test.describe("v2.5.1 Additions - Email Integration", () => {
|
|
|
|
for (const c of cases) {
|
|
test(`[${c.variantId}] ${c.scenario}`, async ({ page, request }) => {
|
|
const role = c._login_role || c.role;
|
|
const kind = c._kind;
|
|
const method = c._method || 'GET';
|
|
|
|
if (kind === 'api') {
|
|
const resp = await apiCall(request, method, c.route);
|
|
await expectApiSafe(resp);
|
|
return;
|
|
}
|
|
|
|
if (kind === 'post') {
|
|
const resp = await apiCall(request, method || 'POST', c.route);
|
|
await expectApiSafe(resp);
|
|
const safe = [400, 401, 403, 404, 405, 409, 422, 429].includes(resp.status());
|
|
expect(safe, `Unsafe POST status ${resp.status()} for ${c.route}`).toBeTruthy();
|
|
return;
|
|
}
|
|
|
|
if (role && role !== 'Public' && !/Anonymous|Attacker|API/.test(role)) {
|
|
await login(page, role);
|
|
}
|
|
|
|
const resp = await safeGoto(page, c.route);
|
|
|
|
if (kind === 'page') {
|
|
await expectRouteAvailable(page, resp);
|
|
if (/password|secret|token|otp/i.test(c.scenario)) await expectNoSecrets(page);
|
|
return;
|
|
}
|
|
|
|
if (kind === 'public') {
|
|
await expectRouteAvailable(page, resp);
|
|
return;
|
|
}
|
|
|
|
if (kind === 'public-no-sensitive') {
|
|
await expectPublicNoSensitive(page);
|
|
return;
|
|
}
|
|
|
|
if (kind === 'no-secret') {
|
|
await expectRouteAvailable(page, resp);
|
|
await expectNoSecrets(page);
|
|
return;
|
|
}
|
|
|
|
await expectNoBackendError(page);
|
|
await expectBlockedOrSafe(page, resp);
|
|
});
|
|
}
|
|
});
|