From c4d32a3292cba650828aab2e5d5f2e6b4e2317f3 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Wed, 24 Jan 2024 09:35:35 +0000 Subject: [PATCH] Bump matrix-sdk-crypto-wasm to 4.0.1 (#4025) * Bump matrix-sdk-crypto-wasm to 4.0.1 * Fix some tests * more test fixes * yet more fixes * update comments --- package.json | 2 +- spec/integ/crypto/cross-signing.spec.ts | 3 ++- spec/integ/crypto/crypto.spec.ts | 16 ++++++++++------ spec/integ/crypto/megolm-backup.spec.ts | 3 ++- spec/integ/crypto/verification.spec.ts | 11 ++++++----- spec/unit/rust-crypto/rust-crypto.spec.ts | 9 ++++++++- yarn.lock | 8 ++++---- 7 files changed, 33 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 66453a493d2..337cb1d20aa 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ ], "dependencies": { "@babel/runtime": "^7.12.5", - "@matrix-org/matrix-sdk-crypto-wasm": "^4.0.0", + "@matrix-org/matrix-sdk-crypto-wasm": "^4.0.1", "another-json": "^0.2.0", "bs58": "^5.0.0", "content-type": "^1.0.4", diff --git a/spec/integ/crypto/cross-signing.spec.ts b/spec/integ/crypto/cross-signing.spec.ts index a06efd20621..a0518d827f3 100644 --- a/spec/integ/crypto/cross-signing.spec.ts +++ b/spec/integ/crypto/cross-signing.spec.ts @@ -398,7 +398,8 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s describe("crossSignDevice", () => { beforeEach(async () => { - jest.useFakeTimers(); + // We want to use fake timers, but the wasm bindings of matrix-sdk-crypto rely on a working `queueMicrotask`. + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); // make sure that there is another device which we can sign e2eKeyResponder.addDeviceKeys(SIGNED_TEST_DEVICE_DATA); diff --git a/spec/integ/crypto/crypto.spec.ts b/spec/integ/crypto/crypto.spec.ts index bac0c46315c..e819cb7cb18 100644 --- a/spec/integ/crypto/crypto.spec.ts +++ b/spec/integ/crypto/crypto.spec.ts @@ -1063,8 +1063,9 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, await startClientAndAwaitFirstSync(); const p2pSession = await establishOlmSession(aliceClient, keyReceiver, syncResponder, testOlmAccount); - // We need to fake the timers to advance the time - jest.useFakeTimers(); + // We need to fake the timers to advance the time, but the wasm bindings of matrix-sdk-crypto rely on a + // working `queueMicrotask` + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); const syncResponse = getSyncResponse(["@bob:xyz"]); @@ -2189,7 +2190,8 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, describe("key upload request", () => { beforeEach(() => { - jest.useFakeTimers(); + // We want to use fake timers, but the wasm bindings of matrix-sdk-crypto rely on a working `queueMicrotask`. + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); }); afterEach(() => { @@ -2389,8 +2391,9 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, expect(devicesInfo.get(user)?.size).toBeFalsy(); }); - it("Get devices from tacked users", async () => { - jest.useFakeTimers(); + it("Get devices from tracked users", async () => { + // We want to use fake timers, but the wasm bindings of matrix-sdk-crypto rely on a working `queueMicrotask`. + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); expectAliceKeyQuery({ device_keys: { "@alice:localhost": {} }, failures: {} }); await startClientAndAwaitFirstSync(); @@ -2745,7 +2748,8 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, describe("Manage Key Backup", () => { beforeEach(async () => { - jest.useFakeTimers(); + // We want to use fake timers, but the wasm bindings of matrix-sdk-crypto rely on a working `queueMicrotask`. + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); }); afterEach(() => { diff --git a/spec/integ/crypto/megolm-backup.spec.ts b/spec/integ/crypto/megolm-backup.spec.ts index f6bd53ef476..11e1c2eb705 100644 --- a/spec/integ/crypto/megolm-backup.spec.ts +++ b/spec/integ/crypto/megolm-backup.spec.ts @@ -129,7 +129,8 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("megolm-keys backup (%s)", (backe let e2eKeyResponder: E2EKeyResponder; beforeEach(async () => { - jest.useFakeTimers(); + // We want to use fake timers, but the wasm bindings of matrix-sdk-crypto rely on a working `queueMicrotask`. + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); // anything that we don't have a specific matcher for silently returns a 404 fetchMock.catch(404); diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index d95097fcfd8..243fd510d58 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -85,7 +85,8 @@ import { encodeBase64 } from "../../../src/base64"; // The verification flows use javascript timers to set timeouts. We tell jest to use mock timer implementations // to ensure that we don't end up with dangling timeouts. -jest.useFakeTimers(); +// But the wasm bindings of matrix-sdk-crypto rely on a working `queueMicrotask`. +jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); beforeAll(async () => { // we use the libolm primitives in the test, so init the Olm library @@ -1285,7 +1286,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st await new Promise((resolve) => { setTimeout(resolve, 500); }); - jest.useFakeTimers(); + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); // the backup secret should not be cached const cachedKey = await aliceClient.getCrypto()!.getSessionBackupPrivateKey(); @@ -1309,7 +1310,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st await new Promise((resolve) => { setTimeout(resolve, 500); }); - jest.useFakeTimers(); + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); // the backup secret should not be cached const cachedKey = await aliceClient.getCrypto()!.getSessionBackupPrivateKey(); @@ -1334,7 +1335,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st await new Promise((resolve) => { setTimeout(resolve, 500); }); - jest.useFakeTimers(); + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); // the backup secret should not be cached const cachedKey = await aliceClient.getCrypto()!.getSessionBackupPrivateKey(); @@ -1355,7 +1356,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st await new Promise((resolve) => { setTimeout(resolve, 500); }); - jest.useFakeTimers(); + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); // the backup secret should not be cached const cachedKey = await aliceClient.getCrypto()!.getSessionBackupPrivateKey(); diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index dbcf0df88c2..68effb2f93b 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -75,6 +75,12 @@ import { CryptoStore, SecretStorePrivateKeys } from "../../../src/crypto/store/b const TEST_USER = "@alice:example.com"; const TEST_DEVICE_ID = "TEST_DEVICE"; +beforeAll(async () => { + // Load the WASM upfront, before any of the tests. This can take some time, and doing it here means that it gets + // a separate timeout. + await RustSdkCryptoJs.initAsync(); +}, 15000); + afterEach(() => { fetchMock.reset(); jest.restoreAllMocks(); @@ -997,7 +1003,8 @@ describe("RustCrypto", () => { }); it("should wait for a keys/query before returning devices", async () => { - jest.useFakeTimers(); + // We want to use fake timers, but the wasm bindings of matrix-sdk-crypto rely on a working `queueMicrotask`. + jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); fetchMock.post("path:/_matrix/client/v3/keys/upload", { one_time_key_counts: {} }); fetchMock.post("path:/_matrix/client/v3/keys/query", { diff --git a/yarn.lock b/yarn.lock index 0d45f7b15fc..19b24992816 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1674,10 +1674,10 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@matrix-org/matrix-sdk-crypto-wasm@^4.0.0": - version "4.0.0" - resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-4.0.0.tgz#b33bae9c418c5516d0dbce29662c6db803003626" - integrity sha512-a883HchJViPo6ukM0fEDmBgvMI6lWEujqAjMZgwaKEYNZTPgezN5PQvSNz2d+b96/R1y4QOC71zXM1yNylXA6Q== +"@matrix-org/matrix-sdk-crypto-wasm@^4.0.1": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-4.0.1.tgz#b1d3848a6adc120622e5225045330d253273b117" + integrity sha512-0B4QQ9kop8AocmQDcOfROCQ6QyGZeogpsvTYfEB9ZIBtndCCwy/C3mkxzJD6+gEo1bJ4TdYnblhN7hEQlAG50g== "@matrix-org/olm@3.2.15": version "3.2.15"