Remove privacy redaction from Errors.toLogFormat
This commit is contained in:
parent
e71246a9e3
commit
44b81f68dd
2 changed files with 22 additions and 19 deletions
|
@ -1,9 +1,7 @@
|
||||||
const ensureError = require('ensure-error');
|
const ensureError = require('ensure-error');
|
||||||
|
|
||||||
const Privacy = require('../privacy');
|
|
||||||
|
|
||||||
// toLogFormat :: Error -> String
|
// toLogFormat :: Error -> String
|
||||||
exports.toLogFormat = (error) => {
|
exports.toLogFormat = (error) => {
|
||||||
const normalizedError = ensureError(error);
|
const normalizedError = ensureError(error);
|
||||||
return Privacy.redactAll(normalizedError.stack);
|
return normalizedError.stack;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,31 +9,36 @@ const APP_ROOT_PATH = Path.join(__dirname, '..', '..', '..');
|
||||||
|
|
||||||
describe('Errors', () => {
|
describe('Errors', () => {
|
||||||
describe('toLogFormat', () => {
|
describe('toLogFormat', () => {
|
||||||
it('should redact sensitive paths in stack trace', () => {
|
it('should convert non-errors to errors', () => {
|
||||||
try {
|
try {
|
||||||
throw new Error('boom');
|
// eslint-disable-next-line no-throw-literal
|
||||||
} catch (error) {
|
throw 'boom';
|
||||||
assert.include(
|
} catch (nonError) {
|
||||||
error.stack,
|
assert.typeOf(nonError, 'string');
|
||||||
APP_ROOT_PATH,
|
assert.isUndefined(nonError.stack);
|
||||||
'Unformatted stack has sensitive paths'
|
|
||||||
);
|
|
||||||
|
|
||||||
const formattedStack = Errors.toLogFormat(error);
|
const formattedStack = Errors.toLogFormat(nonError);
|
||||||
assert.notInclude(
|
|
||||||
formattedStack,
|
|
||||||
APP_ROOT_PATH,
|
|
||||||
'Formatted stack does not have sensitive paths'
|
|
||||||
);
|
|
||||||
assert.include(
|
assert.include(
|
||||||
formattedStack,
|
formattedStack,
|
||||||
'[REDACTED]',
|
APP_ROOT_PATH,
|
||||||
'Formatted stack has redactions'
|
'Formatted stack has app path'
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-unreachable
|
// eslint-disable-next-line no-unreachable
|
||||||
assert.fail('Expected error to be thrown.');
|
assert.fail('Expected error to be thrown.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should add stack to errors without one', () => {
|
||||||
|
const error = new Error('boom');
|
||||||
|
error.stack = null;
|
||||||
|
assert.typeOf(error, 'Error');
|
||||||
|
assert.isNull(error.stack);
|
||||||
|
|
||||||
|
const formattedStack = Errors.toLogFormat(error);
|
||||||
|
assert.include(formattedStack, '<Original stack missing>');
|
||||||
|
assert.include(formattedStack, APP_ROOT_PATH, 'Formatted stack has app path');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue