-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/test: sanitize log messages whilst preserving readability
- Loading branch information
1 parent
5252d26
commit fb143be
Showing
2 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { formatLogMessage } from "../../logger/cloudLogging"; | ||
|
||
describe("formatLogMessage utility function ensures complex log messages are sanitized but still readable", () => { | ||
it("should preserve newlines and carriage returns", () => { | ||
const inputMessage = "Error: Something went wrong\nDetails: Invalid input\r\nPlease try again."; | ||
const expectedOutput = "AUDIT_LOG: Error: Something went wrong\nDetails: Invalid input\r\nPlease try again."; | ||
|
||
const formattedMessage = formatLogMessage(inputMessage); | ||
|
||
console.log("Expected log format:", JSON.stringify(expectedOutput)); | ||
console.log("Received log format:", JSON.stringify(formattedMessage)); | ||
|
||
expect(formattedMessage).toBe(expectedOutput); | ||
}); | ||
|
||
it("should remove non-printable characters", () => { | ||
const message = "Error: Something went wrong\x01\x02\n at FunctionName (file.js:10:15)\x03\x04\n at AnotherFunction (file.js:20:25)\r\n at YetAnotherFunction (file.js:30:35)"; | ||
const expectedOutput = "AUDIT_LOG: Error: Something went wrong\n at FunctionName (file.js:10:15)\n at AnotherFunction (file.js:20:25)\r\n at YetAnotherFunction (file.js:30:35)"; | ||
const formattedMessage = formatLogMessage(message); | ||
|
||
console.log("Expected log format:", JSON.stringify(expectedOutput)); | ||
console.log("Received log format:", JSON.stringify(formattedMessage)); | ||
|
||
expect(formattedMessage).toBe(expectedOutput); | ||
}); | ||
}); |