Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(auth): scan controller paths with `path` instead of splitting on '/' (#1048)
AlexC019b53a3a043
diff --git a/src/modules/auth/global-route-fence-coverage.spec.ts b/src/modules/auth/global-route-fence-coverage.spec.tsindex 11a7a8bf5..09a7ef501 100644--- a/src/modules/auth/global-route-fence-coverage.spec.ts+++ b/src/modules/auth/global-route-fence-coverage.spec.ts@@ -9,7 +9,7 @@// a @SessionScoped controller) and carries neither @RequireUnscopedKey, @Public, nor an entry in// ALLOWLIST below — so a future endpoint cannot silently re-introduce the gap.import { readdirSync, readFileSync } from 'fs';-import { join } from 'path';+import { basename, join, sep } from 'path';/*** Handlers that are deliberately global AND deliberately reachable by a session-restricted key,@@ -184,11 +184,15 @@ export class ThingController {const modulesDir = join(__dirname, '..');const offenders: string[] = [];for (const file of listControllerFiles(modulesDir)) {- const basename = file.split('/').pop() as string;+ // Derive the file name through `path`, and normalize separators before matching: `join()`+ // yields backslashes on Windows, so splitting on '/' left the whole path as the "basename",+ // no ALLOWLIST key ever matched, and every allowlisted controller was reported as an offender.+ const fileName = basename(file);+ const posixPath = file.split(sep).join('/');for (const handler of handlersMissingGlobalFence(readFileSync(file, 'utf8'))) {- const key = `${basename} :: ${handler}`;+ const key = `${fileName} :: ${handler}`;if (ALLOWLIST.has(key)) continue;- offenders.push(`${file.replace(/.*\/src\//, 'src/')} :: ${handler}`);+ offenders.push(`${posixPath.replace(/.*\/src\//, 'src/')} :: ${handler}`);}}expect(offenders).toEqual([]);