Skip to content

Commit e2b7852

Browse files
authored
test e2e: use encryption tab instead of Security & Settings tab in crypto.spec.ts (#29595)
* test(e2e crypto): use encryption tab instead of Security & Settings tab in crypto.spec.ts * test(e2e): remove wrong comment * test(e2e crypto): keep `downloadKeysForUsers` * test(e2e crypto): enter only password * test: fix typo
1 parent c24a1ba commit e2b7852

File tree

1 file changed

+36
-92
lines changed

1 file changed

+36
-92
lines changed

playwright/e2e/crypto/crypto.spec.ts

Lines changed: 36 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@ Please see LICENSE files in the repository root for full details.
88

99
import type { Page } from "@playwright/test";
1010
import { expect, test } from "../../element-web-test";
11-
import {
12-
autoJoin,
13-
completeCreateSecretStorageDialog,
14-
copyAndContinue,
15-
createSharedRoomWithUser,
16-
enableKeyBackup,
17-
verify,
18-
} from "./utils";
11+
import { autoJoin, createSharedRoomWithUser, enableKeyBackup, verify } from "./utils";
1912
import { type Bot } from "../../pages/bot";
2013
import { type ElementAppPage } from "../../pages/ElementAppPage";
2114
import { isDendrite } from "../../plugins/homeserver/dendrite";
@@ -84,86 +77,43 @@ test.describe("Cryptography", function () {
8477
},
8578
});
8679

87-
for (const isDeviceVerified of [true, false]) {
88-
test.describe(`setting up secure key backup should work isDeviceVerified=${isDeviceVerified}`, () => {
89-
/**
90-
* Verify that the `m.cross_signing.${keyType}` key is available on the account data on the server
91-
* @param keyType
92-
*/
93-
async function verifyKey(app: ElementAppPage, keyType: "master" | "self_signing" | "user_signing") {
94-
const accountData: { encrypted: Record<string, Record<string, string>> } = await app.client.evaluate(
95-
(cli, keyType) => cli.getAccountDataFromServer(`m.cross_signing.${keyType}`),
96-
keyType,
97-
);
98-
expect(accountData.encrypted).toBeDefined();
99-
const keys = Object.keys(accountData.encrypted);
100-
const key = accountData.encrypted[keys[0]];
101-
expect(key.ciphertext).toBeDefined();
102-
expect(key.iv).toBeDefined();
103-
expect(key.mac).toBeDefined();
104-
}
105-
106-
test("by recovery code", async ({ page, app, user: aliceCredentials }) => {
107-
// Verified the device
108-
if (isDeviceVerified) {
109-
await app.client.bootstrapCrossSigning(aliceCredentials);
110-
}
111-
112-
await page.route("**/_matrix/client/v3/keys/signatures/upload", async (route) => {
113-
// We delay this API otherwise the `Setting up keys` may happen too quickly and cause flakiness
114-
await new Promise((resolve) => setTimeout(resolve, 500));
115-
await route.continue();
116-
});
80+
/**
81+
* Verify that the `m.cross_signing.${keyType}` key is available on the account data on the server
82+
* @param keyType
83+
*/
84+
async function verifyKey(app: ElementAppPage, keyType: "master" | "self_signing" | "user_signing") {
85+
const accountData: { encrypted: Record<string, Record<string, string>> } = await app.client.evaluate(
86+
(cli, keyType) => cli.getAccountDataFromServer(`m.cross_signing.${keyType}`),
87+
keyType,
88+
);
89+
90+
expect(accountData.encrypted).toBeDefined();
91+
const keys = Object.keys(accountData.encrypted);
92+
const key = accountData.encrypted[keys[0]];
93+
expect(key.ciphertext).toBeDefined();
94+
expect(key.iv).toBeDefined();
95+
expect(key.mac).toBeDefined();
96+
}
11797

118-
await app.settings.openUserSettings("Security & Privacy");
119-
await page.getByRole("button", { name: "Set up Secure Backup" }).click();
98+
test("Setting up key backup by recovery key", async ({ page, app, user: aliceCredentials }) => {
99+
await app.client.bootstrapCrossSigning(aliceCredentials);
120100

121-
await completeCreateSecretStorageDialog(page);
101+
await enableKeyBackup(app);
122102

123-
// Verify that the SSSS keys are in the account data stored in the server
124-
await verifyKey(app, "master");
125-
await verifyKey(app, "self_signing");
126-
await verifyKey(app, "user_signing");
127-
});
103+
// Wait for the cross signing keys to be uploaded
104+
// Waiting for "Change the recovery key" button ensure that all the secrets are uploaded and cached locally
105+
const encryptionTab = await app.settings.openUserSettings("Encryption");
106+
await expect(encryptionTab.getByRole("button", { name: "Change recovery key" })).toBeVisible();
128107

129-
test("by passphrase", async ({ page, app, user: aliceCredentials }) => {
130-
// Verified the device
131-
if (isDeviceVerified) {
132-
await app.client.bootstrapCrossSigning(aliceCredentials);
133-
}
134-
135-
await app.settings.openUserSettings("Security & Privacy");
136-
await page.getByRole("button", { name: "Set up Secure Backup" }).click();
137-
138-
const dialog = page.locator(".mx_Dialog");
139-
// Select passphrase option
140-
await dialog.getByText("Enter a Security Phrase").click();
141-
await dialog.getByRole("button", { name: "Continue" }).click();
142-
143-
// Fill passphrase input
144-
await dialog.locator("input").fill("new passphrase for setting up a secure key backup");
145-
await dialog.locator(".mx_Dialog_primary:not([disabled])", { hasText: "Continue" }).click();
146-
// Confirm passphrase
147-
await dialog.locator("input").fill("new passphrase for setting up a secure key backup");
148-
await dialog.locator(".mx_Dialog_primary:not([disabled])", { hasText: "Continue" }).click();
149-
150-
await copyAndContinue(page);
151-
152-
await expect(dialog.getByText("Secure Backup successful")).toBeVisible();
153-
await dialog.getByRole("button", { name: "Done" }).click();
154-
await expect(dialog.getByText("Secure Backup successful")).not.toBeVisible();
155-
156-
// Verify that the SSSS keys are in the account data stored in the server
157-
await verifyKey(app, "master");
158-
await verifyKey(app, "self_signing");
159-
await verifyKey(app, "user_signing");
160-
});
161-
});
162-
}
108+
// Verify that the SSSS keys are in the account data stored in the server
109+
await verifyKey(app, "master");
110+
await verifyKey(app, "self_signing");
111+
await verifyKey(app, "user_signing");
112+
});
163113

164114
test("Can reset cross-signing keys", async ({ page, app, user: aliceCredentials }) => {
165115
await app.client.bootstrapCrossSigning(aliceCredentials);
166-
const secretStorageKey = await enableKeyBackup(app);
116+
await enableKeyBackup(app);
167117

168118
// Fetch the current cross-signing keys
169119
async function fetchMasterKey() {
@@ -177,18 +127,15 @@ test.describe("Cryptography", function () {
177127
return k;
178128
});
179129
}
130+
180131
const masterKey1 = await fetchMasterKey();
181132

182-
// Find the "reset cross signing" button, and click it
183-
await app.settings.openUserSettings("Security & Privacy");
184-
await page.locator("div.mx_CrossSigningPanel_buttonRow").getByRole("button", { name: "Reset" }).click();
133+
// Find "the Reset cryptographic identity" button
134+
const encryptionTab = await app.settings.openUserSettings("Encryption");
135+
await encryptionTab.getByRole("button", { name: "Reset cryptographic identity" }).click();
185136

186137
// Confirm
187-
await page.getByRole("button", { name: "Clear cross-signing keys" }).click();
188-
189-
// Enter the 4S key
190-
await page.getByPlaceholder("Recovery Key").fill(secretStorageKey);
191-
await page.getByRole("button", { name: "Continue" }).click();
138+
await encryptionTab.getByRole("button", { name: "Continue" }).click();
192139

193140
// Enter the password
194141
await page.getByPlaceholder("Password").fill(aliceCredentials.password);
@@ -198,9 +145,6 @@ test.describe("Cryptography", function () {
198145
const masterKey2 = await fetchMasterKey();
199146
expect(masterKey1).not.toEqual(masterKey2);
200147
}).toPass();
201-
202-
// The dialog should have gone away
203-
await expect(page.locator(".mx_Dialog")).toHaveCount(1);
204148
});
205149

206150
test(

0 commit comments

Comments
 (0)