diff --git a/e2e/serial/dappInteractions/1_appInteractionsFlow.test.ts b/e2e/serial/dappInteractions/1_appInteractionsFlow.test.ts index c2b67356d1..339267ce56 100644 --- a/e2e/serial/dappInteractions/1_appInteractionsFlow.test.ts +++ b/e2e/serial/dappInteractions/1_appInteractionsFlow.test.ts @@ -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); }); diff --git a/e2e/serial/dappInteractions/2_dappInteractionFlow.test.ts b/e2e/serial/dappInteractions/2_dappInteractionFlow.test.ts index c2ea4f6c85..aa0f12c92c 100644 --- a/e2e/serial/dappInteractions/2_dappInteractionFlow.test.ts +++ b/e2e/serial/dappInteractions/2_dappInteractionFlow.test.ts @@ -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); }); diff --git a/e2e/serial/dappInteractions/3_dappAccountsSwitcher.test.ts b/e2e/serial/dappInteractions/3_dappAccountsSwitcher.test.ts index 50d2926815..6a83b37e80 100644 --- a/e2e/serial/dappInteractions/3_dappAccountsSwitcher.test.ts +++ b/e2e/serial/dappInteractions/3_dappAccountsSwitcher.test.ts @@ -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); }); diff --git a/e2e/serial/dappInteractions/4_networksAndTestnetModeFlow.test.ts b/e2e/serial/dappInteractions/4_networksAndTestnetModeFlow.test.ts index 0aa51a1bd1..4f62f2a920 100644 --- a/e2e/serial/dappInteractions/4_networksAndTestnetModeFlow.test.ts +++ b/e2e/serial/dappInteractions/4_networksAndTestnetModeFlow.test.ts @@ -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); }); diff --git a/e2e/serial/dappInteractions/5_maliciousDapp.test.ts b/e2e/serial/dappInteractions/5_maliciousDapp.test.ts new file mode 100644 index 0000000000..dbcf576dc4 --- /dev/null +++ b/e2e/serial/dappInteractions/5_maliciousDapp.test.ts @@ -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); + }); +}); diff --git a/src/entries/popup/pages/messages/DappScanStatus.tsx b/src/entries/popup/pages/messages/DappScanStatus.tsx index fa7b887d05..1addb3cf2b 100644 --- a/src/entries/popup/pages/messages/DappScanStatus.tsx +++ b/src/entries/popup/pages/messages/DappScanStatus.tsx @@ -17,6 +17,7 @@ export function MaliciousRequestWarning({ }) { return (