@@ -6,9 +6,12 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
6
6
Please see LICENSE files in the repository root for full details.
7
7
*/
8
8
9
+ import { Page } from "@playwright/test" ;
10
+
9
11
import { expect , test } from "../../element-web-test" ;
10
12
import { autoJoin , createSharedRoomWithUser , enableKeyBackup , logIntoElement , logOutOfElement , verify } from "./utils" ;
11
13
import { Bot } from "../../pages/bot" ;
14
+ import { HomeserverInstance } from "../../plugins/homeserver" ;
12
15
13
16
test . describe ( "Cryptography" , function ( ) {
14
17
test . use ( {
@@ -48,14 +51,7 @@ test.describe("Cryptography", function () {
48
51
homeserver,
49
52
} , workerInfo ) => {
50
53
// 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 ) ;
59
55
60
56
await bob . sendEvent ( testRoomId , null , "m.room.encrypted" , {
61
57
algorithm : "m.megolm.v1.aes-sha2" ,
@@ -216,14 +212,7 @@ test.describe("Cryptography", function () {
216
212
217
213
test ( "should show the correct shield on edited e2e events" , async ( { page, app, bot : bob , homeserver } ) => {
218
214
// 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 ) ;
227
216
228
217
// verify Bob
229
218
await verify ( app , bob ) ;
@@ -269,5 +258,51 @@ test.describe("Cryptography", function () {
269
258
page . locator ( ".mx_EventTile" , { hasText : "Hee!" } ) . locator ( ".mx_EventTile_e2eIcon_warning" ) ,
270
259
) . not . toBeVisible ( ) ;
271
260
} ) ;
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 ( / m x _ E v e n t T i l e _ e 2 e I c o n _ w a r n i n g / ) ;
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
+ } ) ;
272
297
} ) ;
273
298
} ) ;
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