Skip to content

Commit 5e03cbc

Browse files
committed
fix: don't replace secrets in non-string items
1 parent fd49610 commit 5e03cbc

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.2.1] - 2025-07-16
11+
12+
### Fixed
13+
14+
- Error when trying to remove secrets from console logs that had non-string parameters.
15+
1016
## [0.2.0] - 2025-05-08
1117

1218
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-environment-airtable-script",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "A jest environment for testing Airtable scripts in extensions and automations",
55
"license": "Apache-2.0",
66
"author": "",

src/environment/console-aggregator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ const consoleAggregator = (): ConsoleAggregator => {
3838
return message
3939
}
4040
return secretValues.reduce(
41-
(acc, value) => acc.replace(value, SECRET_VALUE_REDACTED),
41+
(acc, value) =>
42+
typeof acc === 'string'
43+
? acc.replace(value, SECRET_VALUE_REDACTED)
44+
: acc,
4245
message
4346
)
4447
}

test/input.test.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,58 @@ describe('Input', () => {
6767
},
6868
},
6969
})
70-
console.log(results)
7170
expect(results.console[0]).toEqual({
7271
message: SECRET_VALUE_REDACTED,
7372
type: 'log',
7473
})
7574
})
75+
76+
it('masks a partial secret value when console.logged', async () => {
77+
const results = await runAirtableScript({
78+
script: `
79+
const config = input.secret('test-key')
80+
console.log(\`hello, \${config}\`)
81+
`,
82+
base: randomRecords,
83+
inAutomation: true,
84+
mockInput: {
85+
secret: (secretKey: string) => {
86+
if (secretKey === 'test-key') {
87+
return 'test-secret-value'
88+
}
89+
return null
90+
},
91+
},
92+
})
93+
expect(results.console[0]).toEqual({
94+
message: `hello, ${SECRET_VALUE_REDACTED}`,
95+
type: 'log',
96+
})
97+
})
98+
99+
it('does not try to mask a secret in a non-string item is logged', async () => {
100+
const results = await runAirtableScript({
101+
script: `
102+
const config = input.secret('test-key')
103+
console.log(1)
104+
`,
105+
base: randomRecords,
106+
inAutomation: true,
107+
mockInput: {
108+
secret: (secretKey: string) => {
109+
if (secretKey === 'test-key') {
110+
return 'test-secret-value'
111+
}
112+
return null
113+
},
114+
},
115+
})
116+
117+
expect(results.console[0]).toEqual({
118+
message: 1,
119+
type: 'log',
120+
})
121+
})
76122
})
77123
describe('extension script', () => {
78124
it('passes a text item', async () => {

0 commit comments

Comments
 (0)