From 278a935d68559331d894b8a85c9c7bedbac19cf5 Mon Sep 17 00:00:00 2001 From: "ankitatripathi.mp@gmail.com" Date: Fri, 21 Aug 2026 19:23:48 +0530 Subject: [PATCH 1/2] fix: handle keyword placeholder string in emailProviderDefaults for smtp credentials --- src/context/defaults.ts | 24 ++++++++++++++---------- test/context/defaults.test.js | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/context/defaults.ts b/src/context/defaults.ts index 92b4f6187..f307f8f37 100644 --- a/src/context/defaults.ts +++ b/src/context/defaults.ts @@ -32,17 +32,21 @@ export function emailProviderDefaults( } if (name === 'smtp') { - // This is to mask smtp_user to '##SMTP_USER##' - if (updated.credentials && 'smtp_user' in updated.credentials) { - delete updated.credentials.smtp_user; + // If credentials is a keyword placeholder string (e.g. @@SMTP_CREDENTIALS@@), preserve it as-is. + // The `in` operator requires an object and would throw a TypeError on a string. + if (typeof updated.credentials !== 'string') { + // This is to mask smtp_user to '##SMTP_USER##' + if (updated.credentials && 'smtp_user' in updated.credentials) { + delete updated.credentials.smtp_user; + } + updated.credentials = { + smtp_host: '##SMTP_HOSTNAME##', + smtp_port: '##SMTP_PORT##', + smtp_user: '##SMTP_USER##', + smtp_pass: '##SMTP_PASS##', + ...(updated.credentials || {}), + }; } - updated.credentials = { - smtp_host: '##SMTP_HOSTNAME##', - smtp_port: '##SMTP_PORT##', - smtp_user: '##SMTP_USER##', - smtp_pass: '##SMTP_PASS##', - ...(updated.credentials || {}), - }; } if (name === 'ses') { diff --git a/test/context/defaults.test.js b/test/context/defaults.test.js index d5f4b8905..f5940db34 100644 --- a/test/context/defaults.test.js +++ b/test/context/defaults.test.js @@ -22,6 +22,20 @@ describe('#context defaults', () => { }); }); + it('should preserve smtp credentials when it is a keyword placeholder string', async () => { + const emailProvider = { + name: 'smtp', + credentials: '@@SMTP_CREDENTIALS@@', + }; + + const result = emailProviderDefaults(emailProvider); + + expect(result).to.deep.equal({ + name: 'smtp', + credentials: '@@SMTP_CREDENTIALS@@', + }); + }); + it('should set emailProvider defaults for smtp and remove existing smtp_user', async () => { const emailProvider = { name: 'smtp', From d7f2f5df68ff1d82a53a8bf10fa21a9f767a3979 Mon Sep 17 00:00:00 2001 From: "ankitatripathi.mp@gmail.com" Date: Sat, 22 Aug 2026 01:03:00 +0530 Subject: [PATCH 2/2] fix: preserve keyword placeholder strings for all email provider credentials --- src/context/defaults.ts | 48 ++++++++++++++++++++--------------- test/context/defaults.test.js | 26 +++++++++++++++++++ 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/context/defaults.ts b/src/context/defaults.ts index f307f8f37..408a8998c 100644 --- a/src/context/defaults.ts +++ b/src/context/defaults.ts @@ -25,10 +25,12 @@ export function emailProviderDefaults( const { name } = updated; if (apiKeyProviders.includes(name)) { - updated.credentials = { - api_key: `##${name.toUpperCase()}_API_KEY##`, - ...(updated.credentials || {}), - }; + if (typeof updated.credentials !== 'string') { + updated.credentials = { + api_key: `##${name.toUpperCase()}_API_KEY##`, + ...(updated.credentials || {}), + }; + } } if (name === 'smtp') { @@ -50,28 +52,34 @@ export function emailProviderDefaults( } if (name === 'ses') { - updated.credentials = { - accessKeyId: '##SES_ACCESS_KEY_ID##', - secretAccessKey: '##SES_ACCESS_SECRET_KEY##', - region: '##SES_AWS_REGION##', - ...(updated.credentials || {}), - }; + if (typeof updated.credentials !== 'string') { + updated.credentials = { + accessKeyId: '##SES_ACCESS_KEY_ID##', + secretAccessKey: '##SES_ACCESS_SECRET_KEY##', + region: '##SES_AWS_REGION##', + ...(updated.credentials || {}), + }; + } } if (name === 'azure_cs') { - updated.credentials = { - connectionString: '##AZURE_CS_CONNECTION_KEY##', - ...(updated.credentials || {}), - }; + if (typeof updated.credentials !== 'string') { + updated.credentials = { + connectionString: '##AZURE_CS_CONNECTION_KEY##', + ...(updated.credentials || {}), + }; + } } if (name === 'ms365') { - updated.credentials = { - tenantId: '##MS365_TENANT_ID##', - clientId: '##MS365_CLIENT_ID##', - clientSecret: '##MS365_CLIENT_SECRET##', - ...(updated.credentials || {}), - }; + if (typeof updated.credentials !== 'string') { + updated.credentials = { + tenantId: '##MS365_TENANT_ID##', + clientId: '##MS365_CLIENT_ID##', + clientSecret: '##MS365_CLIENT_SECRET##', + ...(updated.credentials || {}), + }; + } } return updated; diff --git a/test/context/defaults.test.js b/test/context/defaults.test.js index f5940db34..82b369a34 100644 --- a/test/context/defaults.test.js +++ b/test/context/defaults.test.js @@ -36,6 +36,32 @@ describe('#context defaults', () => { }); }); + it('should preserve ses credentials when it is a keyword placeholder string', async () => { + const result = emailProviderDefaults({ name: 'ses', credentials: '@@SES_CREDENTIALS@@' }); + expect(result).to.deep.equal({ name: 'ses', credentials: '@@SES_CREDENTIALS@@' }); + }); + + it('should preserve mailgun credentials when it is a keyword placeholder string', async () => { + const result = emailProviderDefaults({ + name: 'mailgun', + credentials: '@@MAILGUN_CREDENTIALS@@', + }); + expect(result).to.deep.equal({ name: 'mailgun', credentials: '@@MAILGUN_CREDENTIALS@@' }); + }); + + it('should preserve azure_cs credentials when it is a keyword placeholder string', async () => { + const result = emailProviderDefaults({ + name: 'azure_cs', + credentials: '@@AZURE_CREDENTIALS@@', + }); + expect(result).to.deep.equal({ name: 'azure_cs', credentials: '@@AZURE_CREDENTIALS@@' }); + }); + + it('should preserve ms365 credentials when it is a keyword placeholder string', async () => { + const result = emailProviderDefaults({ name: 'ms365', credentials: '@@MS365_CREDENTIALS@@' }); + expect(result).to.deep.equal({ name: 'ms365', credentials: '@@MS365_CREDENTIALS@@' }); + }); + it('should set emailProvider defaults for smtp and remove existing smtp_user', async () => { const emailProvider = { name: 'smtp',