Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(config): say where to fix a built-in Redis TLS or user refusal
Yudhi Armyndharisa4defb29ba94
diff --git a/src/config/env.validation.spec.ts b/src/config/env.validation.spec.tsindex e9185c4a7..01e3addd3 100644--- a/src/config/env.validation.spec.ts+++ b/src/config/env.validation.spec.ts@@ -914,6 +914,21 @@ describe('validateEnv built-in Redis connection settings', () => {);});+ it('says where to fix it and names the external Redis way out', () => {+ const message = () => {+ try {+ validateEnv({ ...builtin, REDIS_TLS: 'true' });+ } catch (error) {+ return (error as Error).message;+ }+ return '';+ };+ expect(message()).toMatch(/set REDIS_TLS=false in the environment, \.\/\.env or data\/\.env\.generated/);+ expect(message()).toMatch(+ /use an external Redis \(REDIS_BUILTIN=false with its REDIS_HOST, also on the Infrastructure page\)/,+ );+ });+it('keeps TLS to an external host, and accepts plaintext or a Redis nothing uses', () => {expect(() => validateEnv({ ...builtin, REDIS_HOST: 'cache.example.com', REDIS_TLS: 'true' })).not.toThrow();expect(() => validateEnv({ ...builtin, REDIS_TLS: 'false' })).not.toThrow();@@ -938,6 +953,12 @@ describe('validateEnv built-in Redis connection settings', () => {expect(() => validateEnv({ ...builtin, REDIS_USERNAME: username })).not.toThrow();});+ it('says where to fix it and names the external Redis way out', () => {+ expect(() => validateEnv({ ...builtin, REDIS_USERNAME: 'worker' })).toThrow(+ /remove the named username in the environment, \.\/\.env or data\/\.env\.generated, or use an external Redis \(REDIS_BUILTIN=false with its REDIS_HOST, also on the Infrastructure page\)/,+ );+ });+it('keeps a named user for an external host, and accepts one when Redis is not the bundled one in use', () => {expect(() =>validateEnv({ ...builtin, REDIS_HOST: 'cache.example.com', REDIS_USERNAME: 'worker' }),diff --git a/src/config/env.validation.ts b/src/config/env.validation.tsindex 4dfcce080..29f95b036 100644--- a/src/config/env.validation.ts+++ b/src/config/env.validation.ts@@ -62,6 +62,10 @@ export function postgresSchemaError(schema: string): string | null {const REDIS_CONSUMER_FLAGS = ['REDIS_ENABLED', 'QUEUE_ENABLED', 'CACHE_ENABLED'];+/** The one way to keep TLS or a named user: an external server, which the Infrastructure page selects too. */+const EXTERNAL_REDIS_WAY_OUT =+ 'or use an external Redis (REDIS_BUILTIN=false with its REDIS_HOST, also on the Infrastructure page)';+/** The bundled Redis is the one this deployment connects to: it is selected, in use, and named as the host. */function usesBundledRedis(config: EnvConfig): boolean {const host = typeof config.REDIS_HOST === 'string' ? config.REDIS_HOST : undefined;@@ -76,8 +80,8 @@ function usesBundledRedis(config: EnvConfig): boolean {export function builtinRedisTlsError(config: EnvConfig): string | null {if (!usesBundledRedis(config) || config.REDIS_TLS !== 'true') return null;return (- 'REDIS_TLS=true cannot reach the built-in Redis container, which runs without TLS; ' +- 'set REDIS_TLS=false where it is configured'+ 'REDIS_TLS=true cannot reach the built-in Redis container, which runs without TLS; set REDIS_TLS=false in the ' ++ `environment, ./.env or data/.env.generated, ${EXTERNAL_REDIS_WAY_OUT}`);}@@ -86,8 +90,8 @@ export function builtinRedisUsernameError(config: EnvConfig): string | null {const username = typeof config.REDIS_USERNAME === 'string' ? config.REDIS_USERNAME : undefined;if (!usesBundledRedis(config) || !username || username === 'default') return null;return (- 'REDIS_USERNAME must be unset or default for the built-in Redis container; ' +- 'remove the named username where it is configured'+ 'REDIS_USERNAME must be unset or default for the built-in Redis container; remove the named username in the ' ++ `environment, ./.env or data/.env.generated, ${EXTERNAL_REDIS_WAY_OUT}`);}