From 5d2c0f1af62a866da8d60e60522a4d4a3fd741ff Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 17 Sep 2024 13:11:51 +0100 Subject: [PATCH 1/2] Factor out `createSecondBotDevice` utility --- playwright/e2e/crypto/event-shields.spec.ts | 31 ++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/playwright/e2e/crypto/event-shields.spec.ts b/playwright/e2e/crypto/event-shields.spec.ts index 077d9126fa..8f6d03f1d2 100644 --- a/playwright/e2e/crypto/event-shields.spec.ts +++ b/playwright/e2e/crypto/event-shields.spec.ts @@ -6,9 +6,12 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ +import { Page } from "@playwright/test"; + import { expect, test } from "../../element-web-test"; import { autoJoin, createSharedRoomWithUser, enableKeyBackup, logIntoElement, logOutOfElement, verify } from "./utils"; import { Bot } from "../../pages/bot"; +import { HomeserverInstance } from "../../plugins/homeserver"; test.describe("Cryptography", function () { test.use({ @@ -43,14 +46,7 @@ test.describe("Cryptography", function () { test("should show the correct shield on e2e events", async ({ page, app, bot: bob, homeserver }) => { // Bob has a second, not cross-signed, device - const bobSecondDevice = new Bot(page, homeserver, { - bootstrapSecretStorage: false, - bootstrapCrossSigning: false, - }); - bobSecondDevice.setCredentials( - await homeserver.loginUser(bob.credentials.userId, bob.credentials.password), - ); - await bobSecondDevice.prepareClient(); + const bobSecondDevice = await createSecondBotDevice(page, homeserver, bob); await bob.sendEvent(testRoomId, null, "m.room.encrypted", { algorithm: "m.megolm.v1.aes-sha2", @@ -204,14 +200,7 @@ test.describe("Cryptography", function () { test("should show the correct shield on edited e2e events", async ({ page, app, bot: bob, homeserver }) => { // bob has a second, not cross-signed, device - const bobSecondDevice = new Bot(page, homeserver, { - bootstrapSecretStorage: false, - bootstrapCrossSigning: false, - }); - bobSecondDevice.setCredentials( - await homeserver.loginUser(bob.credentials.userId, bob.credentials.password), - ); - await bobSecondDevice.prepareClient(); + const bobSecondDevice = await createSecondBotDevice(page, homeserver, bob); // verify Bob await verify(app, bob); @@ -259,3 +248,13 @@ test.describe("Cryptography", function () { }); }); }); + +async function createSecondBotDevice(page: Page, homeserver: HomeserverInstance, bob: Bot) { + const bobSecondDevice = new Bot(page, homeserver, { + bootstrapSecretStorage: false, + bootstrapCrossSigning: false, + }); + bobSecondDevice.setCredentials(await homeserver.loginUser(bob.credentials.userId, bob.credentials.password)); + await bobSecondDevice.prepareClient(); + return bobSecondDevice; +} From c14ec0de15cb961cf901968f757e1a37ff2a38a0 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 17 Sep 2024 13:12:15 +0100 Subject: [PATCH 2/2] 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. --- playwright/e2e/crypto/event-shields.spec.ts | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/playwright/e2e/crypto/event-shields.spec.ts b/playwright/e2e/crypto/event-shields.spec.ts index 8f6d03f1d2..6093ed0ce8 100644 --- a/playwright/e2e/crypto/event-shields.spec.ts +++ b/playwright/e2e/crypto/event-shields.spec.ts @@ -246,6 +246,42 @@ test.describe("Cryptography", function () { page.locator(".mx_EventTile", { hasText: "Hee!" }).locator(".mx_EventTile_e2eIcon_warning"), ).not.toBeVisible(); }); + + test("should show correct shields on events sent by devices which have since been deleted", async ({ + page, + app, + bot: bob, + homeserver, + }) => { + // Our app is blocked from syncing while Bob sends his messages. + await app.client.network.goOffline(); + + // Bob sends a message from his verified device + await bob.sendMessage(testRoomId, "test encrypted from verified"); + + // And one from a second, not cross-signed, device + const bobSecondDevice = await createSecondBotDevice(page, homeserver, bob); + await bobSecondDevice.waitForNextSync(); // make sure the client knows the room is encrypted + await bobSecondDevice.sendMessage(testRoomId, "test encrypted from unverified"); + + // ... and then logs out both devices. + await bob.evaluate((cli) => cli.logout(true)); + await bobSecondDevice.evaluate((cli) => cli.logout(true)); + + // Let our app start syncing again + await app.client.network.goOnline(); + + // Wait for the messages to arrive + const last = page.locator(".mx_EventTile_last"); + await expect(last).toContainText("test encrypted from unverified"); + const lastE2eIcon = last.locator(".mx_EventTile_e2eIcon"); + await expect(lastE2eIcon).toHaveClass(/mx_EventTile_e2eIcon_warning/); + await lastE2eIcon.focus(); + await expect(page.getByRole("tooltip")).toContainText("Encrypted by a device not verified by its owner."); + + const penultimate = page.locator(".mx_EventTile").filter({ hasText: "test encrypted from verified" }); + await expect(penultimate.locator(".mx_EventTile_e2eIcon")).not.toBeVisible(); + }); }); });