Obfuscating password from logs
This commit is contained in:
parent
34107e3d58
commit
a97fb5df2f
4 changed files with 33 additions and 2 deletions
|
|
@ -75,6 +75,14 @@ export class LoggerInstance {
|
||||||
message,
|
message,
|
||||||
]
|
]
|
||||||
if (details) {
|
if (details) {
|
||||||
|
if (typeof details === 'object') {
|
||||||
|
const toObfuscate = ['password']
|
||||||
|
toObfuscate.forEach((key) => {
|
||||||
|
if ((details as Record<string, unknown>)[key]) {
|
||||||
|
(details as Record<string, unknown>)[key] = '***'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
params.push(details)
|
params.push(details)
|
||||||
fmtString += ' - %O'
|
fmtString += ' - %O'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ export const work = async (
|
||||||
): Promise<SchedulerResult> => {
|
): Promise<SchedulerResult> => {
|
||||||
Logger.instantiate('scheduler', v4(), LogLevel.DEBUG)
|
Logger.instantiate('scheduler', v4(), LogLevel.DEBUG)
|
||||||
|
|
||||||
// TODO: obfuscate payload
|
|
||||||
Logger.debug('Handling reservation', { payload })
|
Logger.debug('Handling reservation', { payload })
|
||||||
let reservation: Reservation
|
let reservation: Reservation
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
import { Logger, LogLevel } from '../../src/common/logger'
|
import { Logger, LogLevel } from '../../src/common/logger'
|
||||||
|
|
||||||
describe('Logger', () => {
|
describe('Logger', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
test('should create a single instance of LoggerInstance', () => {
|
test('should create a single instance of LoggerInstance', () => {
|
||||||
const a = Logger.instantiate('tag', 'abc', LogLevel.DEBUG)
|
const a = Logger.instantiate('tag', 'abc', LogLevel.DEBUG)
|
||||||
const b = Logger.getInstance()
|
const b = Logger.getInstance()
|
||||||
|
|
@ -56,4 +60,25 @@ describe('Logger', () => {
|
||||||
|
|
||||||
expect(consoleLogSpy).not.toHaveBeenCalled()
|
expect(consoleLogSpy).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should obfuscate password from message', () => {
|
||||||
|
const consoleLogSpy = jest.fn()
|
||||||
|
const consoleErrorSpy = jest.fn()
|
||||||
|
jest.spyOn(console, 'log').mockImplementation(consoleLogSpy)
|
||||||
|
jest.spyOn(console, 'error').mockImplementation(consoleErrorSpy)
|
||||||
|
|
||||||
|
Logger.instantiate('tag', 'abc', LogLevel.DEBUG)
|
||||||
|
Logger.info('first', { password: 'test' })
|
||||||
|
|
||||||
|
expect(consoleLogSpy).toHaveBeenCalledTimes(1)
|
||||||
|
expect(consoleLogSpy).toHaveBeenNthCalledWith(
|
||||||
|
1,
|
||||||
|
'<%s> [%s] %s: %s - %O',
|
||||||
|
'tag',
|
||||||
|
'abc',
|
||||||
|
'INFO',
|
||||||
|
'first',
|
||||||
|
{ password: '***'},
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import dayjs from 'dayjs'
|
||||||
import {
|
import {
|
||||||
validateJSONRequest,
|
validateJSONRequest,
|
||||||
ValidationError,
|
ValidationError,
|
||||||
ValidationErrorCode,
|
|
||||||
} from '../../src/common/request'
|
} from '../../src/common/request'
|
||||||
|
|
||||||
describe('request', () => {
|
describe('request', () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue