@@ -424,13 +424,18 @@ describe("megolm", () => {
424
424
425
425
it ( "Alice receives a megolm message" , async ( ) => {
426
426
await aliceTestClient . start ( ) ;
427
- aliceTestClient . client . crypto ! . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
427
+
428
+ // if we're using the old crypto impl, stub out some methods in the device manager.
429
+ // TODO: replace this with intercepts of the /keys/query endpoint to make it impl agnostic.
430
+ if ( aliceTestClient . client . crypto ) {
431
+ aliceTestClient . client . crypto . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
432
+ aliceTestClient . client . crypto . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
433
+ }
434
+
428
435
const p2pSession = await createOlmSession ( testOlmAccount , aliceTestClient ) ;
429
436
const groupSession = new Olm . OutboundGroupSession ( ) ;
430
437
groupSession . create ( ) ;
431
438
432
- aliceTestClient . client . crypto ! . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
433
-
434
439
// make the room_key event
435
440
const roomKeyEncrypted = encryptGroupSessionKey ( {
436
441
recipient : aliceTestClient ,
@@ -472,16 +477,21 @@ describe("megolm", () => {
472
477
expect ( decryptedEvent . getContent ( ) . body ) . toEqual ( "42" ) ;
473
478
} ) ;
474
479
475
- it ( "Alice receives a megolm message before the session keys" , async ( ) => {
480
+ oldBackendOnly ( "Alice receives a megolm message before the session keys" , async ( ) => {
476
481
// https://github.com/vector-im/element-web/issues/2273
477
482
await aliceTestClient . start ( ) ;
478
- aliceTestClient . client . crypto ! . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
483
+
484
+ // if we're using the old crypto impl, stub out some methods in the device manager.
485
+ // TODO: replace this with intercepts of the /keys/query endpoint to make it impl agnostic.
486
+ if ( aliceTestClient . client . crypto ) {
487
+ aliceTestClient . client . crypto . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
488
+ aliceTestClient . client . crypto . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
489
+ }
490
+
479
491
const p2pSession = await createOlmSession ( testOlmAccount , aliceTestClient ) ;
480
492
const groupSession = new Olm . OutboundGroupSession ( ) ;
481
493
groupSession . create ( ) ;
482
494
483
- aliceTestClient . client . crypto ! . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
484
-
485
495
// make the room_key event, but don't send it yet
486
496
const roomKeyEncrypted = encryptGroupSessionKey ( {
487
497
recipient : aliceTestClient ,
@@ -535,13 +545,18 @@ describe("megolm", () => {
535
545
536
546
it ( "Alice gets a second room_key message" , async ( ) => {
537
547
await aliceTestClient . start ( ) ;
538
- aliceTestClient . client . crypto ! . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
548
+
549
+ // if we're using the old crypto impl, stub out some methods in the device manager.
550
+ // TODO: replace this with intercepts of the /keys/query endpoint to make it impl agnostic.
551
+ if ( aliceTestClient . client . crypto ) {
552
+ aliceTestClient . client . crypto . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
553
+ aliceTestClient . client . crypto . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
554
+ }
555
+
539
556
const p2pSession = await createOlmSession ( testOlmAccount , aliceTestClient ) ;
540
557
const groupSession = new Olm . OutboundGroupSession ( ) ;
541
558
groupSession . create ( ) ;
542
559
543
- aliceTestClient . client . crypto ! . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
544
-
545
560
// make the room_key event
546
561
const roomKeyEncrypted1 = encryptGroupSessionKey ( {
547
562
recipient : aliceTestClient ,
@@ -972,15 +987,20 @@ describe("megolm", () => {
972
987
await Promise . all ( [ downloadPromise , sendPromise ] ) ;
973
988
} ) ;
974
989
975
- it ( "Alice exports megolm keys and imports them to a new device" , async ( ) => {
990
+ oldBackendOnly ( "Alice exports megolm keys and imports them to a new device" , async ( ) => {
976
991
aliceTestClient . expectKeyQuery ( { device_keys : { "@alice:localhost" : { } } , failures : { } } ) ;
977
992
await aliceTestClient . start ( ) ;
978
- aliceTestClient . client . crypto ! . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
993
+
994
+ // if we're using the old crypto impl, stub out some methods in the device manager.
995
+ // TODO: replace this with intercepts of the /keys/query endpoint to make it impl agnostic.
996
+ if ( aliceTestClient . client . crypto ) {
997
+ aliceTestClient . client . crypto . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
998
+ aliceTestClient . client . crypto . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
999
+ }
1000
+
979
1001
// establish an olm session with alice
980
1002
const p2pSession = await createOlmSession ( testOlmAccount , aliceTestClient ) ;
981
1003
982
- aliceTestClient . client . crypto ! . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
983
-
984
1004
const groupSession = new Olm . OutboundGroupSession ( ) ;
985
1005
groupSession . create ( ) ;
986
1006
@@ -1031,7 +1051,11 @@ describe("megolm", () => {
1031
1051
await aliceTestClient . client . importRoomKeys ( exported ) ;
1032
1052
await aliceTestClient . start ( ) ;
1033
1053
1034
- aliceTestClient . client . crypto ! . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
1054
+ // if we're using the old crypto impl, stub out some methods in the device manager.
1055
+ // TODO: replace this with intercepts of the /keys/query endpoint to make it impl agnostic.
1056
+ if ( aliceTestClient . client . crypto ) {
1057
+ aliceTestClient . client . crypto . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
1058
+ }
1035
1059
1036
1060
const syncResponse = {
1037
1061
next_batch : 1 ,
@@ -1107,13 +1131,18 @@ describe("megolm", () => {
1107
1131
1108
1132
it ( "Alice can decrypt a message with falsey content" , async ( ) => {
1109
1133
await aliceTestClient . start ( ) ;
1110
- aliceTestClient . client . crypto ! . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
1134
+
1135
+ // if we're using the old crypto impl, stub out some methods in the device manager.
1136
+ // TODO: replace this with intercepts of the /keys/query endpoint to make it impl agnostic.
1137
+ if ( aliceTestClient . client . crypto ) {
1138
+ aliceTestClient . client . crypto . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
1139
+ aliceTestClient . client . crypto . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
1140
+ }
1141
+
1111
1142
const p2pSession = await createOlmSession ( testOlmAccount , aliceTestClient ) ;
1112
1143
const groupSession = new Olm . OutboundGroupSession ( ) ;
1113
1144
groupSession . create ( ) ;
1114
1145
1115
- aliceTestClient . client . crypto ! . deviceList . getUserByIdentityKey = ( ) => "@bob:xyz" ;
1116
-
1117
1146
// make the room_key event
1118
1147
const roomKeyEncrypted = encryptGroupSessionKey ( {
1119
1148
recipient : aliceTestClient ,
@@ -1165,9 +1194,16 @@ describe("megolm", () => {
1165
1194
await beccaTestClient . client . initCrypto ( ) ;
1166
1195
1167
1196
await aliceTestClient . start ( ) ;
1168
- aliceTestClient . client . crypto ! . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
1169
1197
await beccaTestClient . start ( ) ;
1170
1198
1199
+ // if we're using the old crypto impl, stub out some methods in the device manager.
1200
+ // TODO: replace this with intercepts of the /keys/query endpoint to make it impl agnostic.
1201
+ if ( aliceTestClient . client . crypto ) {
1202
+ aliceTestClient . client . crypto ! . deviceList . downloadKeys = ( ) => Promise . resolve ( { } ) ;
1203
+ aliceTestClient . client . crypto ! . deviceList . getDeviceByIdentityKey = ( ) => device ;
1204
+ aliceTestClient . client . crypto ! . deviceList . getUserByIdentityKey = ( ) => beccaTestClient . client . getUserId ( ) ! ;
1205
+ }
1206
+
1171
1207
const beccaRoom = new Room ( ROOM_ID , beccaTestClient . client , "@becca:localhost" , { } ) ;
1172
1208
beccaTestClient . client . store . storeRoom ( beccaRoom ) ;
1173
1209
await beccaTestClient . client . setRoomEncryption ( ROOM_ID , { algorithm : "m.megolm.v1.aes-sha2" } ) ;
@@ -1193,8 +1229,6 @@ describe("megolm", () => {
1193
1229
event . claimedEd25519Key = null ;
1194
1230
1195
1231
const device = new DeviceInfo ( beccaTestClient . client . deviceId ! ) ;
1196
- aliceTestClient . client . crypto ! . deviceList . getDeviceByIdentityKey = ( ) => device ;
1197
- aliceTestClient . client . crypto ! . deviceList . getUserByIdentityKey = ( ) => beccaTestClient . client . getUserId ( ) ! ;
1198
1232
1199
1233
// Create an olm session for Becca and Alice's devices
1200
1234
const aliceOtks = await aliceTestClient . awaitOneTimeKeyUpload ( ) ;
0 commit comments