350 lines
11 KiB
JavaScript
350 lines
11 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-HRRULE-001",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Staff",
|
|
"scenario": "Attendance page loads",
|
|
"type": "UAT",
|
|
"route": "/employee/attendance",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": "Staff"
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-002",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Staff",
|
|
"scenario": "Leave page loads",
|
|
"type": "UAT",
|
|
"route": "/employee/leaves",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": "Staff"
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-003",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Manager",
|
|
"scenario": "Manager team attendance loads",
|
|
"type": "UAT",
|
|
"route": "/employees/attendance",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": "Manager"
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-004",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Manager",
|
|
"scenario": "Manager team leave loads",
|
|
"type": "UAT",
|
|
"route": "/employees/leave",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": "Manager"
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-005",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Firm Admin",
|
|
"scenario": "Payroll page loads for Firm Admin",
|
|
"type": "UAT",
|
|
"route": "/employees/payroll",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-006",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Firm Admin",
|
|
"scenario": "Employee documents page loads",
|
|
"type": "UAT",
|
|
"route": "/employees/documents",
|
|
"_kind": "page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": "Firm Admin"
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-007",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Client",
|
|
"scenario": "Client cannot access attendance",
|
|
"type": "VAPT",
|
|
"route": "/employee/attendance",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": "Client"
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-008",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Consultant",
|
|
"scenario": "Consultant cannot access payroll",
|
|
"type": "VAPT",
|
|
"route": "/employees/payroll",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": "Consultant"
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-009",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Duplicate attendance same date rejected",
|
|
"type": "VAPT",
|
|
"route": "/employee/attendance",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-010",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Manual attendance CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/employees/attendance/manual",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-011",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Leave exceeding balance rejected",
|
|
"type": "VAPT",
|
|
"route": "/employee/leaves",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-012",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Leave approve invalid ID rejected",
|
|
"type": "VAPT",
|
|
"route": "/employees/leave/999999/approve",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-013",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Leave reject invalid ID rejected",
|
|
"type": "VAPT",
|
|
"route": "/employees/leave/999999/reject",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-014",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Payroll generate CSRF-less POST rejected",
|
|
"type": "VAPT",
|
|
"route": "/employees/payroll/generate",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-015",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Payroll approve before generate invalid safe",
|
|
"type": "VAPT",
|
|
"route": "/employees/payroll/999999/approve",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-016",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Payroll paid before approval invalid safe",
|
|
"type": "VAPT",
|
|
"route": "/employees/payroll/999999/mark-paid",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-017",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Payslip invalid ID safe",
|
|
"type": "VAPT",
|
|
"route": "/employees/payroll/999999/payslip",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-018",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Offboarding complete invalid employee safe",
|
|
"type": "VAPT",
|
|
"route": "/employees/999999/offboarding/complete",
|
|
"_kind": "safe-page",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-019",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Employee document approve invalid ID rejected",
|
|
"type": "VAPT",
|
|
"route": "/employees/documents/999999/approve",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
},
|
|
{
|
|
"variantId": "V251-HRRULE-020",
|
|
"module": "Employee HR Business Rules",
|
|
"role": "Anonymous/Attacker",
|
|
"scenario": "Employee document reject invalid ID rejected",
|
|
"type": "VAPT",
|
|
"route": "/employees/documents/999999/reject",
|
|
"_kind": "post",
|
|
"_method": "GET",
|
|
"_file": "employee-hr-business-rules.spec.js",
|
|
"_login_role": null
|
|
}
|
|
];
|
|
|
|
test.describe("v2.5.1 Additions - Employee HR Business Rules", () => {
|
|
|
|
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);
|
|
});
|
|
}
|
|
});
|