fix logs privacy test

pull/2242/head
Audric Ackermann 3 years ago
parent 7c1707f48e
commit dbcae0f844
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -0,0 +1,101 @@
// tslint:disable: no-implicit-dependencies max-func-body-length no-unused-expression
import chai, { expect } from 'chai';
import { describe } from 'mocha';
import path from 'path';
import chaiAsPromised from 'chai-as-promised';
import { redactAll } from '../../../../util/privacy';
chai.use(chaiAsPromised as any);
// tslint:disable-next-line: max-func-body-length
describe('Privacy', () => {
describe('Redact sessionID', () => {
it('redact sessionID', () => {
expect(
redactAll('052d3096a72d2271bbba0d820729a3548749a2b3890c3b41ea08c4c2722616dd2b')
).to.be.equal('[REDACTED]');
});
it('redact multiple sessionID', () => {
expect(
redactAll(
'052d3096a72d2271bbba0d820729a3548749a2b3890c3b41ea08c4c2722616dd2b 052d3096a72d2271bbba0d820729a3548749a2b3890c3b41ea08c4c2722616dd2c end'
)
).to.be.equal('[REDACTED] [REDACTED] end');
});
it('redact sessionID without the 05 prefix', () => {
expect(
redactAll(
'start 2d3096a72d2271bbba0d820729a3548749a2b3890c3b41ea08c4c2722616dd2b middle 2d3096a72d2271bbba0d820729a3548749a2b3890c3b41ea08c4c2722616dd2c end'
)
).to.be.equal('start [REDACTED] middle [REDACTED] end');
});
});
describe('Redact serverUrl', () => {
it('redact serverUrl https no port', () => {
expect(redactAll('https://example.org')).to.be.equal('[REDACTED]');
});
it('redact serverUrl http no port', () => {
expect(redactAll('http://example.org')).to.be.equal('[REDACTED]');
});
it('redact serverUrl https with port', () => {
expect(redactAll('https://example.org:8080')).to.be.equal('[REDACTED]');
});
it('redact serverUrl http with port', () => {
expect(redactAll('http://example.org:8001')).to.be.equal('[REDACTED]');
});
it('redact serverUrl http with port keep rest of content', () => {
expect(redactAll('start http://example.org:8001 end')).to.be.equal('start [REDACTED] end');
});
it('redact multiple serverUrl http with port keep rest of content', () => {
expect(redactAll('start http://example.org:8001 http://session.org:8003 end')).to.be.equal(
'start [REDACTED] [REDACTED] end'
);
});
});
describe('Redact snodeIP', () => {
it('redact snodeIP no port', () => {
expect(redactAll('127.0.0.1')).to.be.equal('[REDACTED]');
});
it('redact snodeIP with port', () => {
expect(redactAll('127.0.0.1:22')).to.be.equal('[REDACTED]:22');
});
it('redact snodeIP with port multiple', () => {
expect(redactAll('127.0.0.1:8098 127.0.0.1:22 127.0.0.1')).to.be.equal(
'[REDACTED]:8098 [REDACTED]:22 [REDACTED]'
);
});
it('redact snodeIP with port multiple but keep rest of content', () => {
expect(redactAll('start 127.0.0.1:2212 127.0.0.1:2200 middle 127.0.0.1 end')).to.be.equal(
'start [REDACTED]:2212 [REDACTED]:2200 middle [REDACTED] end'
);
});
});
describe('Redact app path', () => {
it('removes whatever is in front of the app root path before logging', () => {
const appRootPath = path.join(__dirname, '..', '..', '..', '..', '..');
const appFolderName = path.basename(appRootPath);
expect(redactAll(appRootPath)).to.be.equal(`[REDACTED]/${appFolderName}`);
});
it('removes whatever is in front of the app root path before logging', () => {
const appRootPath = path.join(__dirname, '..', '..', '..', '..', '..');
const appFolderName = path.basename(appRootPath);
expect(redactAll(appRootPath)).to.be.equal(`[REDACTED]/${appFolderName}`);
});
});
});

@ -8,7 +8,7 @@ import { escapeRegExp, isRegExp, isString } from 'lodash';
const APP_ROOT_PATH = path.join(__dirname, '..', '..', '..');
const SESSION_ID_PATTERN = /\b((05)?[0-9a-f]{64})\b/gi;
const SNODE_PATTERN = /(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
const SNODE_PATTERN = /(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/g;
const GROUP_ID_PATTERN = /(group\()([^)]+)(\))/g;
const SERVER_URL_PATTERN = /https?:\/\/[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g;
const REDACTION_PLACEHOLDER = '[REDACTED]';
@ -63,7 +63,7 @@ const redactSessionID = (text: string) => {
throw new TypeError("'text' must be a string");
}
return text.replace(SESSION_ID_PATTERN, REDACTION_PLACEHOLDER);
return text.replaceAll(SESSION_ID_PATTERN, REDACTION_PLACEHOLDER);
};
const redactSnodeIP = (text: string) => {
@ -71,7 +71,7 @@ const redactSnodeIP = (text: string) => {
throw new TypeError("'text' must be a string");
}
return text.replace(SNODE_PATTERN, REDACTION_PLACEHOLDER);
return text.replaceAll(SNODE_PATTERN, REDACTION_PLACEHOLDER);
};
const redactServerUrl = (text: string) => {
@ -79,7 +79,7 @@ const redactServerUrl = (text: string) => {
throw new TypeError("'text' must be a string");
}
return text.replace(SERVER_URL_PATTERN, REDACTION_PLACEHOLDER);
return text.replaceAll(SERVER_URL_PATTERN, REDACTION_PLACEHOLDER);
};
// redactGroupIds :: String -> String
@ -88,7 +88,7 @@ const redactGroupIds = (text: string) => {
throw new TypeError("'text' must be a string");
}
return text.replace(
return text.replaceAll(
GROUP_ID_PATTERN,
(_match, before, id, after) =>
`${before}${REDACTION_PLACEHOLDER}${removeNewlines(id).slice(-3)}${after}`

Loading…
Cancel
Save