diff --git a/CHANGELOG.md b/CHANGELOG.md index 9357b74..084bd68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.2] - 2025-07-16 + +### Fixed + +- Error when trying to remove secrets from console logs that had non-string parameters. + ## [0.2.1] - 2025-05-15 ### Fixed diff --git a/package.json b/package.json index 10d956c..ceefe59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jest-environment-airtable-script", - "version": "0.2.1", + "version": "0.2.2", "description": "A jest environment for testing Airtable scripts in extensions and automations", "license": "Apache-2.0", "author": "", diff --git a/src/environment/console-aggregator.ts b/src/environment/console-aggregator.ts index de58fca..96a1549 100644 --- a/src/environment/console-aggregator.ts +++ b/src/environment/console-aggregator.ts @@ -38,7 +38,10 @@ const consoleAggregator = (): ConsoleAggregator => { return message } return secretValues.reduce( - (acc, value) => acc.replace(value, SECRET_VALUE_REDACTED), + (acc, value) => + typeof acc === 'string' + ? acc.replace(value, SECRET_VALUE_REDACTED) + : acc, message ) } diff --git a/test/input.test.ts b/test/input.test.ts index d48635a..f75dd5c 100644 --- a/test/input.test.ts +++ b/test/input.test.ts @@ -67,12 +67,58 @@ describe('Input', () => { }, }, }) - console.log(results) expect(results.console[0]).toEqual({ message: SECRET_VALUE_REDACTED, type: 'log', }) }) + + it('masks a partial secret value when console.logged', async () => { + const results = await runAirtableScript({ + script: ` + const config = input.secret('test-key') + console.log(\`hello, \${config}\`) + `, + base: randomRecords, + inAutomation: true, + mockInput: { + secret: (secretKey: string) => { + if (secretKey === 'test-key') { + return 'test-secret-value' + } + return null + }, + }, + }) + expect(results.console[0]).toEqual({ + message: `hello, ${SECRET_VALUE_REDACTED}`, + type: 'log', + }) + }) + + it('does not try to mask a secret in a non-string item is logged', async () => { + const results = await runAirtableScript({ + script: ` + const config = input.secret('test-key') + console.log(1) + `, + base: randomRecords, + inAutomation: true, + mockInput: { + secret: (secretKey: string) => { + if (secretKey === 'test-key') { + return 'test-secret-value' + } + return null + }, + }, + }) + + expect(results.console[0]).toEqual({ + message: 1, + type: 'log', + }) + }) }) describe('extension script', () => { it('passes a text item', async () => {