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 = {
});
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: {
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