Skip to content

Commit

Permalink
test(e2e): unacquired device
Browse files Browse the repository at this point in the history
(cherry picked from commit 192bb35)
  • Loading branch information
mroz22 authored and komret committed Nov 6, 2023
1 parent 8612617 commit 9a46694
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/suite-web/e2e/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import CDP from 'chrome-remote-interface';
import fs from 'fs';
import path from 'path';
import { addMatchImageSnapshotPlugin } from 'cypress-image-snapshot/plugin';
import { BridgeTransport } from '@trezor/transport';
import * as messages from '@trezor/protobuf/src/messages';

import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link';
import * as metadataUtils from '@trezor/suite/src/utils/suite/metadata';
Expand Down Expand Up @@ -149,6 +151,15 @@ export default defineConfig({
await mocked.bridge.stop();
return null;
},
stealBridgeSession: async () => {
const bridge = new BridgeTransport({ messages });
await bridge.init().promise;
const enumerateRes = await bridge.enumerate().promise;
if (!enumerateRes.success) return null;
await bridge.acquire({ input: { path: enumerateRes.payload[0].path } }).promise;

return null;
},

resetCRI: async () => {
if (client) {
Expand Down
40 changes: 40 additions & 0 deletions packages/suite-web/e2e/tests/suite/unacquired-device.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @group:suite
// @retry=2

describe('unacquried device', () => {
beforeEach(() => {
cy.viewport(1080, 1440).resetDb();
cy.task('startEmu', { wipe: true });
cy.task('setupEmu', { passphrase_protection: true, pin_protection: false });
cy.task('startBridge');
});

it('somone steals session, device status turns inactive', () => {
cy.prefixedVisit('/');
cy.passThroughInitialRun();
cy.getTestElement('@passphrase-type/standard').click();
cy.discoveryShouldFinish();

// simulate stolen session from another window. device receives indicative button
cy.task('stealBridgeSession');
cy.getTestElement('@menu/switch-device/refresh-button').click();
cy.getTestElement('@deviceStatus-connected');

// when user reloads app while device is ancquired, suite will not try to acquire device so that it
// does not interfers with somebody else's session
cy.task('stealBridgeSession');
cy.getTestElement('@menu/switch-device/refresh-button');
cy.reload();
cy.getTestElement('@device-acquire').click();
cy.getTestElement('@passphrase-type/standard').click();
cy.discoveryShouldFinish();
});

// todo:
// - it is broken in settings! there is not acquire button
// - make sure it works in onboarding, I am not sure there is acquire button present
// - also firmware update, maybe standalone backup/recovery might have custom implementation that might be worth revisiting
// - device state is incorrect is wrong copy!!!
});

export {};
2 changes: 2 additions & 0 deletions packages/suite-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"@trezor/connect": "workspace:*",
"@trezor/e2e-utils": "workspace:*",
"@trezor/env-utils": "workspace:*",
"@trezor/protobuf": "workspace:*",
"@trezor/suite-analytics": "workspace:*",
"@trezor/transport": "workspace:*",
"@trezor/trezor-user-env-link": "workspace:*",
"@trezor/utils": "workspace:*",
"@types/chrome-remote-interface": "^0.31.10",
Expand Down
2 changes: 2 additions & 0 deletions packages/suite-web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
},
{ "path": "../e2e-utils" },
{ "path": "../env-utils" },
{ "path": "../protobuf" },
{ "path": "../suite-analytics" },
{ "path": "../transport" },
{ "path": "../trezor-user-env-link" },
{ "path": "../utils" }
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const DeviceStatus = ({
icon="REFRESH"
size={12}
color={getStatusColor(status, theme)}
data-test="@menu/switch-device/refresh-button"
/>
);
}
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10201,8 +10201,10 @@ __metadata:
"@trezor/device-utils": "workspace:*"
"@trezor/e2e-utils": "workspace:*"
"@trezor/env-utils": "workspace:*"
"@trezor/protobuf": "workspace:*"
"@trezor/suite": "workspace:*"
"@trezor/suite-analytics": "workspace:*"
"@trezor/transport": "workspace:*"
"@trezor/trezor-user-env-link": "workspace:*"
"@trezor/utils": "workspace:*"
"@types/chrome-remote-interface": ^0.31.10
Expand Down

0 comments on commit 9a46694

Please sign in to comment.