Files
arrr-erp-test-v2/tests/billing-business-rules.spec.js
T
2026-06-26 20:38:14 +05:30

435 lines
13 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-BIZBILL-001",
"module": "Billing Business Rules",
"role": "Firm Admin",
"scenario": "Billing dashboard loads",
"type": "UAT",
"route": "/billing",
"_kind": "page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": "Firm Admin"
},
{
"variantId": "V251-BIZBILL-002",
"module": "Billing Business Rules",
"role": "Firm Admin",
"scenario": "Invoices list loads",
"type": "UAT",
"route": "/billing/invoices",
"_kind": "page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": "Firm Admin"
},
{
"variantId": "V251-BIZBILL-003",
"module": "Billing Business Rules",
"role": "Firm Admin",
"scenario": "Invoice create page loads",
"type": "UAT",
"route": "/billing/invoices/new",
"_kind": "page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": "Firm Admin"
},
{
"variantId": "V251-BIZBILL-004",
"module": "Billing Business Rules",
"role": "Firm Admin",
"scenario": "Payments list loads",
"type": "UAT",
"route": "/billing/payments",
"_kind": "page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": "Firm Admin"
},
{
"variantId": "V251-BIZBILL-005",
"module": "Billing Business Rules",
"role": "Firm Admin",
"scenario": "Invalid invoice detail safe",
"type": "VAPT",
"route": "/billing/invoices/999999",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": "Firm Admin"
},
{
"variantId": "V251-BIZBILL-006",
"module": "Billing Business Rules",
"role": "Client",
"scenario": "Client cannot access all invoices",
"type": "VAPT",
"route": "/billing/invoices",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": "Client"
},
{
"variantId": "V251-BIZBILL-007",
"module": "Billing Business Rules",
"role": "Staff",
"scenario": "Staff cannot access billing",
"type": "VAPT",
"route": "/billing",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": "Staff"
},
{
"variantId": "V251-BIZBILL-008",
"module": "Billing Business Rules",
"role": "Consultant",
"scenario": "Consultant cannot access billing",
"type": "VAPT",
"route": "/billing",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": "Consultant"
},
{
"variantId": "V251-BIZBILL-009",
"module": "Billing Business Rules",
"role": "Client",
"scenario": "Client own invoice invalid ID safe",
"type": "VAPT",
"route": "/client/invoices/999999",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": "Client"
},
{
"variantId": "V251-BIZBILL-010",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice create without line items rejected",
"type": "VAPT",
"route": "/billing/invoices",
"_kind": "post",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-011",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice duplicate number invalid POST safe",
"type": "VAPT",
"route": "/billing/invoices",
"_kind": "post",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-012",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice invalid GST/tax values rejected",
"type": "VAPT",
"route": "/billing/invoices",
"_kind": "post",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-013",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice issue CSRF-less POST rejected",
"type": "VAPT",
"route": "/billing/invoices/999999/issue",
"_kind": "post",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-014",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice cancel CSRF-less POST rejected",
"type": "VAPT",
"route": "/billing/invoices/999999/cancel",
"_kind": "post",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-015",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Void invoice cannot accept payment",
"type": "VAPT",
"route": "/billing/invoices/999999/payments",
"_kind": "post",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-016",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Partial payment invalid ID safe",
"type": "VAPT",
"route": "/billing/invoices/999999/payments",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-017",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Overpayment blocked",
"type": "VAPT",
"route": "/billing/invoices/999999/payments",
"_kind": "post",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-018",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Payment receipt invalid ID safe",
"type": "VAPT",
"route": "/billing/payments/999999/receipt",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-019",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice PDF invalid ID safe",
"type": "VAPT",
"route": "/billing/invoices/999999/pdf",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-020",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice print invalid ID safe",
"type": "VAPT",
"route": "/billing/invoices/999999/print",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-021",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice internal notes hidden from client route safe",
"type": "VAPT",
"route": "/client/invoices/999999",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-022",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Payment delete CSRF-less POST rejected",
"type": "VAPT",
"route": "/billing/payments/999999/delete",
"_kind": "post",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-023",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice line update invalid ID rejected",
"type": "VAPT",
"route": "/billing/invoices/999999/lines/999999",
"_kind": "post",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-024",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice export requires authorization",
"type": "VAPT",
"route": "/billing/invoices/export",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-025",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Payment export requires authorization",
"type": "VAPT",
"route": "/billing/payments/export",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-026",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Cross-client invoice IDOR safe",
"type": "VAPT",
"route": "/billing/invoices/999999?client_id=999999",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
},
{
"variantId": "V251-BIZBILL-027",
"module": "Billing Business Rules",
"role": "Anonymous/Attacker",
"scenario": "Invoice number sequence endpoint safe",
"type": "VAPT",
"route": "/billing/invoices/next-number",
"_kind": "safe-page",
"_method": "GET",
"_file": "billing-business-rules.spec.js",
"_login_role": null
}
];
test.describe("v2.5.1 Additions - Billing 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);
});
}
});