Skip to content

Commit

Permalink
fix: null dereference in redact()
Browse files Browse the repository at this point in the history
* add some tests as well
  • Loading branch information
ahochsteger committed May 16, 2024
1 parent c8621a3 commit 0c6f80c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/lib/utils/Logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,21 @@ it("should trace to console and logsheet", () => {
)
expect(sheetSpy).toHaveBeenCalled()
})

describe("redact", () => {
it("should show beginning and end of longer sensible information", () => {
const actual = logger.redact(
mocks.processingContext,
"abcdefghijklmnopqrstuvwxyz",
)
expect(actual).toEqual("abc...xyz")
})
it("should show (redacted) for shorter sensible information", () => {
const actual = logger.redact(mocks.processingContext, "abcdef")
expect(actual).toEqual("(redacted)")
})
it("should gracefully handle null and undefined values", () => {
const actual = logger.redact(mocks.processingContext, null)
expect(actual).toEqual("")
})
})
5 changes: 4 additions & 1 deletion src/lib/utils/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export class Logger {
ctx.proc.spreadsheetAdapter.log(ctx, args)
}
}
redact(ctx: ProcessingContext, value: string): string {
redact(ctx: ProcessingContext, value?: string | null): string {
if (value === null || value === undefined) {
return ""
}
switch (ctx.proc.config.settings.logSensitiveRedactionMode) {
case LogRedactionMode.ALL:
value = "(redacted)"
Expand Down

0 comments on commit 0c6f80c

Please sign in to comment.