signal-desktop/test/modules/privacy_test.js

156 lines
5.6 KiB
JavaScript
Raw Normal View History

2018-04-06 16:40:26 +00:00
const path = require('path');
2018-03-06 21:25:43 +00:00
const { assert } = require('chai');
const Privacy = require('../../js/modules/privacy');
2018-04-06 16:40:26 +00:00
const APP_ROOT_PATH = path.join(__dirname, '..', '..', '..');
2018-03-06 21:25:43 +00:00
describe('Privacy', () => {
describe('redactPhoneNumbers', () => {
it('should redact all phone numbers', () => {
2018-04-27 21:25:04 +00:00
const text =
'This is a log line with a phone number +12223334455\n' +
2018-03-06 21:25:43 +00:00
'and another one +13334445566';
const actual = Privacy.redactPhoneNumbers(text);
2018-04-27 21:25:04 +00:00
const expected =
'This is a log line with a phone number +[REDACTED]455\n' +
2018-03-06 21:25:43 +00:00
'and another one +[REDACTED]566';
assert.equal(actual, expected);
});
});
describe('redactGroupIds', () => {
it('should redact all group IDs', () => {
2018-04-27 21:25:04 +00:00
const text =
'This is a log line with two group IDs: group(123456789)\n' +
2018-03-06 21:25:43 +00:00
'and group(abcdefghij)';
const actual = Privacy.redactGroupIds(text);
2018-04-27 21:25:04 +00:00
const expected =
'This is a log line with two group IDs: group([REDACTED]789)\n' +
2018-03-06 21:25:43 +00:00
'and group([REDACTED]hij)';
assert.equal(actual, expected);
});
2018-05-03 15:46:21 +00:00
it('should remove newlines from redacted group IDs', () => {
const text =
'This is a log line with two group IDs: group(12345678\n9)\n' +
'and group(abc\ndefghij)';
const actual = Privacy.redactGroupIds(text);
const expected =
'This is a log line with two group IDs: group([REDACTED]789)\n' +
'and group([REDACTED]hij)';
assert.equal(actual, expected);
});
2018-03-06 21:25:43 +00:00
});
describe('redactAll', () => {
it('should redact all sensitive information', () => {
const encodedAppRootPath = APP_ROOT_PATH.replace(/ /g, '%20');
2018-04-27 21:25:04 +00:00
const text =
'This is a log line with sensitive information:\n' +
2018-03-06 21:25:43 +00:00
`path1 ${APP_ROOT_PATH}/main.js\n` +
'phone1 +12223334455 ipsum\n' +
'group1 group(123456789) doloret\n' +
`path2 file:///${encodedAppRootPath}/js/background.js.` +
2018-03-06 21:25:43 +00:00
'phone2 +13334445566 lorem\n' +
'group2 group(abcdefghij) doloret\n';
const actual = Privacy.redactAll(text);
2018-04-27 21:25:04 +00:00
const expected =
'This is a log line with sensitive information:\n' +
2018-03-06 21:25:43 +00:00
'path1 [REDACTED]/main.js\n' +
'phone1 +[REDACTED]455 ipsum\n' +
'group1 group([REDACTED]789) doloret\n' +
'path2 file:///[REDACTED]/js/background.js.' +
'phone2 +[REDACTED]566 lorem\n' +
'group2 group([REDACTED]hij) doloret\n';
assert.equal(actual, expected);
});
});
describe('_redactPath', () => {
2018-04-06 17:24:43 +00:00
it('should redact file paths', () => {
const testPath = '/Users/meow/Library/Application Support/Signal Beta';
2018-04-27 21:25:04 +00:00
const text =
'This is a log line with sensitive information:\n' +
2018-04-06 17:24:43 +00:00
`path1 ${testPath}/main.js\n` +
'phone1 +12223334455 ipsum\n';
const actual = Privacy._redactPath(testPath)(text);
2018-04-27 21:25:04 +00:00
const expected =
'This is a log line with sensitive information:\n' +
2018-04-06 17:24:43 +00:00
'path1 [REDACTED]/main.js\n' +
'phone1 +12223334455 ipsum\n';
assert.equal(actual, expected);
});
it('should redact URL-encoded paths', () => {
const testPath = '/Users/meow/Library/Application Support/Signal Beta';
const encodedTestPath = encodeURI(testPath);
2018-04-27 21:25:04 +00:00
const text =
'This is a log line with sensitive information:\n' +
`path1 ${testPath}/main.js\n` +
'phone1 +12223334455 ipsum\n' +
'group1 group(123456789) doloret\n' +
`path2 file:///${encodedTestPath}/js/background.js.`;
const actual = Privacy._redactPath(testPath)(text);
2018-04-27 21:25:04 +00:00
const expected =
'This is a log line with sensitive information:\n' +
'path1 [REDACTED]/main.js\n' +
'phone1 +12223334455 ipsum\n' +
'group1 group(123456789) doloret\n' +
'path2 file:///[REDACTED]/js/background.js.';
assert.equal(actual, expected);
});
it('should redact stack traces with both forward and backslashes', () => {
2018-04-27 21:25:04 +00:00
const testPath =
'C:/Users/Meow/AppData/Local/Programs/signal-desktop-beta';
const modifiedTestPath =
'C:\\Users\\Meow\\AppData\\Local\\Programs\\signal-desktop-beta';
2018-04-27 21:25:04 +00:00
const text =
'This is a log line with sensitive information:\n' +
`path1 ${testPath}\\main.js\n` +
'phone1 +12223334455 ipsum\n' +
'group1 group(123456789) doloret\n' +
`path2 ${modifiedTestPath}\\js\\background.js.`;
const actual = Privacy._redactPath(testPath)(text);
2018-04-27 21:25:04 +00:00
const expected =
'This is a log line with sensitive information:\n' +
'path1 [REDACTED]\\main.js\n' +
'phone1 +12223334455 ipsum\n' +
'group1 group(123456789) doloret\n' +
'path2 [REDACTED]\\js\\background.js.';
assert.equal(actual, expected);
});
2018-04-06 18:25:55 +00:00
it('should redact stack traces with escaped backslashes', () => {
2018-04-27 21:25:04 +00:00
const testPath =
'C:\\Users\\Meow\\AppData\\Local\\Programs\\signal-desktop-beta';
2018-04-06 18:25:55 +00:00
const modifiedTestPath =
'C:\\\\Users\\\\Meow\\\\AppData\\\\Local\\\\Programs\\\\signal-desktop-beta';
2018-04-27 21:25:04 +00:00
const text =
'This is a log line with sensitive information:\n' +
2018-04-06 18:25:55 +00:00
`path1 ${testPath}\\main.js\n` +
'phone1 +12223334455 ipsum\n' +
'group1 group(123456789) doloret\n' +
`path2 ${modifiedTestPath}\\js\\background.js.`;
const actual = Privacy._redactPath(testPath)(text);
2018-04-27 21:25:04 +00:00
const expected =
'This is a log line with sensitive information:\n' +
2018-04-06 18:25:55 +00:00
'path1 [REDACTED]\\main.js\n' +
'phone1 +12223334455 ipsum\n' +
'group1 group(123456789) doloret\n' +
'path2 [REDACTED]\\js\\background.js.';
assert.equal(actual, expected);
});
});
2018-03-06 21:25:43 +00:00
});