1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

E2e phishing detection (#13704)

* phishing detection test

* remove unused arg
This commit is contained in:
PeterYinusa 2022-02-22 16:48:12 +00:00 committed by GitHub
parent 575cedf2aa
commit 30b2afe7bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 2 deletions

View File

@ -1,4 +1,4 @@
function setupMocking(server) {
function setupMocking(server, testSpecificMock) {
server.forAnyRequest().thenPassThrough();
server
@ -27,6 +27,8 @@ function setupMocking(server) {
},
};
});
testSpecificMock(server);
}
module.exports = { setupMocking };

View File

@ -29,6 +29,9 @@ async function withFixtures(options, testSuite) {
title,
failOnConsoleError = true,
dappPath = undefined,
testSpecificMock = function () {
// do nothing.
},
} = options;
const fixtureServer = new FixtureServer();
const ganacheServer = new Ganache();
@ -89,8 +92,8 @@ async function withFixtures(options, testSuite) {
}
const https = await mockttp.generateCACertificate();
mockServer = mockttp.getLocal({ https });
setupMocking(mockServer, testSpecificMock);
await mockServer.start(8000);
setupMocking(mockServer);
if (
process.env.SELENIUM_BROWSER === 'chrome' &&
process.env.CI === 'true'

View File

@ -0,0 +1,53 @@
const { strict: assert } = require('assert');
const { convertToHexValue, withFixtures } = require('../helpers');
describe('Phishing Detection', function () {
function mockPhishingDetection(mockServer) {
mockServer
.forGet(
'https://cdn.jsdelivr.net/gh/MetaMask/eth-phishing-detect@master/src/config.json',
)
.thenCallback(() => {
return {
headers: { 'Access-Control-Allow-Origin': '*' },
statusCode: 200,
json: {
version: 2,
tolerance: 2,
fuzzylist: [],
whitelist: [],
blacklist: ['example.com'],
},
};
});
}
const ganacheOptions = {
accounts: [
{
secretKey:
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
balance: convertToHexValue(25000000000000000000),
},
],
};
it('should display the MetaMask Phishing Detection page', async function () {
await withFixtures(
{
fixtures: 'imported-account',
ganacheOptions,
title: this.test.title,
testSpecificMock: mockPhishingDetection,
},
async ({ driver }) => {
await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
await driver.navigate();
await driver.openNewPage('http://example.com');
await driver.waitForSelector({ text: 'continuing at your own risk' });
const header = await driver.findElement('h1');
assert.equal(await header.getText(), 'MetaMask Phishing Detection');
},
);
});
});