From 5e03cbc5eb9d5f32f6479a36e043a48e24d0c2e6 Mon Sep 17 00:00:00 2001 From: Kevin Miller Date: Wed, 16 Jul 2025 15:40:34 -0400 Subject: [PATCH] fix: don't replace secrets in non-string items --- CHANGELOG.md | 6 ++++ package.json | 2 +- src/environment/console-aggregator.ts | 5 ++- test/input.test.ts | 48 ++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ec4dd1..3e7f2cc 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.1] - 2025-07-16 + +### Fixed + +- Error when trying to remove secrets from console logs that had non-string parameters. + ## [0.2.0] - 2025-05-08 ### Added diff --git a/package.json b/package.json index 4ea3497..10d956c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jest-environment-airtable-script", - "version": "0.2.0", + "version": "0.2.1", "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 1d31eb5..f607c15 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 () => {