@@ -18,6 +18,9 @@ limitations under the License.
18
18
import anotherjson from "another-json" ;
19
19
import MockHttpBackend from "matrix-mock-request" ;
20
20
21
+ import "fake-indexeddb/auto" ;
22
+ import { IDBFactory } from "fake-indexeddb" ;
23
+
21
24
import * as testUtils from "../test-utils/test-utils" ;
22
25
import { TestClient } from "../TestClient" ;
23
26
import { logger } from "../../src/logger" ;
@@ -38,9 +41,17 @@ import {
38
41
} from "../../src/matrix" ;
39
42
import { IDeviceKeys } from "../../src/crypto/dehydration" ;
40
43
import { DeviceInfo } from "../../src/crypto/deviceinfo" ;
44
+ import { CRYPTO_BACKENDS , InitCrypto } from "../test-utils/test-utils" ;
41
45
42
46
const ROOM_ID = "!room:id" ;
43
47
48
+ afterEach ( ( ) => {
49
+ // reset fake-indexeddb after each test, to make sure we don't leak connections
50
+ // cf https://github.com/dumbmatter/fakeIndexedDB#wipingresetting-the-indexeddb-for-a-fresh-state
51
+ // eslint-disable-next-line no-global-assign
52
+ indexedDB = new IDBFactory ( ) ;
53
+ } ) ;
54
+
44
55
// start an Olm session with a given recipient
45
56
async function createOlmSession ( olmAccount : Olm . Account , recipientTestClient : TestClient ) : Promise < Olm . Session > {
46
57
const keys = await recipientTestClient . awaitOneTimeKeyUpload ( ) ;
@@ -341,11 +352,17 @@ async function expectSendMegolmMessage(
341
352
return JSON . parse ( r . plaintext ) ;
342
353
}
343
354
344
- describe ( "megolm" , ( ) => {
355
+ describe . each ( Object . entries ( CRYPTO_BACKENDS ) ) ( "megolm (%s) " , ( backend : string , initCrypto : InitCrypto ) => {
345
356
if ( ! global . Olm ) {
357
+ // currently we use libolm to implement the crypto in the tests, so need it to be present.
346
358
logger . warn ( "not running megolm tests: Olm not present" ) ;
347
359
return ;
348
360
}
361
+
362
+ // oldBackendOnly is an alternative to `it` or `test` which will skip the test if we are running against the
363
+ // Rust backend. Once we have full support in the rust sdk, it will go away.
364
+ const oldBackendOnly = backend === "rust-sdk" ? test . skip : test ;
365
+
349
366
const Olm = global . Olm ;
350
367
351
368
let testOlmAccount = { } as unknown as Olm . Account ;
@@ -410,8 +427,10 @@ describe("megolm", () => {
410
427
411
428
beforeEach ( async ( ) => {
412
429
aliceTestClient = new TestClient ( "@alice:localhost" , "xzcvb" , "akjgkrgjs" ) ;
413
- await aliceTestClient . client . initCrypto ( ) ;
430
+ await initCrypto ( aliceTestClient . client ) ;
414
431
432
+ // create a test olm device which we will use to communicate with alice. We use libolm to implement this.
433
+ await Olm . init ( ) ;
415
434
testOlmAccount = new Olm . Account ( ) ;
416
435
testOlmAccount . create ( ) ;
417
436
const testE2eKeys = JSON . parse ( testOlmAccount . identity_keys ( ) ) ;
@@ -615,7 +634,7 @@ describe("megolm", () => {
615
634
expect ( event . getContent ( ) . body ) . toEqual ( "42" ) ;
616
635
} ) ;
617
636
618
- it ( "Alice sends a megolm message" , async ( ) => {
637
+ oldBackendOnly ( "Alice sends a megolm message" , async ( ) => {
619
638
aliceTestClient . expectKeyQuery ( { device_keys : { "@alice:localhost" : { } } , failures : { } } ) ;
620
639
await aliceTestClient . start ( ) ;
621
640
const p2pSession = await establishOlmSession ( aliceTestClient , testOlmAccount ) ;
@@ -658,7 +677,7 @@ describe("megolm", () => {
658
677
] ) ;
659
678
} ) ;
660
679
661
- it ( "We shouldn't attempt to send to blocked devices" , async ( ) => {
680
+ oldBackendOnly ( "We shouldn't attempt to send to blocked devices" , async ( ) => {
662
681
aliceTestClient . expectKeyQuery ( { device_keys : { "@alice:localhost" : { } } , failures : { } } ) ;
663
682
await aliceTestClient . start ( ) ;
664
683
await establishOlmSession ( aliceTestClient , testOlmAccount ) ;
@@ -702,7 +721,7 @@ describe("megolm", () => {
702
721
expect ( ( ) => aliceTestClient . client . getGlobalErrorOnUnknownDevices ( ) ) . toThrowError ( "encryption disabled" ) ;
703
722
} ) ;
704
723
705
- it ( "should permit sending to unknown devices" , async ( ) => {
724
+ oldBackendOnly ( "should permit sending to unknown devices" , async ( ) => {
706
725
expect ( aliceTestClient . client . getGlobalErrorOnUnknownDevices ( ) ) . toBeTruthy ( ) ;
707
726
708
727
aliceTestClient . expectKeyQuery ( { device_keys : { "@alice:localhost" : { } } , failures : { } } ) ;
@@ -760,7 +779,7 @@ describe("megolm", () => {
760
779
) ;
761
780
} ) ;
762
781
763
- it ( "should disable sending to unverified devices" , async ( ) => {
782
+ oldBackendOnly ( "should disable sending to unverified devices" , async ( ) => {
764
783
aliceTestClient . expectKeyQuery ( { device_keys : { "@alice:localhost" : { } } , failures : { } } ) ;
765
784
await aliceTestClient . start ( ) ;
766
785
const p2pSession = await establishOlmSession ( aliceTestClient , testOlmAccount ) ;
@@ -818,7 +837,7 @@ describe("megolm", () => {
818
837
} ) ;
819
838
} ) ;
820
839
821
- it ( "We should start a new megolm session when a device is blocked" , async ( ) => {
840
+ oldBackendOnly ( "We should start a new megolm session when a device is blocked" , async ( ) => {
822
841
aliceTestClient . expectKeyQuery ( { device_keys : { "@alice:localhost" : { } } , failures : { } } ) ;
823
842
await aliceTestClient . start ( ) ;
824
843
const p2pSession = await establishOlmSession ( aliceTestClient , testOlmAccount ) ;
@@ -876,7 +895,7 @@ describe("megolm", () => {
876
895
} ) ;
877
896
878
897
// https://github.com/vector-im/element-web/issues/2676
879
- it ( "Alice should send to her other devices" , async ( ) => {
898
+ oldBackendOnly ( "Alice should send to her other devices" , async ( ) => {
880
899
// for this test, we make the testOlmAccount be another of Alice's devices.
881
900
// it ought to get included in messages Alice sends.
882
901
await aliceTestClient . start ( ) ;
@@ -957,7 +976,7 @@ describe("megolm", () => {
957
976
expect ( decrypted . content ?. body ) . toEqual ( "test" ) ;
958
977
} ) ;
959
978
960
- it ( "Alice should wait for device list to complete when sending a megolm message" , async ( ) => {
979
+ oldBackendOnly ( "Alice should wait for device list to complete when sending a megolm message" , async ( ) => {
961
980
aliceTestClient . expectKeyQuery ( { device_keys : { "@alice:localhost" : { } } , failures : { } } ) ;
962
981
await aliceTestClient . start ( ) ;
963
982
await establishOlmSession ( aliceTestClient , testOlmAccount ) ;
@@ -1047,7 +1066,7 @@ describe("megolm", () => {
1047
1066
aliceTestClient . stop ( ) ;
1048
1067
1049
1068
aliceTestClient = new TestClient ( "@alice:localhost" , "device2" , "access_token2" ) ;
1050
- await aliceTestClient . client . initCrypto ( ) ;
1069
+ await initCrypto ( aliceTestClient . client ) ;
1051
1070
await aliceTestClient . client . importRoomKeys ( exported ) ;
1052
1071
await aliceTestClient . start ( ) ;
1053
1072
@@ -1189,7 +1208,7 @@ describe("megolm", () => {
1189
1208
expect ( decryptedEvent . getClearContent ( ) ) . toBeUndefined ( ) ;
1190
1209
} ) ;
1191
1210
1192
- it ( "Alice receives shared history before being invited to a room by the sharer" , async ( ) => {
1211
+ oldBackendOnly ( "Alice receives shared history before being invited to a room by the sharer" , async ( ) => {
1193
1212
const beccaTestClient = new TestClient ( "@becca:localhost" , "foobar" , "bazquux" ) ;
1194
1213
await beccaTestClient . client . initCrypto ( ) ;
1195
1214
@@ -1341,7 +1360,7 @@ describe("megolm", () => {
1341
1360
await beccaTestClient . stop ( ) ;
1342
1361
} ) ;
1343
1362
1344
- it ( "Alice receives shared history before being invited to a room by someone else" , async ( ) => {
1363
+ oldBackendOnly ( "Alice receives shared history before being invited to a room by someone else" , async ( ) => {
1345
1364
const beccaTestClient = new TestClient ( "@becca:localhost" , "foobar" , "bazquux" ) ;
1346
1365
await beccaTestClient . client . initCrypto ( ) ;
1347
1366
@@ -1487,7 +1506,7 @@ describe("megolm", () => {
1487
1506
await beccaTestClient . stop ( ) ;
1488
1507
} ) ;
1489
1508
1490
- it ( "allows sending an encrypted event as soon as room state arrives" , async ( ) => {
1509
+ oldBackendOnly ( "allows sending an encrypted event as soon as room state arrives" , async ( ) => {
1491
1510
/* Empirically, clients expect to be able to send encrypted events as soon as the
1492
1511
* RoomStateEvent.NewMember notification is emitted, so test that works correctly.
1493
1512
*/
@@ -1612,7 +1631,7 @@ describe("megolm", () => {
1612
1631
await aliceTestClient . httpBackend . flush ( membersPath , 1 ) ;
1613
1632
}
1614
1633
1615
- it ( "Sending an event initiates a member list sync" , async ( ) => {
1634
+ oldBackendOnly ( "Sending an event initiates a member list sync" , async ( ) => {
1616
1635
// we expect a call to the /members list...
1617
1636
const memberListPromise = expectMembershipRequest ( ROOM_ID , [ "@bob:xyz" ] ) ;
1618
1637
@@ -1644,7 +1663,7 @@ describe("megolm", () => {
1644
1663
] ) ;
1645
1664
} ) ;
1646
1665
1647
- it ( "loading the membership list inhibits a later load" , async ( ) => {
1666
+ oldBackendOnly ( "loading the membership list inhibits a later load" , async ( ) => {
1648
1667
const room = aliceTestClient . client . getRoom ( ROOM_ID ) ! ;
1649
1668
await Promise . all ( [ room . loadMembersIfNeeded ( ) , expectMembershipRequest ( ROOM_ID , [ "@bob:xyz" ] ) ] ) ;
1650
1669
@@ -1676,7 +1695,7 @@ describe("megolm", () => {
1676
1695
// TODO: there are a bunch more tests for this sort of thing in spec/unit/crypto/algorithms/megolm.spec.ts.
1677
1696
// They should be converted to integ tests and moved.
1678
1697
1679
- it ( "does not block decryption on an 'm.unavailable' report" , async function ( ) {
1698
+ oldBackendOnly ( "does not block decryption on an 'm.unavailable' report" , async function ( ) {
1680
1699
await aliceTestClient . start ( ) ;
1681
1700
1682
1701
// there may be a key downloads for alice
0 commit comments