|
| 1 | +/* |
| 2 | +Copyright 2024 New Vector Ltd. |
| 3 | +
|
| 4 | +SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only |
| 5 | +Please see LICENSE files in the repository root for full details. |
| 6 | +*/ |
| 7 | + |
| 8 | +import { expect, test } from "../../element-web-test"; |
| 9 | +import { autoJoin, createSecondBotDevice, createSharedRoomWithUser, verify } from "./utils"; |
| 10 | +import { bootstrapCrossSigningForClient } from "../../pages/client.ts"; |
| 11 | + |
| 12 | +/** Tests for the "invisible crypto" behaviour -- i.e., when the "exclude insecure devices" setting is enabled */ |
| 13 | +test.describe("Invisible cryptography", () => { |
| 14 | + test.use({ |
| 15 | + displayName: "Alice", |
| 16 | + botCreateOpts: { displayName: "Bob" }, |
| 17 | + labsFlags: ["feature_exclude_insecure_devices"], |
| 18 | + }); |
| 19 | + |
| 20 | + test("Messages fail to decrypt when sender is previously verified", async ({ |
| 21 | + page, |
| 22 | + bot: bob, |
| 23 | + user: aliceCredentials, |
| 24 | + app, |
| 25 | + homeserver, |
| 26 | + }) => { |
| 27 | + await app.client.bootstrapCrossSigning(aliceCredentials); |
| 28 | + await autoJoin(bob); |
| 29 | + |
| 30 | + // create an encrypted room |
| 31 | + const testRoomId = await createSharedRoomWithUser(app, bob.credentials.userId, { |
| 32 | + name: "TestRoom", |
| 33 | + initial_state: [ |
| 34 | + { |
| 35 | + type: "m.room.encryption", |
| 36 | + state_key: "", |
| 37 | + content: { |
| 38 | + algorithm: "m.megolm.v1.aes-sha2", |
| 39 | + }, |
| 40 | + }, |
| 41 | + ], |
| 42 | + }); |
| 43 | + |
| 44 | + // Verify Bob |
| 45 | + await verify(app, bob); |
| 46 | + |
| 47 | + // Bob logs in a new device and resets cross-signing |
| 48 | + const bobSecondDevice = await createSecondBotDevice(page, homeserver, bob); |
| 49 | + await bootstrapCrossSigningForClient(await bobSecondDevice.prepareClient(), bob.credentials, true); |
| 50 | + |
| 51 | + /* should show an error for a message from a previously verified device */ |
| 52 | + await bobSecondDevice.sendMessage(testRoomId, "test encrypted from user that was previously verified"); |
| 53 | + const lastTile = page.locator(".mx_EventTile_last"); |
| 54 | + await expect(lastTile).toContainText("Verified identity has changed"); |
| 55 | + }); |
| 56 | +}); |
0 commit comments