mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-24 02:18:15 +01:00
Add Errors.toLogFormat
Allows errors to be formatted and sanitized for logging. Removes sensitive paths such as the app root directory. Ideally, this module would be called singular `Error` but that is already a global name. Using `Errors` plural is similar to Java convention for utilities such as `Arrays`, `Collections`, `Files`, etc. See: https://stackoverflow.com/a/11673838
This commit is contained in:
39
test/modules/types/errors_test.js
Normal file
39
test/modules/types/errors_test.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const Path = require('path');
|
||||
|
||||
const { assert } = require('chai');
|
||||
|
||||
const Errors = require('../../../js/modules/types/errors');
|
||||
|
||||
|
||||
const APP_ROOT_PATH = Path.join(__dirname, '..', '..', '..');
|
||||
|
||||
describe('Errors', () => {
|
||||
describe('toLogFormat', () => {
|
||||
it('should redact sensitive paths in stack trace', () => {
|
||||
try {
|
||||
throw new Error('boom');
|
||||
} catch (error) {
|
||||
assert.include(
|
||||
error.stack,
|
||||
APP_ROOT_PATH,
|
||||
'Unformatted stack has sensitive paths'
|
||||
);
|
||||
|
||||
const formattedStack = Errors.toLogFormat(error);
|
||||
assert.notInclude(
|
||||
formattedStack,
|
||||
APP_ROOT_PATH,
|
||||
'Formatted stack does not have sensitive paths'
|
||||
);
|
||||
assert.include(
|
||||
formattedStack,
|
||||
'<REDACTED_PATH>',
|
||||
'Formatted stack has redactions'
|
||||
);
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-unreachable
|
||||
assert.fail('Expected error to be thrown.');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user