Skip to content

Commit

Permalink
feat(APIM-344): added test to redact using regex in 'redactStringsInL…
Browse files Browse the repository at this point in the history
…ogArgs'
  • Loading branch information
avaitonis committed Jul 19, 2023
1 parent f1c101a commit 709477d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/helpers/redact-strings-in-log-args.helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,35 @@ describe('Redact errors helper', () => {
expect(redacted).toStrictEqual(args);
});

it('replaces sensitive data in input object using regex', () => {
const redactStrings = [{ searchValue: /(Login failed for user ').*(')/g, replaceValue: '$1[Redacted]$2' }];
const otherSensitiveValue = valueGenerator.word();
const messageforRegex = `Connection error: Login failed for user '${otherSensitiveValue}'`;
const redactedMessage = `Connection error: Login failed for user '[Redacted]'`;
const args = [
{
message: messageforRegex,
stack: messageforRegex,
originalError: {
message: messageforRegex,
},
},
];
const expectedResult = [
{
message: redactedMessage,
stack: redactedMessage,
originalError: {
message: redactedMessage,
},
},
];

const redacted = redactStringsInLogArgs(true, REDACT_STRING_PATHS, redactStrings, args);

expect(redacted).toStrictEqual(expectedResult);
});

it('replaces sensitive data in different input object', () => {
const args = [
{
Expand Down

0 comments on commit 709477d

Please sign in to comment.