Skip to content

Commit

Permalink
[e2e] Malicious dapp warning (#1556)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Sinclair <[email protected]>
  • Loading branch information
BrodyHughes and DanielSinclair authored Sep 6, 2024
1 parent 572aa99 commit 6fff157
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 14 deletions.
6 changes: 2 additions & 4 deletions e2e/serial/dappInteractions/1_appInteractionsFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,11 @@ describe.runIf(browser !== 'firefox')('App interactions flow', () => {
rootURL += extensionId;
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
beforeEach(async (context: any) => {
beforeEach<{ driver: WebDriver }>(async (context) => {
context.driver = driver;
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
afterEach(async (context: any) => {
afterEach<{ driver: WebDriver }>(async (context) => {
await takeScreenshotOnFailure(context);
});

Expand Down
6 changes: 2 additions & 4 deletions e2e/serial/dappInteractions/2_dappInteractionFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ describe.runIf(browser !== 'firefox')('App interactions flow', () => {
rootURL += extensionId;
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
beforeEach(async (context: any) => {
beforeEach<{ driver: WebDriver }>(async (context) => {
context.driver = driver;
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
afterEach(async (context: any) => {
afterEach<{ driver: WebDriver }>(async (context) => {
await takeScreenshotOnFailure(context);
});

Expand Down
6 changes: 2 additions & 4 deletions e2e/serial/dappInteractions/3_dappAccountsSwitcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ describe.runIf(browser !== 'firefox')('Dapp accounts switcher flow', () => {
rootURL += extensionId;
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
beforeEach(async (context: any) => {
beforeEach<{ driver: WebDriver }>(async (context) => {
context.driver = driver;
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
afterEach(async (context: any) => {
afterEach<{ driver: WebDriver }>(async (context) => {
await takeScreenshotOnFailure(context);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ describe.runIf(browser !== 'firefox')('Networks & Testnet Mode flows', () => {
});
afterAll(async () => await driver.quit());

// eslint-disable-next-line @typescript-eslint/no-explicit-any
beforeEach<{ driver: WebDriver }>(async (context) => {
context.driver = driver;
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
afterEach<{ driver: WebDriver }>(async (context) => {
await takeScreenshotOnFailure(context);
});
Expand Down
123 changes: 123 additions & 0 deletions e2e/serial/dappInteractions/5_maliciousDapp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import 'chromedriver';
import 'geckodriver';
import { WebDriver } from 'selenium-webdriver';
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from 'vitest';

import {
checkWalletName,
delayTime,
findElementByTestId,
findElementByTestIdAndClick,
findElementByText,
getAllWindowHandles,
getExtensionIdByName,
getRootUrl,
getWindowHandle,
goToPopup,
importWalletFlow,
initDriverWithOptions,
takeScreenshotOnFailure,
waitAndClick,
} from '../../helpers';
import { TEST_VARIABLES } from '../../walletVariables';

let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
const os = process.env.OS || 'mac';

describe('App interactions flow', () => {
beforeAll(async () => {
driver = await initDriverWithOptions({
browser,
os,
});
const extensionId = await getExtensionIdByName(driver, 'Rainbow');
if (!extensionId) throw new Error('Extension not found');
rootURL += extensionId;
});

beforeEach<{ driver: WebDriver }>(async (context) => {
context.driver = driver;
});

afterEach<{ driver: WebDriver }>(async (context) => {
await takeScreenshotOnFailure(context);
});

afterAll(() => driver.quit());

it('should be able import a wallet via seed', async () => {
await importWalletFlow(driver, rootURL, TEST_VARIABLES.EMPTY_WALLET.SECRET);
});

it('should display account name', async () => {
await checkWalletName(driver, rootURL, TEST_VARIABLES.EMPTY_WALLET.ADDRESS);
});

it('should be able to go to setings', async () => {
await goToPopup(driver, rootURL);
await findElementByTestIdAndClick({ id: 'home-page-header-right', driver });
await findElementByTestIdAndClick({ id: 'settings-link', driver });
});

it('should be able to connect to hardhat', async () => {
await findElementByTestIdAndClick({ id: 'connect-to-hardhat', driver });
const button = await findElementByText(driver, 'Disconnect from Hardhat');
expect(button).toBeTruthy();
await findElementByTestIdAndClick({
id: 'navbar-button-with-back',
driver,
});
});

it('should be able to navigate to the malicious app and click connect', async () => {
await delayTime('long');
await driver.get('https://test-dap-welps.vercel.app/');
const dappHandler = await getWindowHandle({ driver });

const button = await findElementByTestId({
id: 'rk-connect-button',
driver,
});
expect(button).toBeTruthy();
await waitAndClick(button, driver);

await delayTime('long');

await findElementByTestIdAndClick({
id: 'rk-wallet-option-rainbow',
driver,
});
await delayTime('long');

const { popupHandler } = await getAllWindowHandles({ driver, dappHandler });
await driver.switchTo().window(popupHandler);
});

it('should be able to navigate to switch to BX and see malicious app warning', async () => {
await delayTime('long');
const dappWarning = await findElementByTestId({
id: 'malicious-request-warning',
driver,
});
const warningText = await dappWarning.getText();

const warningText1 = 'This app is likely malicious';
const warningText2 =
'Signing messages or transactions from this app could result in losing your assets';

expect(dappWarning).toBeTruthy();
expect(warningText).toContain(warningText1);
expect(warningText).toContain(warningText2);
});
});
1 change: 1 addition & 0 deletions src/entries/popup/pages/messages/DappScanStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function MaliciousRequestWarning({
}) {
return (
<Box
testId={'malicious-request-warning'}
as={motion.div}
initial={{ opacity: 0, scale: 0.5 }}
animate={{ opacity: 1, scale: 1 }}
Expand Down

0 comments on commit 6fff157

Please sign in to comment.