Skip to content

Commit

Permalink
Added unit test for redacting from JSON strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmwllc committed Sep 13, 2018
1 parent 4830119 commit 29aab47
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/encoder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ describe('encoder', () => {
)
})

it('should redact values from JSON string and convert JSON to object', () => {
let encoded = new Encoder({redactList: [new RegExp('(\blng\b)|(\blat\b)|firstName|lastName|phone', 'gi')]}).encode({
traceId: 'abc',
spanId: 'def',
parentId: 'ghi',
operation: 'op1',
start: 1489522409134,
duration: 123,
tags: {
redact: 'val1',
tag2: 'val2'
},
logs: [{
firstName: 'Tom',
event:"Handled Request",
level:"info",
message:"Handled Request POST:/v2/reservations/8FC5735C312A44A1933365EDECFCA36D-1518675144764[461]",
logEvent:"Handled Request",
request: {
headers: {},
body:"{\"status\":\"active\",\"shopper\":{\"firstName\":\"Tom\",\"lastName\":\"Wallace\",\"phone\":\"1234567891\"}}"
}
}]
})
encoded.should.equal('{"traceId":"abc","spanId":"def","parentId":"ghi","operation":"op1","start":1489522409134,"duration":123,"tags":{"redact":"val1","tag2":"val2"},"logs":[{"firstName":"***","event":"Handled Request","level":"info","message":"Handled Request POST:/v2/reservations/8FC5735C312A44A1933365EDECFCA36D-1518675144764[461]","logEvent":"Handled Request","request":{"headers":{},"body":{"status":"active","shopper":{"firstName":"***","lastName":"***","phone":"***"}}}}]}' + os.EOL
)
})

it('should redact values', () => {
let encoded = new Encoder({redactList: [/redact/]}).encode({
traceId: 'abc',
Expand Down

0 comments on commit 29aab47

Please sign in to comment.