mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-25 11:28:51 +01:00
feature(16691): mv3 e2e test for phishing warning page when sw restarts (#19196)
* feature(16691): mv3 e2e test for phishing warning page when sw restarts * feature(16691): code review feedback to remove console and extract helper
This commit is contained in:
parent
ab4ef4f744
commit
fd8b81def0
@ -391,10 +391,100 @@ const openDapp = async (driver, contract = null, dappURL = DAPP_URL) => {
|
||||
? await driver.openNewPage(`${dappURL}/?contract=${contract}`)
|
||||
: await driver.openNewPage(dappURL);
|
||||
};
|
||||
const STALELIST_URL =
|
||||
'https://static.metafi.codefi.network/api/v1/lists/stalelist.json';
|
||||
|
||||
const emptyHtmlPage = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>title</title>
|
||||
</head>
|
||||
<body>
|
||||
Empty page
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
/**
|
||||
* Setup fetch mocks for the phishing detection feature.
|
||||
*
|
||||
* The mock configuration will show that "127.0.0.1" is blocked. The dynamic lookup on the warning
|
||||
* page can be customized, so that we can test both the MetaMask and PhishFort block cases.
|
||||
*
|
||||
* @param {import('mockttp').Mockttp} mockServer - The mock server.
|
||||
* @param {object} metamaskPhishingConfigResponse - The response for the dynamic phishing
|
||||
* configuration lookup performed by the warning page.
|
||||
*/
|
||||
async function setupPhishingDetectionMocks(
|
||||
mockServer,
|
||||
metamaskPhishingConfigResponse,
|
||||
) {
|
||||
await mockServer.forGet(STALELIST_URL).thenCallback(() => {
|
||||
return {
|
||||
statusCode: 200,
|
||||
json: {
|
||||
version: 2,
|
||||
tolerance: 2,
|
||||
fuzzylist: [],
|
||||
allowlist: [],
|
||||
blocklist: ['127.0.0.1'],
|
||||
lastUpdated: 0,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
await mockServer
|
||||
.forGet('https://github.com/MetaMask/eth-phishing-detect/issues/new')
|
||||
.thenCallback(() => {
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: emptyHtmlPage,
|
||||
};
|
||||
});
|
||||
await mockServer
|
||||
.forGet('https://github.com/phishfort/phishfort-lists/issues/new')
|
||||
.thenCallback(() => {
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: emptyHtmlPage,
|
||||
};
|
||||
});
|
||||
|
||||
await mockServer
|
||||
.forGet(
|
||||
'https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/master/src/config.json',
|
||||
)
|
||||
.thenCallback(() => metamaskPhishingConfigResponse);
|
||||
}
|
||||
|
||||
function mockPhishingDetection(mockServer) {
|
||||
setupPhishingDetectionMocks(mockServer, {
|
||||
statusCode: 200,
|
||||
json: {
|
||||
version: 2,
|
||||
tolerance: 2,
|
||||
fuzzylist: [],
|
||||
whitelist: [],
|
||||
blacklist: ['127.0.0.1'],
|
||||
lastUpdated: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const PRIVATE_KEY =
|
||||
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC';
|
||||
|
||||
const generateETHBalance = (eth) => convertToHexValue(eth * 10 ** 18);
|
||||
const defaultGanacheOptions = {
|
||||
accounts: [{ secretKey: PRIVATE_KEY, balance: generateETHBalance(25) }],
|
||||
};
|
||||
|
||||
const SERVICE_WORKER_URL = 'chrome://inspect/#service-workers';
|
||||
|
||||
module.exports = {
|
||||
DAPP_URL,
|
||||
DAPP_ONE_URL,
|
||||
SERVICE_WORKER_URL,
|
||||
getWindowHandles,
|
||||
convertToHexValue,
|
||||
tinyDelayMs,
|
||||
@ -410,4 +500,7 @@ module.exports = {
|
||||
importWrongSRPOnboardingFlow,
|
||||
testSRPDropdownIterations,
|
||||
openDapp,
|
||||
mockPhishingDetection,
|
||||
setupPhishingDetectionMocks,
|
||||
defaultGanacheOptions,
|
||||
};
|
||||
|
@ -1,5 +1,10 @@
|
||||
const { strict: assert } = require('assert');
|
||||
const { convertToHexValue, withFixtures, openDapp } = require('../helpers');
|
||||
const {
|
||||
convertToHexValue,
|
||||
withFixtures,
|
||||
openDapp,
|
||||
SERVICE_WORKER_URL,
|
||||
} = require('../helpers');
|
||||
const FixtureBuilder = require('../fixture-builder');
|
||||
|
||||
describe('MV3 - Dapp interactions', function () {
|
||||
@ -34,7 +39,7 @@ describe('MV3 - Dapp interactions', function () {
|
||||
await openDapp(driver);
|
||||
|
||||
// Terminate Service Worker
|
||||
await driver.openNewPage('chrome://inspect/#service-workers/');
|
||||
await driver.openNewPage(SERVICE_WORKER_URL);
|
||||
await driver.clickElement({
|
||||
text: 'Service workers',
|
||||
tag: 'button',
|
||||
|
52
test/e2e/mv3/phishing-warning-sw-restart.spec.js
Normal file
52
test/e2e/mv3/phishing-warning-sw-restart.spec.js
Normal file
@ -0,0 +1,52 @@
|
||||
const { strict: assert } = require('assert');
|
||||
const {
|
||||
withFixtures,
|
||||
mockPhishingDetection,
|
||||
SERVICE_WORKER_URL,
|
||||
openDapp,
|
||||
defaultGanacheOptions,
|
||||
} = require('../helpers');
|
||||
const FixtureBuilder = require('../fixture-builder');
|
||||
|
||||
describe('Phishing warning page', function () {
|
||||
it('should restore the transaction when service worker restarts', async function () {
|
||||
await withFixtures(
|
||||
{
|
||||
dapp: true,
|
||||
fixtures: new FixtureBuilder().build(),
|
||||
ganacheOptions: defaultGanacheOptions,
|
||||
title: this.test.title,
|
||||
testSpecificMock: mockPhishingDetection,
|
||||
},
|
||||
async ({ driver }) => {
|
||||
await driver.navigate();
|
||||
// log in wallet
|
||||
await driver.fill('#password', 'correct horse battery staple');
|
||||
await driver.press('#password', driver.Key.ENTER);
|
||||
|
||||
// Restart service worker
|
||||
await driver.openNewPage(SERVICE_WORKER_URL);
|
||||
|
||||
await driver.clickElement({
|
||||
text: 'Service workers',
|
||||
tag: 'button',
|
||||
});
|
||||
|
||||
await driver.clickElement({
|
||||
text: 'terminate',
|
||||
tag: 'span',
|
||||
});
|
||||
|
||||
// Open the dapp site and extension detect it as phishing warning page
|
||||
await openDapp(driver);
|
||||
|
||||
await driver.switchToWindowWithTitle('MetaMask Phishing Detection');
|
||||
const phishingPageHeader = await driver.findElements({
|
||||
text: 'Deceptive site ahead',
|
||||
tag: 'h1',
|
||||
});
|
||||
assert.ok(phishingPageHeader.length, 1);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
@ -1,5 +1,12 @@
|
||||
const { strict: assert } = require('assert');
|
||||
const { convertToHexValue, withFixtures, openDapp } = require('../helpers');
|
||||
|
||||
const {
|
||||
convertToHexValue,
|
||||
withFixtures,
|
||||
openDapp,
|
||||
SERVICE_WORKER_URL,
|
||||
defaultGanacheOptions,
|
||||
} = require('../helpers');
|
||||
const FixtureBuilder = require('../fixture-builder');
|
||||
const {
|
||||
ACTION_QUEUE_METRICS_E2E_TEST,
|
||||
@ -9,14 +16,6 @@ const {
|
||||
MetaMetricsEventCategory,
|
||||
} = require('../../../shared/constants/metametrics');
|
||||
|
||||
const PRIVATE_KEY =
|
||||
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC';
|
||||
|
||||
const generateETHBalance = (eth) => convertToHexValue(eth * 10 ** 18);
|
||||
const defaultGanacheOptions = {
|
||||
accounts: [{ secretKey: PRIVATE_KEY, balance: generateETHBalance(25) }],
|
||||
};
|
||||
|
||||
const numberOfSegmentRequests = 3;
|
||||
|
||||
async function mockSegment(mockServer) {
|
||||
@ -76,7 +75,7 @@ describe('MV3 - Service worker restart', function () {
|
||||
|
||||
await driver.clickElement({ text: 'Create', tag: 'button' });
|
||||
|
||||
await driver.openNewPage('chrome://inspect/#service-workers/');
|
||||
await driver.openNewPage(SERVICE_WORKER_URL);
|
||||
await driver.clickElement({
|
||||
text: 'Service workers',
|
||||
tag: 'button',
|
||||
@ -159,7 +158,7 @@ describe('MV3 - Service worker restart', function () {
|
||||
// Restart service worker in a new window
|
||||
// Because if we stay in the same window we will lose the popup when opening a new tab
|
||||
await driver.switchToNewWindow();
|
||||
await driver.openNewURL('chrome://inspect/#service-workers');
|
||||
await driver.openNewURL(SERVICE_WORKER_URL);
|
||||
windowHandles = await driver.getAllWindowHandles();
|
||||
// MM expanded view, Dapp, Notification popup, console and service worker
|
||||
await driver.waitUntilXWindowHandles(5);
|
||||
|
@ -1,88 +1,14 @@
|
||||
const { strict: assert } = require('assert');
|
||||
const { convertToHexValue, withFixtures, openDapp } = require('../helpers');
|
||||
const {
|
||||
convertToHexValue,
|
||||
withFixtures,
|
||||
openDapp,
|
||||
setupPhishingDetectionMocks,
|
||||
mockPhishingDetection,
|
||||
} = require('../helpers');
|
||||
const FixtureBuilder = require('../fixture-builder');
|
||||
|
||||
const STALELIST_URL =
|
||||
'https://static.metafi.codefi.network/api/v1/lists/stalelist.json';
|
||||
|
||||
const emptyHtmlPage = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>title</title>
|
||||
</head>
|
||||
<body>
|
||||
Empty page
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
/**
|
||||
* Setup fetch mocks for the phishing detection feature.
|
||||
*
|
||||
* The mock configuration will show that "127.0.0.1" is blocked. The dynamic lookup on the warning
|
||||
* page can be customized, so that we can test both the MetaMask and PhishFort block cases.
|
||||
*
|
||||
* @param {import('mockttp').Mockttp} mockServer - The mock server.
|
||||
* @param {object} metamaskPhishingConfigResponse - The response for the dynamic phishing
|
||||
* configuration lookup performed by the warning page.
|
||||
*/
|
||||
async function setupPhishingDetectionMocks(
|
||||
mockServer,
|
||||
metamaskPhishingConfigResponse,
|
||||
) {
|
||||
await mockServer.forGet(STALELIST_URL).thenCallback(() => {
|
||||
return {
|
||||
statusCode: 200,
|
||||
json: {
|
||||
version: 2,
|
||||
tolerance: 2,
|
||||
fuzzylist: [],
|
||||
allowlist: [],
|
||||
blocklist: ['127.0.0.1'],
|
||||
lastUpdated: 0,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
await mockServer
|
||||
.forGet('https://github.com/MetaMask/eth-phishing-detect/issues/new')
|
||||
.thenCallback(() => {
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: emptyHtmlPage,
|
||||
};
|
||||
});
|
||||
await mockServer
|
||||
.forGet('https://github.com/phishfort/phishfort-lists/issues/new')
|
||||
.thenCallback(() => {
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: emptyHtmlPage,
|
||||
};
|
||||
});
|
||||
|
||||
await mockServer
|
||||
.forGet(
|
||||
'https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/master/src/config.json',
|
||||
)
|
||||
.thenCallback(() => metamaskPhishingConfigResponse);
|
||||
}
|
||||
|
||||
describe('Phishing Detection', function () {
|
||||
function mockPhishingDetection(mockServer) {
|
||||
setupPhishingDetectionMocks(mockServer, {
|
||||
statusCode: 200,
|
||||
json: {
|
||||
version: 2,
|
||||
tolerance: 2,
|
||||
fuzzylist: [],
|
||||
whitelist: [],
|
||||
blacklist: ['127.0.0.1'],
|
||||
lastUpdated: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const ganacheOptions = {
|
||||
accounts: [
|
||||
{
|
||||
|
@ -403,6 +403,10 @@ class Driver {
|
||||
throw new Error(`No window with title: ${title}`);
|
||||
}
|
||||
|
||||
async closeWindow() {
|
||||
await this.driver.close();
|
||||
}
|
||||
|
||||
// Close Alert Popup
|
||||
async closeAlertPopup() {
|
||||
return await this.driver.switchTo().alert().accept();
|
||||
|
Loading…
Reference in New Issue
Block a user