- /api (v1) answers 410 API_V1_REMOVED, except provider webhooks (/api/webhooks/*, /api/whatsapp/webhook) and links in sent messages (308s, one-click POST). 43 v1 route files and deprecation.ts removed; /docs redirects to /docs/v2; API_DOCUMENTATION.md points there. - Read-only and impersonation lists name v2 paths only. The campus scope route test now runs over v2 routes (v2CampusScope.test.ts). - Passwords hashed with Argon2id (@node-rs/argon2); bcrypt hashes still sign in and are re-hashed at the next sign-in. - e2e on /api/v2 only (v2() helper); Playwright waits on /api/v2. - MIGRATING-TO-2.md with the full v1 -> v2 table. - Two documented response shapes corrected. Backend 690 tests and e2e 102/102 (PayFast sandbox skipped) pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
2.8 KiB
TypeScript
54 lines
2.8 KiB
TypeScript
// Every staff/supervisor route on /api/v2 must really check campus-scoped staff (utils/campusScope.js).
|
|
// A route has to declare `campusScope` (start-up fails otherwise), but the declaration is only text:
|
|
// the check itself is a marked middleware — scopeEvent(...), scopeBody(...), scopeList,
|
|
// unscopedOnly, campusIndependent('reason') or scopeBroadcast(...). A route without one would show
|
|
// a campus-limited supervisor every campus's data, so this fails on it.
|
|
//
|
|
// (Until 2.0 the same test ran over the v1 route files, which held the markers.)
|
|
//
|
|
// The routes below check campuses inside their TypeScript service or handler instead, as their
|
|
// `campusScope` text says. Adding a route here means its handler does the check itself.
|
|
const CHECKED_IN_HANDLER = new Set([
|
|
'GET /events/manage', 'POST /events', 'GET /sections', 'POST /uploads/event-image',
|
|
'GET /series', 'POST /series', 'PATCH /series/:id', 'GET /series/:id/compare',
|
|
'GET /season-passes', 'POST /season-passes', 'PATCH /season-passes/:id', 'DELETE /season-passes/:id',
|
|
'GET /coupons', 'GET /coupons/redemptions', 'GET /coupons/:id', 'POST /coupons', 'PATCH /coupons/:id',
|
|
'GET /campuses/:id/audience', 'GET /registrations',
|
|
'GET /saved-filters', 'POST /saved-filters', 'PUT /saved-filters/:id', 'DELETE /saved-filters/:id',
|
|
'GET /checkin/:qrCode', 'POST /checkin/:qrCode',
|
|
]);
|
|
|
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
const { v2Router } = require('../src/v2');
|
|
const { routes } = require('../src/v2/route');
|
|
|
|
type Route = { method: string; path: string; access: string; campusScope?: string; middleware?: { campusScope?: string }[] };
|
|
|
|
describe('campus scope on v2 staff and supervisor routes', () => {
|
|
v2Router();
|
|
const staffRoutes = (routes as Route[]).filter(r => r.access === 'staff' || r.access === 'supervisor');
|
|
const key = (r: Route) => `${r.method.toUpperCase()} ${r.path}`;
|
|
const marker = (r: Route) => (r.middleware || []).find(h => h && h.campusScope)?.campusScope;
|
|
|
|
test('finds the staff and supervisor routes', () => {
|
|
expect(staffRoutes.length).toBeGreaterThan(150);
|
|
});
|
|
|
|
test('each one has a campus-scope middleware, or checks in its handler', () => {
|
|
const missing = staffRoutes.filter(r => !marker(r) && !CHECKED_IN_HANDLER.has(key(r))).map(key);
|
|
expect(missing).toEqual([]);
|
|
});
|
|
|
|
test('the handler-checked list holds only real staff routes without a middleware', () => {
|
|
const real = new Set(staffRoutes.filter(r => !marker(r)).map(key));
|
|
expect([...CHECKED_IN_HANDLER].filter(k => !real.has(k))).toEqual([]);
|
|
});
|
|
|
|
test('a campus-independent route gives a reason', () => {
|
|
for (const r of staffRoutes) {
|
|
const m = marker(r);
|
|
if (m && m.startsWith('independent')) expect(m.length).toBeGreaterThan('independent: '.length + 5);
|
|
}
|
|
});
|
|
});
|