Adding all the tests and fixes to the passengers app

This commit is contained in:
Muluhabt
2026-07-21 13:45:49 +03:00
parent 8ce2d2d874
commit f2ae9c883f
3316 changed files with 15548 additions and 37 deletions

View File

@@ -1,29 +1,34 @@
/**
* Auth/authorization gaps (matrix Suite J), proven via route guard metadata — no boot needed.
* J1 🔴 The exchange-rate controller's write routes (PUT upsert, PATCH update) carry NO guard,
* so USD/ETB/DJF rates — which every international fare multiplies by — can be rewritten by
* an unauthenticated caller. Only DELETE is guarded (@PassengerAdmin). fare-engine/currency.controller.ts:25,32,42
* Auth/authorization gaps (matrix Suite J), via route guard metadata — no boot needed.
*
* C-8 🔴 The exchange-rate write routes (PUT upsert, PATCH update) carry no METHOD-LEVEL guard, so
* they get only the global JwtGuard (authentication) and NOT @PassengerAdmin (authorization)
* — unlike DELETE, which is admin-gated. Net effect (verified live in
* e2e-ui .../pb-config-propagation.spec.ts BC-11): anonymous → 401, but ANY authenticated
* user incl. a passenger → 200 rewrites live FX. fare-engine/currency.controller.ts:25,32,42
*
* NOTE: this metadata check proves the missing ADMIN guard, NOT "unauthenticated" — a global
* APP_GUARD=JwtGuard (SharedAuthModule) still requires a valid token. The earlier "unauthenticated
* FX write" reading was a false positive corrected by the live BC-11 test.
*/
import "reflect-metadata";
import { CurrencyController } from "../src/modules/fare-engine/currency.controller";
// Nest stores @UseGuards under the "__guards__" metadata key on the route handler.
const GUARDS_METADATA = "__guards__";
function guardsOn(handler: unknown): unknown[] {
return (Reflect.getMetadata(GUARDS_METADATA, handler as object) as unknown[]) ?? [];
}
describe("Auth gaps (Suite J)", () => {
it("J1 🔴 PUT upsert exchange-rate has NO guard (unauthenticated FX write)", () => {
it("C-8 🔴 PUT upsert exchange-rate has NO admin guard (only the global JwtGuard applies)", () => {
expect(guardsOn(CurrencyController.prototype.upsert)).toHaveLength(0);
});
it("J1 🔴 PATCH update exchange-rate has NO guard (unauthenticated FX write)", () => {
it("C-8 🔴 PATCH update exchange-rate has NO admin guard (only the global JwtGuard applies)", () => {
expect(guardsOn(CurrencyController.prototype.update)).toHaveLength(0);
});
it("J1 control: DELETE exchange-rate IS guarded — proving the omission on writes is not global", () => {
it("C-8 control: DELETE exchange-rate IS admin-gated — proving writes should be too", () => {
expect(guardsOn(CurrencyController.prototype.remove).length).toBeGreaterThan(0);
});
});