1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

feat(882): Ensure user's IP address is not leaked to third parties before opting-out (#20101)

This commit is contained in:
Danica Shen 2023-07-19 20:56:31 +01:00 committed by GitHub
parent 39b1996aab
commit cc3ef534ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 55 deletions

View File

@ -313,10 +313,10 @@ const onboardingBeginCreateNewWallet = async (driver) => {
* Choose either "I Agree" or "No Thanks" on the MetaMetrics onboarding screen * Choose either "I Agree" or "No Thanks" on the MetaMetrics onboarding screen
* *
* @param {WebDriver} driver * @param {WebDriver} driver
* @param {boolean} optin - true to opt into metrics, default is false * @param {boolean} option - true to opt into metrics, default is false
*/ */
const onboardingChooseMetametricsOption = async (driver, optin = false) => { const onboardingChooseMetametricsOption = async (driver, option = false) => {
const optionIdentifier = optin ? 'i-agree' : 'no-thanks'; const optionIdentifier = option ? 'i-agree' : 'no-thanks';
// metrics // metrics
await driver.clickElement(`[data-testid="metametrics-${optionIdentifier}"]`); await driver.clickElement(`[data-testid="metametrics-${optionIdentifier}"]`);
}; };
@ -744,15 +744,17 @@ async function switchToNotificationWindow(driver) {
* *
* @param {WebDriver} driver * @param {WebDriver} driver
* @param {import('mockttp').Mockttp} mockedEndpoints * @param {import('mockttp').Mockttp} mockedEndpoints
* @param {boolean} hasRequest
* @returns {import('mockttp/dist/pluggable-admin').MockttpClientResponse[]} * @returns {import('mockttp/dist/pluggable-admin').MockttpClientResponse[]}
*/ */
async function getEventPayloads(driver, mockedEndpoints) { async function getEventPayloads(driver, mockedEndpoints, hasRequest = true) {
await driver.wait(async () => { await driver.wait(async () => {
let isPending = true; let isPending = true;
for (const mockedEndpoint of mockedEndpoints) { for (const mockedEndpoint of mockedEndpoints) {
isPending = await mockedEndpoint.isPending(); isPending = await mockedEndpoint.isPending();
} }
return isPending === false;
return isPending === !hasRequest;
}, 10000); }, 10000);
const mockedRequests = []; const mockedRequests = [];
for (const mockedEndpoint of mockedEndpoints) { for (const mockedEndpoint of mockedEndpoints) {

View File

@ -5,6 +5,7 @@ const {
withFixtures, withFixtures,
openDapp, openDapp,
unlockWallet, unlockWallet,
getEventPayloads,
} = require('../helpers'); } = require('../helpers');
const FixtureBuilder = require('../fixture-builder'); const FixtureBuilder = require('../fixture-builder');
@ -43,28 +44,6 @@ async function mockSegment(mockServer) {
]; ];
} }
/**
* This method handles getting the mocked requests to the segment server
*
* @param {WebDriver} driver
* @param {import('mockttp').Mockttp} mockedEndpoints
* @returns {import('mockttp/dist/pluggable-admin').MockttpClientResponse[]}
*/
async function getEventPayloads(driver, mockedEndpoints) {
await driver.wait(async () => {
let isPending = true;
for (const mockedEndpoint of mockedEndpoints) {
isPending = await mockedEndpoint.isPending();
}
return isPending === false;
}, 10000);
const mockedRequests = [];
for (const mockedEndpoint of mockedEndpoints) {
mockedRequests.push(...(await mockedEndpoint.getSeenRequests()));
}
return mockedRequests.map((req) => req.body.json.batch).flat();
}
describe('Permissions Approved Event', function () { describe('Permissions Approved Event', function () {
it('Successfully tracked when connecting to dapp', async function () { it('Successfully tracked when connecting to dapp', async function () {
await withFixtures( await withFixtures(

View File

@ -1,8 +1,12 @@
const { strict: assert } = require('assert'); const { strict: assert } = require('assert');
const { convertToHexValue, withFixtures } = require('../helpers'); const {
withFixtures,
unlockWallet,
defaultGanacheOptions,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder'); const FixtureBuilder = require('../fixture-builder');
describe('Segment metrics', function () { describe('Unlock wallet', function () {
async function mockSegment(mockServer) { async function mockSegment(mockServer) {
return await mockServer return await mockServer
.forPost('https://api.segment.io/v1/batch') .forPost('https://api.segment.io/v1/batch')
@ -14,15 +18,7 @@ describe('Segment metrics', function () {
}; };
}); });
} }
const ganacheOptions = {
accounts: [
{
secretKey:
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
balance: convertToHexValue(25000000000000000000),
},
],
};
it('should send first three Page metric events upon fullscreen page load', async function () { it('should send first three Page metric events upon fullscreen page load', async function () {
await withFixtures( await withFixtures(
{ {
@ -32,14 +28,13 @@ describe('Segment metrics', function () {
participateInMetaMetrics: true, participateInMetaMetrics: true,
}) })
.build(), .build(),
ganacheOptions, ganacheOptions: defaultGanacheOptions,
title: this.test.title, title: this.test.title,
testSpecificMock: mockSegment, testSpecificMock: mockSegment,
}, },
async ({ driver, mockedEndpoint }) => { async ({ driver, mockedEndpoint }) => {
await driver.navigate(); await driver.navigate();
await driver.fill('#password', 'correct horse battery staple'); await unlockWallet(driver);
await driver.press('#password', driver.Key.ENTER);
await driver.wait(async () => { await driver.wait(async () => {
const isPending = await mockedEndpoint.isPending(); const isPending = await mockedEndpoint.isPending();
return isPending === false; return isPending === false;
@ -47,19 +42,17 @@ describe('Segment metrics', function () {
const mockedRequests = await mockedEndpoint.getSeenRequests(); const mockedRequests = await mockedEndpoint.getSeenRequests();
assert.equal(mockedRequests.length, 3); assert.equal(mockedRequests.length, 3);
const [firstMock, secondMock, thirdMock] = mockedRequests; const [firstMock, secondMock, thirdMock] = mockedRequests;
let [mockJson] = firstMock.body.json.batch; assertBatchValue(firstMock, 'Home', '/');
let { title, path } = mockJson.context.page; assertBatchValue(secondMock, 'Unlock Page', '/unlock');
assert.equal(title, 'Home'); assertBatchValue(thirdMock, 'Home', '/');
assert.equal(path, '/');
[mockJson] = secondMock.body.json.batch;
({ title, path } = mockJson.context.page);
assert.equal(title, 'Unlock Page');
assert.equal(path, '/unlock');
[mockJson] = thirdMock.body.json.batch;
({ title, path } = mockJson.context.page);
assert.equal(title, 'Home');
assert.equal(path, '/');
}, },
); );
}); });
}); });
function assertBatchValue(mockRequest, assertedTitle, assertedPath) {
const [mockJson] = mockRequest.body.json.batch;
const { title, path } = mockJson.context.page;
assert.equal(title, assertedTitle);
assert.equal(path, assertedPath);
}

View File

@ -48,8 +48,8 @@ async function mockSegment(mockServer) {
]; ];
} }
describe('Wallet Created Event', function () { describe('Wallet Created Events', function () {
it('Successfully tracked when onboarding', async function () { it('are sent when onboarding user who chooses to opt in metrics', async function () {
await withFixtures( await withFixtures(
{ {
fixtures: new FixtureBuilder({ onboarding: true }) fixtures: new FixtureBuilder({ onboarding: true })
@ -73,6 +73,7 @@ describe('Wallet Created Event', function () {
await onboardingPinExtension(driver); await onboardingPinExtension(driver);
const events = await getEventPayloads(driver, mockedEndpoints); const events = await getEventPayloads(driver, mockedEndpoints);
assert.equal(events.length, 2);
assert.deepStrictEqual(events[0].properties, { assert.deepStrictEqual(events[0].properties, {
account_type: 'metamask', account_type: 'metamask',
category: 'Onboarding', category: 'Onboarding',
@ -90,4 +91,36 @@ describe('Wallet Created Event', function () {
}, },
); );
}); });
it('are not sent when onboarding user who chooses to opt out metrics', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder({ onboarding: true })
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
})
.build(),
defaultGanacheOptions,
title: this.test.title,
testSpecificMock: mockSegment,
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await driver.navigate();
await onboardingBeginCreateNewWallet(driver);
await onboardingChooseMetametricsOption(driver, false);
await onboardingCreatePassword(driver, WALLET_PASSWORD);
await onboardingRevealAndConfirmSRP(driver);
await onboardingCompleteWalletCreation(driver);
await onboardingPinExtension(driver);
const mockedRequests = await getEventPayloads(
driver,
mockedEndpoints,
false,
);
assert.equal(mockedRequests.length, 0);
},
);
});
}); });

View File

@ -101,6 +101,7 @@ export default function OnboardingWelcome() {
message_title: t('welcomeToMetaMask'), message_title: t('welcomeToMetaMask'),
app_version: global?.platform?.getVersion(), app_version: global?.platform?.getVersion(),
}, },
addEventBeforeMetricsOptIn: true,
}); });
return ( return (