X-Git-Url: https://git.squeep.com/?p=squeep-logger-json-console;a=blobdiff_plain;f=test%2Flib%2Flogger.js;fp=test%2Flib%2Flogger.js;h=939c61f4f25960fbe19790e492db0dd7db91fd6f;hp=a2efb537fd5e2eb0b00e4d72274f0567ce5488cc;hb=48e12e20d03a60384830773c2ee5f37db556a894;hpb=1f557bcdd06dfdba6ce7485bd6307db3359dcb08 diff --git a/test/lib/logger.js b/test/lib/logger.js index a2efb53..939c61f 100644 --- a/test/lib/logger.js +++ b/test/lib/logger.js @@ -11,6 +11,18 @@ const asyncLocalStorage = new AsyncLocalStorage(); describe('Logger', function () { let config, logger, commonObject, scope, message; + function sanitizeCredential(data, sanitize = true) { + let unclean = false; + const credentialLength = data?.ctx?.parsedBody?.credential?.length; + if (credentialLength) { + unclean = true; + } + if (unclean && sanitize) { + data.ctx.parsedBody.credential = '*'.repeat(credentialLength); + } + return unclean; + } + beforeEach(function () { config = {}; commonObject = { @@ -76,17 +88,7 @@ describe('Logger', function () { }); it('sanitizes', function () { - logger.dataSanitizers.push((data, sanitize = true) => { - let unclean = false; - const credentialLength = data?.ctx?.parsedBody?.credential?.length; - if (credentialLength) { - unclean = true; - } - if (unclean && sanitize) { - data.ctx.parsedBody.credential = '*'.repeat(credentialLength); - } - return unclean; - }); + logger.dataSanitizers.push(sanitizeCredential); logger.info(scope, message, { ctx: { parsedBody: { @@ -157,4 +159,19 @@ describe('Logger', function () { assert(logger.backend.info.called); assert(logger.backend.info.args[0][0].includes('[Circular]')); }); + + it('covers non-serializable objects', function () { + logger.dataSanitizers.push(sanitizeCredential); + const data = { + ctx: { + parsedBody: { + credential: 'foo', + }, + }, + foo: new WeakMap(), + }; + logger.info(scope, message, data); + assert(logger.backend.info.called); + }); + }); // Logger \ No newline at end of file