Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 1058af6

Browse files
authored
Playwright test for E2E messages from deleted devices (#47)
* Factor out `createSecondBotDevice` utility * Add playwright test for messages from deleted devices Thanks to MSC4147, we now have information on the devices that sent messages, even when the device has since been deleted. Test that out.
1 parent c24661f commit 1058af6

File tree

1 file changed

+51
-16
lines changed

1 file changed

+51
-16
lines changed

playwright/e2e/crypto/event-shields.spec.ts

+51-16
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9+
import { Page } from "@playwright/test";
10+
911
import { expect, test } from "../../element-web-test";
1012
import { autoJoin, createSharedRoomWithUser, enableKeyBackup, logIntoElement, logOutOfElement, verify } from "./utils";
1113
import { Bot } from "../../pages/bot";
14+
import { HomeserverInstance } from "../../plugins/homeserver";
1215

1316
test.describe("Cryptography", function () {
1417
test.use({
@@ -48,14 +51,7 @@ test.describe("Cryptography", function () {
4851
homeserver,
4952
}, workerInfo) => {
5053
// Bob has a second, not cross-signed, device
51-
const bobSecondDevice = new Bot(page, homeserver, {
52-
bootstrapSecretStorage: false,
53-
bootstrapCrossSigning: false,
54-
});
55-
bobSecondDevice.setCredentials(
56-
await homeserver.loginUser(bob.credentials.userId, bob.credentials.password),
57-
);
58-
await bobSecondDevice.prepareClient();
54+
const bobSecondDevice = await createSecondBotDevice(page, homeserver, bob);
5955

6056
await bob.sendEvent(testRoomId, null, "m.room.encrypted", {
6157
algorithm: "m.megolm.v1.aes-sha2",
@@ -216,14 +212,7 @@ test.describe("Cryptography", function () {
216212

217213
test("should show the correct shield on edited e2e events", async ({ page, app, bot: bob, homeserver }) => {
218214
// bob has a second, not cross-signed, device
219-
const bobSecondDevice = new Bot(page, homeserver, {
220-
bootstrapSecretStorage: false,
221-
bootstrapCrossSigning: false,
222-
});
223-
bobSecondDevice.setCredentials(
224-
await homeserver.loginUser(bob.credentials.userId, bob.credentials.password),
225-
);
226-
await bobSecondDevice.prepareClient();
215+
const bobSecondDevice = await createSecondBotDevice(page, homeserver, bob);
227216

228217
// verify Bob
229218
await verify(app, bob);
@@ -269,5 +258,51 @@ test.describe("Cryptography", function () {
269258
page.locator(".mx_EventTile", { hasText: "Hee!" }).locator(".mx_EventTile_e2eIcon_warning"),
270259
).not.toBeVisible();
271260
});
261+
262+
test("should show correct shields on events sent by devices which have since been deleted", async ({
263+
page,
264+
app,
265+
bot: bob,
266+
homeserver,
267+
}) => {
268+
// Our app is blocked from syncing while Bob sends his messages.
269+
await app.client.network.goOffline();
270+
271+
// Bob sends a message from his verified device
272+
await bob.sendMessage(testRoomId, "test encrypted from verified");
273+
274+
// And one from a second, not cross-signed, device
275+
const bobSecondDevice = await createSecondBotDevice(page, homeserver, bob);
276+
await bobSecondDevice.waitForNextSync(); // make sure the client knows the room is encrypted
277+
await bobSecondDevice.sendMessage(testRoomId, "test encrypted from unverified");
278+
279+
// ... and then logs out both devices.
280+
await bob.evaluate((cli) => cli.logout(true));
281+
await bobSecondDevice.evaluate((cli) => cli.logout(true));
282+
283+
// Let our app start syncing again
284+
await app.client.network.goOnline();
285+
286+
// Wait for the messages to arrive
287+
const last = page.locator(".mx_EventTile_last");
288+
await expect(last).toContainText("test encrypted from unverified");
289+
const lastE2eIcon = last.locator(".mx_EventTile_e2eIcon");
290+
await expect(lastE2eIcon).toHaveClass(/mx_EventTile_e2eIcon_warning/);
291+
await lastE2eIcon.focus();
292+
await expect(page.getByRole("tooltip")).toContainText("Encrypted by a device not verified by its owner.");
293+
294+
const penultimate = page.locator(".mx_EventTile").filter({ hasText: "test encrypted from verified" });
295+
await expect(penultimate.locator(".mx_EventTile_e2eIcon")).not.toBeVisible();
296+
});
272297
});
273298
});
299+
300+
async function createSecondBotDevice(page: Page, homeserver: HomeserverInstance, bob: Bot) {
301+
const bobSecondDevice = new Bot(page, homeserver, {
302+
bootstrapSecretStorage: false,
303+
bootstrapCrossSigning: false,
304+
});
305+
bobSecondDevice.setCredentials(await homeserver.loginUser(bob.credentials.userId, bob.credentials.password));
306+
await bobSecondDevice.prepareClient();
307+
return bobSecondDevice;
308+
}

0 commit comments

Comments
 (0)