471 lines
14 KiB
JavaScript
471 lines
14 KiB
JavaScript
|
|
const { test, expect } = require('@playwright/test');
|
|
require('dotenv').config();
|
|
const { BASE_URL, absoluteUrl } = require('../fixtures/url');
|
|
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 = absoluteUrl(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-WORK2-001",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Firm Admin",
|
|
"scenario": "Engagement create page/list loads",
|
|
"type": "UAT",
|
|
"route": "/work/engagements",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-002",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Firm Admin",
|
|
"scenario": "Existing engagement detail loads",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/1",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-003",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Staff",
|
|
"scenario": "Staff work board loads",
|
|
"type": "UAT",
|
|
"route": "/work",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": "Staff"
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-004",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Manager",
|
|
"scenario": "Manager team work board loads",
|
|
"type": "UAT",
|
|
"route": "/manager/work",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": "Manager"
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-005",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Partner",
|
|
"scenario": "Partner reviews page loads",
|
|
"type": "UAT",
|
|
"route": "/partner/reviews",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": "Partner"
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-006",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Client",
|
|
"scenario": "Client dashboard compliance item list loads",
|
|
"type": "UAT",
|
|
"route": "/client/dashboard",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": "Client"
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-007",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Consultant",
|
|
"scenario": "Consultant assignment area loads",
|
|
"type": "UAT",
|
|
"route": "/consultants",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": "Consultant"
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-008",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Staff",
|
|
"scenario": "Invalid engagement ID is safe",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/999999",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": "Staff"
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-009",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Client",
|
|
"scenario": "Client cannot access internal engagement detail",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/999999",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": "Client"
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-010",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Consultant",
|
|
"scenario": "Consultant cannot access internal engagement detail",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/999999",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": "Consultant"
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-011",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Create engagement CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-012",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Generate tasks CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/999999/generate-tasks",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-013",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Assign task CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/tasks/999999/assign",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-014",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Staff start task invalid ID safe",
|
|
"type": "VAPT",
|
|
"route": "/work/tasks/999999/start",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-015",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Staff complete task invalid ID safe",
|
|
"type": "VAPT",
|
|
"route": "/work/tasks/999999/complete",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-016",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Task upload document invalid ID rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/tasks/999999/documents/upload",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-017",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Manager review invalid task rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/tasks/999999/review",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-018",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Partner approve invalid engagement rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/999999/approve",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-019",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Partner reject invalid engagement rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/999999/reject",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-020",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Add internal comment CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/999999/comments",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-021",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Add client-visible comment invalid route safe",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/999999/client-comments",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-022",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Blocked task without reason rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/tasks/999999/block",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-023",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Completed task edit invalid ID safe",
|
|
"type": "VAPT",
|
|
"route": "/work/tasks/999999/edit",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-024",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Locked FY task change rejected or safe",
|
|
"type": "VAPT",
|
|
"route": "/work/tasks/999999/status",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-025",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Task priority update CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/tasks/999999/priority",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-026",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Task due date update CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/tasks/999999/due-date",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-027",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Work document download invalid ID safe",
|
|
"type": "VAPT",
|
|
"route": "/work/documents/999999/download",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-028",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Work communication internal note hidden from client route safe",
|
|
"type": "VAPT",
|
|
"route": "/client/work/engagements/999999/comments",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-029",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Cross-tenant engagement IDOR safe",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/999999?tenant_id=999999",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-WORK2-030",
|
|
"module": "Work Lifecycle E2E",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Engagement delete CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/work/engagements/999999/delete",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "work-lifecycle-e2e.spec.js",
|
|
"_login_role": null
|
|
}
|
|
];
|
|
|
|
test.describe("v2.5.1 Additions - Work Lifecycle E2E", () => {
|
|
|
|
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);
|
|
});
|
|
}
|
|
});
|