Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(config): warn when a pinned database TLS flag outranks the saved one
Yudhi Armyndharis94e3a76dfb5c
diff --git a/src/config/load-env.spec.ts b/src/config/load-env.spec.tsindex 763752b74..cbfb54ecb 100644--- a/src/config/load-env.spec.ts+++ b/src/config/load-env.spec.ts@@ -70,6 +70,38 @@ describe('loadEnvironment', () => {expect(process.env.REDIS_HOST).toBe('host-from-process-env');expect(workerConnectionOptions().host).toBe('host-from-process-env');});++ // Older .env templates shipped DATABASE_SSL=false, and compose forwards it, so it silently outranks+ // TLS turned on in the dashboard. The override stands, but the boot log names both values.+ it('warns when a pinned database TLS setting differs from the one saved in the dashboard', () => {+ delete process.env.DATABASE_SSL;+ process.env.DATABASE_SSL_REJECT_UNAUTHORIZED = 'true';+ makeTempCwd({+ '.env': 'DATABASE_SSL=false\n',+ 'data/.env.generated': 'DATABASE_SSL=true\nDATABASE_SSL_REJECT_UNAUTHORIZED=false\n',+ });+ const warn = jest.spyOn(console, 'warn').mockImplementation(() => undefined);++ runLoader();++ expect(process.env.DATABASE_SSL).toBe('false');+ expect(warn.mock.calls.map(([line]) => line as string)).toEqual([+ expect.stringMatching(/DATABASE_SSL=false .*DATABASE_SSL=true /),+ expect.stringMatching(/DATABASE_SSL_REJECT_UNAUTHORIZED=true .*DATABASE_SSL_REJECT_UNAUTHORIZED=false /),+ ]);+ });++ it('stays quiet when the pinned TLS setting matches the saved one or nothing pins it', () => {+ process.env.DATABASE_SSL = 'true';+ delete process.env.DATABASE_SSL_REJECT_UNAUTHORIZED;+ makeTempCwd({ 'data/.env.generated': 'DATABASE_SSL=true\nDATABASE_SSL_REJECT_UNAUTHORIZED=false\n' });+ const warn = jest.spyOn(console, 'warn').mockImplementation(() => undefined);++ runLoader();++ expect(process.env.DATABASE_SSL_REJECT_UNAUTHORIZED).toBe('false');+ expect(warn).not.toHaveBeenCalled();+ });});describe('main.ts bootstrap order', () => {diff --git a/src/config/load-env.ts b/src/config/load-env.tsindex 2ef9fc6cf..144823b07 100644--- a/src/config/load-env.ts+++ b/src/config/load-env.ts@@ -69,7 +69,17 @@ export function loadEnvironment(): void {// 3. Dashboard-saved config (does not override .env or process env)if (fs.existsSync(generatedEnvPath)) {console.log('[Bootstrap] Loading saved configuration from:', generatedEnvPath);- dotenv.config({ path: generatedEnvPath, override: false });+ const { parsed = {} } = dotenv.config({ path: generatedEnvPath, override: false });+ // Compose forwards DATABASE_SSL*, and templates older than 0.18 set DATABASE_SSL=false in .env, so+ // a stale line can outrank TLS turned on in the dashboard. The override stands; the log names it.+ for (const key of ['DATABASE_SSL', 'DATABASE_SSL_REJECT_UNAUTHORIZED']) {+ if (parsed[key] !== undefined && process.env[key] !== parsed[key]) {+ console.warn(+ `[Bootstrap] ${key}=${process.env[key]} from the environment or .env overrides ${key}=${parsed[key]} ` ++ 'saved in data/.env.generated (Dashboard > Infrastructure)',+ );+ }+ }} else {console.log('[Bootstrap] First run detected, creating default configuration...');// Create minimal .env.generated with sensible defaults