1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00
metamask-extension/test/e2e/mv3/phishing-warning-sw-restart.spec.js
Nicholas Ellul b76875ac69
Update @metamask/phishing-controller to v4.0.0 (#18840)
* Update phishing controller to v4.0.0

* Move phishing e2e test utilities into its own helper.js

* Update phishing detection e2e test

* Update MetaMask Controller test mocks

* Update mv3 phishing tests

* Fix test for 500 error on warning page

* Allow for directories in test folder

* Update migration number

* Linting fixes

* Remove fail on console error

* Separate mocks from helpers

* Have migration delete PhishingController state entirely

* Remove phishing detection directory

* Only delete the listState in migration

* Bump migration version
2023-07-31 10:18:48 -02:30

79 lines
2.3 KiB
JavaScript

const { strict: assert } = require('assert');
const FixtureBuilder = require('../fixture-builder');
const {
withFixtures,
openDapp,
defaultGanacheOptions,
assertAccountBalanceForDOM,
SERVICE_WORKER_URL,
regularDelayMs,
WALLET_PASSWORD,
unlockWallet,
terminateServiceWorker,
} = require('../helpers');
const {
setupPhishingDetectionMocks,
BlockProvider,
} = require('../tests/phishing-controller/helpers');
describe('Phishing warning page', function () {
const driverOptions = { openDevToolsForTabs: true };
it('should restore the transaction when service worker restarts', async function () {
let windowHandles;
await withFixtures(
{
fixtures: new FixtureBuilder().build(),
ganacheOptions: defaultGanacheOptions,
title: this.test.title,
driverOptions,
testSpecificMock: async (mockServer) => {
return setupPhishingDetectionMocks(mockServer, {
blockProvider: BlockProvider.MetaMask,
blocklist: ['127.0.0.1'],
});
},
dapp: true,
},
async ({ driver, ganacheServer }) => {
await driver.navigate();
await unlockWallet(driver, WALLET_PASSWORD);
// DAPP is detected as phishing page
await openDapp(driver);
const phishingPageHeader = await driver.findElements({
text: 'Deceptive site ahead',
tag: 'h1',
});
assert.ok(phishingPageHeader.length, 1);
// Restart service worker
await driver.openNewPage(SERVICE_WORKER_URL);
await terminateServiceWorker(driver);
await driver.delay(regularDelayMs);
// wait until extension is reloaded
windowHandles = await driver.getAllWindowHandles();
const extension = windowHandles[0];
await driver.switchToWindow(extension);
await assertAccountBalanceForDOM(driver, ganacheServer);
// Open the dapp site and extension detect it as phishing warning page
await openDapp(driver);
// - extension, dapp, service worker and new dapp
await driver.waitUntilXWindowHandles(4);
const newPhishingPageHeader = await driver.findElements({
text: 'Deceptive site ahead',
tag: 'h1',
});
assert.ok(newPhishingPageHeader.length, 1);
},
);
});
});