diff --git a/playwright/e2e/crypto/device-verification.spec.ts b/playwright/e2e/crypto/device-verification.spec.ts index 551f9302a91..7757d813ebc 100644 --- a/playwright/e2e/crypto/device-verification.spec.ts +++ b/playwright/e2e/crypto/device-verification.spec.ts @@ -29,7 +29,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => { let expectedBackupVersion: string; test.beforeEach(async ({ page, homeserver, credentials }) => { - const res = await createBot(page, homeserver, credentials); + const res = await createBot(page, homeserver, credentials, true); aliceBotClient = res.botClient; expectedBackupVersion = res.expectedBackupVersion; }); diff --git a/playwright/e2e/crypto/toasts.spec.ts b/playwright/e2e/crypto/toasts.spec.ts index 76d9ebea7a6..8b19b6ea615 100644 --- a/playwright/e2e/crypto/toasts.spec.ts +++ b/playwright/e2e/crypto/toasts.spec.ts @@ -34,7 +34,6 @@ test.describe("Key storage out of sync toast", () => { await expect(page.getByRole("alert").first()).toMatchScreenshot("key-storage-out-of-sync-toast.png"); await page.getByRole("button", { name: "Enter recovery key" }).click(); - await page.locator(".mx_Dialog").getByRole("button", { name: "use your Security Key" }).click(); await page.getByRole("textbox", { name: "Security key" }).fill(recoveryKey.encodedPrivateKey); await page.getByRole("button", { name: "Continue" }).click(); diff --git a/playwright/e2e/crypto/utils.ts b/playwright/e2e/crypto/utils.ts index ccdb320b94f..8d54a32fb20 100644 --- a/playwright/e2e/crypto/utils.ts +++ b/playwright/e2e/crypto/utils.ts @@ -28,11 +28,13 @@ import { Bot } from "../../pages/bot"; * @param page - the playwright `page` fixture * @param homeserver - the homeserver to use * @param credentials - the credentials to use for the bot client + * @param usePassphrase - whether to use a passphrase when creating the recovery key */ export async function createBot( page: Page, homeserver: HomeserverInstance, credentials: Credentials, + usePassphrase = false, ): Promise<{ botClient: Bot; recoveryKey: GeneratedSecretStorageKey; expectedBackupVersion: string }> { // Visit the login page of the app, to load the matrix sdk await page.goto("/#/login"); @@ -44,6 +46,7 @@ export async function createBot( const botClient = new Bot(page, homeserver, { bootstrapCrossSigning: true, bootstrapSecretStorage: true, + usePassphrase, }); botClient.setCredentials(credentials); // Backup is prepared in the background. Poll until it is ready. diff --git a/playwright/e2e/settings/encryption-user-tab/encryption-tab.spec.ts b/playwright/e2e/settings/encryption-user-tab/encryption-tab.spec.ts index a2799618143..107f8085cc9 100644 --- a/playwright/e2e/settings/encryption-user-tab/encryption-tab.spec.ts +++ b/playwright/e2e/settings/encryption-user-tab/encryption-tab.spec.ts @@ -67,7 +67,7 @@ test.describe("Encryption tab", () => { "should prompt to enter the recovery key when the secrets are not cached locally", { tag: "@screenshot" }, async ({ page, app, util }) => { - await verifySession(app, "new passphrase"); + await verifySession(app, recoveryKey.encodedPrivateKey); // We need to delete the cached secrets await deleteCachedSecrets(page); @@ -99,7 +99,7 @@ test.describe("Encryption tab", () => { app, util, }) => { - await verifySession(app, "new passphrase"); + await verifySession(app, recoveryKey.encodedPrivateKey); // We need to delete the cached secrets await deleteCachedSecrets(page); diff --git a/playwright/e2e/settings/encryption-user-tab/index.ts b/playwright/e2e/settings/encryption-user-tab/index.ts index 1a83097e55e..22dcd9041bb 100644 --- a/playwright/e2e/settings/encryption-user-tab/index.ts +++ b/playwright/e2e/settings/encryption-user-tab/index.ts @@ -43,7 +43,7 @@ class Helpers { */ async verifyDevice(recoveryKey: GeneratedSecretStorageKey) { // Select the security phrase - await this.page.getByRole("button", { name: "Verify with Security Key or Phrase" }).click(); + await this.page.getByRole("button", { name: "Verify with Security Key" }).click(); await this.enterRecoveryKey(recoveryKey); await this.page.getByRole("button", { name: "Done" }).click(); } @@ -53,9 +53,6 @@ class Helpers { * @param recoveryKey */ async enterRecoveryKey(recoveryKey: GeneratedSecretStorageKey) { - // Select to use recovery key - await this.page.getByRole("button", { name: "use your Security Key" }).click(); - // Fill the recovery key const dialog = this.page.locator(".mx_Dialog"); await dialog.getByRole("textbox").fill(recoveryKey.encodedPrivateKey); diff --git a/playwright/e2e/settings/encryption-user-tab/recovery.spec.ts b/playwright/e2e/settings/encryption-user-tab/recovery.spec.ts index 8bb16f018b2..8895e4a7ee2 100644 --- a/playwright/e2e/settings/encryption-user-tab/recovery.spec.ts +++ b/playwright/e2e/settings/encryption-user-tab/recovery.spec.ts @@ -7,22 +7,25 @@ import { test, expect } from "."; import { checkDeviceIsConnectedKeyBackup, createBot, verifySession } from "../../crypto/utils"; +import type { GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api"; test.describe("Recovery section in Encryption tab", () => { test.use({ displayName: "Alice", }); + let recoveryKey: GeneratedSecretStorageKey; test.beforeEach(async ({ page, homeserver, credentials }) => { // The bot bootstraps cross-signing, creates a key backup and sets up a recovery key - await createBot(page, homeserver, credentials); + const res = await createBot(page, homeserver, credentials); + recoveryKey = res.recoveryKey; }); test( "should change the recovery key", { tag: ["@screenshot", "@no-webkit"] }, async ({ page, app, homeserver, credentials, util, context }) => { - await verifySession(app, "new passphrase"); + await verifySession(app, recoveryKey.encodedPrivateKey); const dialog = await util.openEncryptionTab(); // The user can only change the recovery key @@ -49,7 +52,7 @@ test.describe("Recovery section in Encryption tab", () => { ); test("should setup the recovery key", { tag: ["@screenshot", "@no-webkit"] }, async ({ page, app, util }) => { - await verifySession(app, "new passphrase"); + await verifySession(app, recoveryKey.encodedPrivateKey); await util.removeSecretStorageDefaultKeyId(); // The key backup is deleted and the user needs to set it up diff --git a/playwright/pages/bot.ts b/playwright/pages/bot.ts index ef6fc3861dd..05a8948a65e 100644 --- a/playwright/pages/bot.ts +++ b/playwright/pages/bot.ts @@ -41,6 +41,10 @@ export interface CreateBotOpts { * Whether to bootstrap the secret storage */ bootstrapSecretStorage?: boolean; + /** + * Whether to use a passphrase when creating the recovery key + */ + usePassphrase?: boolean; } const defaultCreateBotOptions = { @@ -48,6 +52,7 @@ const defaultCreateBotOptions = { autoAcceptInvites: true, startClient: true, bootstrapCrossSigning: true, + usePassphrase: false, } satisfies CreateBotOpts; type ExtendedMatrixClient = MatrixClient & { __playwright_recovery_key: GeneratedSecretStorageKey }; @@ -206,8 +211,8 @@ export class Bot extends Client { } if (this.opts.bootstrapSecretStorage) { - await clientHandle.evaluate(async (cli) => { - const passphrase = "new passphrase"; + await clientHandle.evaluate(async (cli, usePassphrase) => { + const passphrase = usePassphrase ? "new passphrase" : undefined; const recoveryKey = await cli.getCrypto().createRecoveryKeyFromPassphrase(passphrase); Object.assign(cli, { __playwright_recovery_key: recoveryKey }); @@ -216,7 +221,7 @@ export class Bot extends Client { setupNewKeyBackup: true, createSecretStorageKey: () => Promise.resolve(recoveryKey), }); - }); + }, this.opts.usePassphrase); } return clientHandle;