Skip to content

Commit 7b3ce5d

Browse files
authored
e2e test: by default the bot should not use a passphrase to create the recovery key (#29214)
* test(crypto): by default do not use a passphrase to create the recovery key * test(crypto): update tests
1 parent 4a231c6 commit 7b3ce5d

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

playwright/e2e/crypto/device-verification.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => {
2929
let expectedBackupVersion: string;
3030

3131
test.beforeEach(async ({ page, homeserver, credentials }) => {
32-
const res = await createBot(page, homeserver, credentials);
32+
const res = await createBot(page, homeserver, credentials, true);
3333
aliceBotClient = res.botClient;
3434
expectedBackupVersion = res.expectedBackupVersion;
3535
});

playwright/e2e/crypto/toasts.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ test.describe("Key storage out of sync toast", () => {
3434
await expect(page.getByRole("alert").first()).toMatchScreenshot("key-storage-out-of-sync-toast.png");
3535

3636
await page.getByRole("button", { name: "Enter recovery key" }).click();
37-
await page.locator(".mx_Dialog").getByRole("button", { name: "use your Security Key" }).click();
3837

3938
await page.getByRole("textbox", { name: "Security key" }).fill(recoveryKey.encodedPrivateKey);
4039
await page.getByRole("button", { name: "Continue" }).click();

playwright/e2e/crypto/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ import { Bot } from "../../pages/bot";
2828
* @param page - the playwright `page` fixture
2929
* @param homeserver - the homeserver to use
3030
* @param credentials - the credentials to use for the bot client
31+
* @param usePassphrase - whether to use a passphrase when creating the recovery key
3132
*/
3233
export async function createBot(
3334
page: Page,
3435
homeserver: HomeserverInstance,
3536
credentials: Credentials,
37+
usePassphrase = false,
3638
): Promise<{ botClient: Bot; recoveryKey: GeneratedSecretStorageKey; expectedBackupVersion: string }> {
3739
// Visit the login page of the app, to load the matrix sdk
3840
await page.goto("/#/login");
@@ -44,6 +46,7 @@ export async function createBot(
4446
const botClient = new Bot(page, homeserver, {
4547
bootstrapCrossSigning: true,
4648
bootstrapSecretStorage: true,
49+
usePassphrase,
4750
});
4851
botClient.setCredentials(credentials);
4952
// Backup is prepared in the background. Poll until it is ready.

playwright/e2e/settings/encryption-user-tab/encryption-tab.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test.describe("Encryption tab", () => {
6767
"should prompt to enter the recovery key when the secrets are not cached locally",
6868
{ tag: "@screenshot" },
6969
async ({ page, app, util }) => {
70-
await verifySession(app, "new passphrase");
70+
await verifySession(app, recoveryKey.encodedPrivateKey);
7171
// We need to delete the cached secrets
7272
await deleteCachedSecrets(page);
7373

@@ -99,7 +99,7 @@ test.describe("Encryption tab", () => {
9999
app,
100100
util,
101101
}) => {
102-
await verifySession(app, "new passphrase");
102+
await verifySession(app, recoveryKey.encodedPrivateKey);
103103
// We need to delete the cached secrets
104104
await deleteCachedSecrets(page);
105105

playwright/e2e/settings/encryption-user-tab/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Helpers {
4343
*/
4444
async verifyDevice(recoveryKey: GeneratedSecretStorageKey) {
4545
// Select the security phrase
46-
await this.page.getByRole("button", { name: "Verify with Security Key or Phrase" }).click();
46+
await this.page.getByRole("button", { name: "Verify with Security Key" }).click();
4747
await this.enterRecoveryKey(recoveryKey);
4848
await this.page.getByRole("button", { name: "Done" }).click();
4949
}
@@ -53,9 +53,6 @@ class Helpers {
5353
* @param recoveryKey
5454
*/
5555
async enterRecoveryKey(recoveryKey: GeneratedSecretStorageKey) {
56-
// Select to use recovery key
57-
await this.page.getByRole("button", { name: "use your Security Key" }).click();
58-
5956
// Fill the recovery key
6057
const dialog = this.page.locator(".mx_Dialog");
6158
await dialog.getByRole("textbox").fill(recoveryKey.encodedPrivateKey);

playwright/e2e/settings/encryption-user-tab/recovery.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,25 @@
77

88
import { test, expect } from ".";
99
import { checkDeviceIsConnectedKeyBackup, createBot, verifySession } from "../../crypto/utils";
10+
import type { GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api";
1011

1112
test.describe("Recovery section in Encryption tab", () => {
1213
test.use({
1314
displayName: "Alice",
1415
});
1516

17+
let recoveryKey: GeneratedSecretStorageKey;
1618
test.beforeEach(async ({ page, homeserver, credentials }) => {
1719
// The bot bootstraps cross-signing, creates a key backup and sets up a recovery key
18-
await createBot(page, homeserver, credentials);
20+
const res = await createBot(page, homeserver, credentials);
21+
recoveryKey = res.recoveryKey;
1922
});
2023

2124
test(
2225
"should change the recovery key",
2326
{ tag: ["@screenshot", "@no-webkit"] },
2427
async ({ page, app, homeserver, credentials, util, context }) => {
25-
await verifySession(app, "new passphrase");
28+
await verifySession(app, recoveryKey.encodedPrivateKey);
2629
const dialog = await util.openEncryptionTab();
2730

2831
// The user can only change the recovery key
@@ -49,7 +52,7 @@ test.describe("Recovery section in Encryption tab", () => {
4952
);
5053

5154
test("should setup the recovery key", { tag: ["@screenshot", "@no-webkit"] }, async ({ page, app, util }) => {
52-
await verifySession(app, "new passphrase");
55+
await verifySession(app, recoveryKey.encodedPrivateKey);
5356
await util.removeSecretStorageDefaultKeyId();
5457

5558
// The key backup is deleted and the user needs to set it up

playwright/pages/bot.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ export interface CreateBotOpts {
4141
* Whether to bootstrap the secret storage
4242
*/
4343
bootstrapSecretStorage?: boolean;
44+
/**
45+
* Whether to use a passphrase when creating the recovery key
46+
*/
47+
usePassphrase?: boolean;
4448
}
4549

4650
const defaultCreateBotOptions = {
4751
userIdPrefix: "bot_",
4852
autoAcceptInvites: true,
4953
startClient: true,
5054
bootstrapCrossSigning: true,
55+
usePassphrase: false,
5156
} satisfies CreateBotOpts;
5257

5358
type ExtendedMatrixClient = MatrixClient & { __playwright_recovery_key: GeneratedSecretStorageKey };
@@ -206,8 +211,8 @@ export class Bot extends Client {
206211
}
207212

208213
if (this.opts.bootstrapSecretStorage) {
209-
await clientHandle.evaluate(async (cli) => {
210-
const passphrase = "new passphrase";
214+
await clientHandle.evaluate(async (cli, usePassphrase) => {
215+
const passphrase = usePassphrase ? "new passphrase" : undefined;
211216
const recoveryKey = await cli.getCrypto().createRecoveryKeyFromPassphrase(passphrase);
212217
Object.assign(cli, { __playwright_recovery_key: recoveryKey });
213218

@@ -216,7 +221,7 @@ export class Bot extends Client {
216221
setupNewKeyBackup: true,
217222
createSecretStorageKey: () => Promise.resolve(recoveryKey),
218223
});
219-
});
224+
}, this.opts.usePassphrase);
220225
}
221226

222227
return clientHandle;

0 commit comments

Comments
 (0)