mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
ba3914e9fe
* Sanitize privacy sensitive data before sending to sentry. Temp Near complete Complete * Temp * Fix url error message rewrite * Add unit tests and cleanup code * Improvements * Update app/scripts/lib/setupSentry.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update app/scripts/lib/setupSentry.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update app/scripts/lib/setupSentry.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Fix syntax of doc comments * Catch errors caused by invalid urls in sanitizeUrlsFromErrorMessages * Ensure our allowlist matches multiple subdomains * Ensure sanitizeUrlsFromErrorMessages correctly matches hostnames * Update app/scripts/lib/setupSentry.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Improve test descriptions * fix Co-authored-by: Ariella Vu <20778143+digiwand@users.noreply.github.com> Co-authored-by: Mark Stacey <markjstacey@gmail.com>
242 lines
8.0 KiB
JavaScript
242 lines
8.0 KiB
JavaScript
import { rewriteReport, removeUrlsFromBreadCrumb } from './setupSentry';
|
|
|
|
describe('Setup Sentry', () => {
|
|
describe('rewriteReport', () => {
|
|
it('should remove urls from error messages', () => {
|
|
const testReport = {
|
|
message: 'This report has a test url: http://example.com',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual(
|
|
'This report has a test url: **',
|
|
);
|
|
});
|
|
|
|
it('should remove urls from error reports that have an exception with an array of values', () => {
|
|
const testReport = {
|
|
exception: {
|
|
values: [
|
|
{
|
|
value: 'This report has a test url: http://example.com',
|
|
},
|
|
{
|
|
value: 'https://example.com is another url',
|
|
},
|
|
],
|
|
},
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.exception.values).toStrictEqual([
|
|
{
|
|
value: 'This report has a test url: **',
|
|
},
|
|
{
|
|
value: '** is another url',
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('should remove ethereum addresses from error messages', () => {
|
|
const testReport = {
|
|
message:
|
|
'There is an ethereum address 0x790A8A9E9bc1C9dB991D8721a92e461Db4CfB235 in this message',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual(
|
|
'There is an ethereum address 0x** in this message',
|
|
);
|
|
});
|
|
|
|
it('should not remove urls from our allow list', () => {
|
|
const testReport = {
|
|
message: 'This report has an allowed url: https://codefi.network/',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual(
|
|
'This report has an allowed url: https://codefi.network/',
|
|
);
|
|
});
|
|
|
|
it('should not remove urls at subdomains of the urls in the allow list', () => {
|
|
const testReport = {
|
|
message:
|
|
'This report has an allowed url: https://subdomain.codefi.network/',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual(
|
|
'This report has an allowed url: https://subdomain.codefi.network/',
|
|
);
|
|
});
|
|
|
|
it('should remove urls very similar to, but different from, those in our allow list', () => {
|
|
const testReport = {
|
|
message:
|
|
'This report does not have an allowed url: https://nodefi.network/',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual(
|
|
'This report does not have an allowed url: **',
|
|
);
|
|
});
|
|
|
|
it('should remove urls with allow list urls in their domain path', () => {
|
|
const testReport = {
|
|
message:
|
|
'This report does not have an allowed url: https://codefi.network.another.domain.com/',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual(
|
|
'This report does not have an allowed url: **',
|
|
);
|
|
});
|
|
|
|
it('should remove urls have allowed urls in their URL path', () => {
|
|
const testReport = {
|
|
message:
|
|
'This report does not have an allowed url: https://example.com/test?redirect=http://codefi.network',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual(
|
|
'This report does not have an allowed url: **',
|
|
);
|
|
});
|
|
|
|
it('should remove urls with subdomains', () => {
|
|
const testReport = {
|
|
message:
|
|
'This report does not have an allowed url: https://subdomain.example.com/',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual(
|
|
'This report does not have an allowed url: **',
|
|
);
|
|
});
|
|
|
|
it('should remove invalid urls', () => {
|
|
const testReport = {
|
|
message:
|
|
'This report does not have an allowed url: https://example.%%%/',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual(
|
|
'This report does not have an allowed url: **',
|
|
);
|
|
});
|
|
|
|
it('should remove urls and ethereum addresses from error messages', () => {
|
|
const testReport = {
|
|
message:
|
|
'This 0x790A8A9E9bc1C9dB991D8721a92e461Db4CfB235 address used http://example.com on Saturday',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual(
|
|
'This 0x** address used ** on Saturday',
|
|
);
|
|
});
|
|
|
|
it('should not modify an error message with no urls or addresses', () => {
|
|
const testReport = {
|
|
message: 'This is a simple report',
|
|
request: {},
|
|
};
|
|
const rewrittenReport = rewriteReport(testReport);
|
|
expect(rewrittenReport.message).toStrictEqual('This is a simple report');
|
|
});
|
|
});
|
|
|
|
describe('removeUrlsFromBreadCrumb', () => {
|
|
it('should hide the breadcrumb data url', () => {
|
|
const testBreadcrumb = {
|
|
data: {
|
|
url: 'https://example.com',
|
|
},
|
|
};
|
|
const rewrittenBreadcrumb = removeUrlsFromBreadCrumb(testBreadcrumb);
|
|
expect(rewrittenBreadcrumb.data.url).toStrictEqual('');
|
|
});
|
|
|
|
it('should hide the breadcrumb data "to" page', () => {
|
|
const testBreadcrumb = {
|
|
data: {
|
|
to: 'https://example.com',
|
|
},
|
|
};
|
|
const rewrittenBreadcrumb = removeUrlsFromBreadCrumb(testBreadcrumb);
|
|
expect(rewrittenBreadcrumb.data.to).toStrictEqual('');
|
|
});
|
|
|
|
it('should hide the breadcrumb data "from" page', () => {
|
|
const testBreadcrumb = {
|
|
data: {
|
|
from: 'https://example.com',
|
|
},
|
|
};
|
|
const rewrittenBreadcrumb = removeUrlsFromBreadCrumb(testBreadcrumb);
|
|
expect(rewrittenBreadcrumb.data.from).toStrictEqual('');
|
|
});
|
|
|
|
it('should NOT hide the breadcrumb data url if the url is on the extension protocol', () => {
|
|
const testBreadcrumb = {
|
|
data: {
|
|
url: 'chrome-extension://abcefg/home.html',
|
|
},
|
|
};
|
|
const rewrittenBreadcrumb = removeUrlsFromBreadCrumb(testBreadcrumb);
|
|
expect(rewrittenBreadcrumb.data.url).toStrictEqual(
|
|
'chrome-extension://abcefg/home.html',
|
|
);
|
|
});
|
|
|
|
it('should NOT hide the breadcrumb data "to" page if the url is on the extension protocol', () => {
|
|
const testBreadcrumb = {
|
|
data: {
|
|
to: 'chrome-extension://abcefg/home.html',
|
|
},
|
|
};
|
|
const rewrittenBreadcrumb = removeUrlsFromBreadCrumb(testBreadcrumb);
|
|
expect(rewrittenBreadcrumb.data.to).toStrictEqual(
|
|
'chrome-extension://abcefg/home.html',
|
|
);
|
|
});
|
|
|
|
it('should NOT hide the breadcrumb data "from" page if the url is on the extension protocol', () => {
|
|
const testBreadcrumb = {
|
|
data: {
|
|
from: 'chrome-extension://abcefg/home.html',
|
|
},
|
|
};
|
|
const rewrittenBreadcrumb = removeUrlsFromBreadCrumb(testBreadcrumb);
|
|
expect(rewrittenBreadcrumb.data.from).toStrictEqual(
|
|
'chrome-extension://abcefg/home.html',
|
|
);
|
|
});
|
|
|
|
it('should hide "to" but not "from" or url if "to" is the only one not matching an internal url', () => {
|
|
const testBreadcrumb = {
|
|
data: {
|
|
url: 'chrome-extension://abcefg/home.html',
|
|
to: 'https://example.com',
|
|
from: 'chrome-extension://abcefg/home.html',
|
|
},
|
|
};
|
|
const rewrittenBreadcrumb = removeUrlsFromBreadCrumb(testBreadcrumb);
|
|
expect(rewrittenBreadcrumb.data).toStrictEqual({
|
|
url: 'chrome-extension://abcefg/home.html',
|
|
to: '',
|
|
from: 'chrome-extension://abcefg/home.html',
|
|
});
|
|
});
|
|
});
|
|
});
|