@@ -7,8 +7,15 @@ Please see LICENSE files in the repository root for full details.
77*/
88
99import { expect , test } from "../../element-web-test" ;
10- import { autoJoin , createSharedRoomWithUser , enableKeyBackup , logIntoElement , logOutOfElement , verify } from "./utils" ;
11- import { Bot } from "../../pages/bot" ;
10+ import {
11+ autoJoin ,
12+ createSecondBotDevice ,
13+ createSharedRoomWithUser ,
14+ enableKeyBackup ,
15+ logIntoElement ,
16+ logOutOfElement ,
17+ verify ,
18+ } from "./utils" ;
1219
1320test . describe ( "Cryptography" , function ( ) {
1421 test . use ( {
@@ -41,16 +48,14 @@ test.describe("Cryptography", function () {
4148 } ) ;
4249 } ) ;
4350
44- test ( "should show the correct shield on e2e events" , async ( { page, app, bot : bob , homeserver } ) => {
51+ test ( "should show the correct shield on e2e events" , async ( {
52+ page,
53+ app,
54+ bot : bob ,
55+ homeserver,
56+ } , workerInfo ) => {
4557 // Bob has a second, not cross-signed, device
46- const bobSecondDevice = new Bot ( page , homeserver , {
47- bootstrapSecretStorage : false ,
48- bootstrapCrossSigning : false ,
49- } ) ;
50- bobSecondDevice . setCredentials (
51- await homeserver . loginUser ( bob . credentials . userId , bob . credentials . password ) ,
52- ) ;
53- await bobSecondDevice . prepareClient ( ) ;
58+ const bobSecondDevice = await createSecondBotDevice ( page , homeserver , bob ) ;
5459
5560 await bob . sendEvent ( testRoomId , null , "m.room.encrypted" , {
5661 algorithm : "m.megolm.v1.aes-sha2" ,
@@ -117,7 +122,10 @@ test.describe("Cryptography", function () {
117122 await lastTileE2eIcon . focus ( ) ;
118123 await expect ( page . getByRole ( "tooltip" ) ) . toContainText ( "Encrypted by a device not verified by its owner." ) ;
119124
120- /* Should show a grey padlock for a message from an unknown device */
125+ /* In legacy crypto: should show a grey padlock for a message from a deleted device.
126+ * In rust crypto: should show a red padlock for a message from an unverified device.
127+ * Rust crypto remembers the verification state of the sending device, so it will know that the device was
128+ * unverified, even if it gets deleted. */
121129 // bob deletes his second device
122130 await bobSecondDevice . evaluate ( ( cli ) => cli . logout ( true ) ) ;
123131
@@ -148,7 +156,11 @@ test.describe("Cryptography", function () {
148156 await expect ( last ) . toContainText ( "test encrypted from unverified" ) ;
149157 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 / ) ;
150158 await lastE2eIcon . focus ( ) ;
151- await expect ( page . getByRole ( "tooltip" ) ) . toContainText ( "Encrypted by an unknown or deleted device." ) ;
159+ await expect ( page . getByRole ( "tooltip" ) ) . toContainText (
160+ workerInfo . project . name === "Legacy Crypto"
161+ ? "Encrypted by an unknown or deleted device."
162+ : "Encrypted by a device not verified by its owner." ,
163+ ) ;
152164 } ) ;
153165
154166 test ( "Should show a grey padlock for a key restored from backup" , async ( {
@@ -204,14 +216,7 @@ test.describe("Cryptography", function () {
204216
205217 test ( "should show the correct shield on edited e2e events" , async ( { page, app, bot : bob , homeserver } ) => {
206218 // bob has a second, not cross-signed, device
207- const bobSecondDevice = new Bot ( page , homeserver , {
208- bootstrapSecretStorage : false ,
209- bootstrapCrossSigning : false ,
210- } ) ;
211- bobSecondDevice . setCredentials (
212- await homeserver . loginUser ( bob . credentials . userId , bob . credentials . password ) ,
213- ) ;
214- await bobSecondDevice . prepareClient ( ) ;
219+ const bobSecondDevice = await createSecondBotDevice ( page , homeserver , bob ) ;
215220
216221 // verify Bob
217222 await verify ( app , bob ) ;
@@ -257,5 +262,41 @@ test.describe("Cryptography", function () {
257262 page . locator ( ".mx_EventTile" , { hasText : "Hee!" } ) . locator ( ".mx_EventTile_e2eIcon_warning" ) ,
258263 ) . not . toBeVisible ( ) ;
259264 } ) ;
265+
266+ test ( "should show correct shields on events sent by devices which have since been deleted" , async ( {
267+ page,
268+ app,
269+ bot : bob ,
270+ homeserver,
271+ } ) => {
272+ // Our app is blocked from syncing while Bob sends his messages.
273+ await app . client . network . goOffline ( ) ;
274+
275+ // Bob sends a message from his verified device
276+ await bob . sendMessage ( testRoomId , "test encrypted from verified" ) ;
277+
278+ // And one from a second, not cross-signed, device
279+ const bobSecondDevice = await createSecondBotDevice ( page , homeserver , bob ) ;
280+ await bobSecondDevice . waitForNextSync ( ) ; // make sure the client knows the room is encrypted
281+ await bobSecondDevice . sendMessage ( testRoomId , "test encrypted from unverified" ) ;
282+
283+ // ... and then logs out both devices.
284+ await bob . evaluate ( ( cli ) => cli . logout ( true ) ) ;
285+ await bobSecondDevice . evaluate ( ( cli ) => cli . logout ( true ) ) ;
286+
287+ // Let our app start syncing again
288+ await app . client . network . goOnline ( ) ;
289+
290+ // Wait for the messages to arrive
291+ const last = page . locator ( ".mx_EventTile_last" ) ;
292+ await expect ( last ) . toContainText ( "test encrypted from unverified" ) ;
293+ const lastE2eIcon = last . locator ( ".mx_EventTile_e2eIcon" ) ;
294+ 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 / ) ;
295+ await lastE2eIcon . focus ( ) ;
296+ await expect ( page . getByRole ( "tooltip" ) ) . toContainText ( "Encrypted by a device not verified by its owner." ) ;
297+
298+ const penultimate = page . locator ( ".mx_EventTile" ) . filter ( { hasText : "test encrypted from verified" } ) ;
299+ await expect ( penultimate . locator ( ".mx_EventTile_e2eIcon" ) ) . not . toBeVisible ( ) ;
300+ } ) ;
260301 } ) ;
261302} ) ;
0 commit comments