diff --git a/spec/TestClient.ts b/spec/TestClient.ts index 7662b57c6..2192dbce0 100644 --- a/spec/TestClient.ts +++ b/spec/TestClient.ts @@ -19,9 +19,6 @@ limitations under the License. // `expect` is allowed in helper functions which are called within `test`/`it` blocks /* eslint-disable jest/no-standalone-expect */ -// load olm before the sdk if possible -import "./olm-loader"; - import MockHttpBackend from "matrix-mock-request"; import type { IDeviceKeys, IOneTimeKey } from "../src/@types/crypto"; diff --git a/spec/integ/crypto/crypto.spec.ts b/spec/integ/crypto/crypto.spec.ts index f292f9ff4..e1f541a92 100644 --- a/spec/integ/crypto/crypto.spec.ts +++ b/spec/integ/crypto/crypto.spec.ts @@ -19,9 +19,9 @@ import anotherjson from "another-json"; import fetchMock from "fetch-mock-jest"; import "fake-indexeddb/auto"; import { IDBFactory } from "fake-indexeddb"; +import Olm from "@matrix-org/olm"; import type FetchMock from "fetch-mock"; -import type Olm from "@matrix-org/olm"; import * as testUtils from "../../test-utils/test-utils"; import { emitPromise, @@ -124,7 +124,6 @@ async function expectSendRoomKey( recipientOlmAccount: Olm.Account, recipientOlmSession: Olm.Session | null = null, ): Promise { - const Olm = globalThis.Olm; const testRecipientKey = JSON.parse(recipientOlmAccount.identity_keys())["curve25519"]; function onSendRoomKey(content: any): Olm.InboundGroupSession { @@ -207,14 +206,6 @@ async function expectSendMegolmMessage( } describe("crypto", () => { - if (!globalThis.Olm) { - // currently we use libolm to implement the crypto in the tests, so need it to be present. - logger.warn("not running megolm tests: Olm not present"); - return; - } - - const Olm = globalThis.Olm; - let testOlmAccount = {} as unknown as Olm.Account; let testSenderKey = ""; diff --git a/spec/integ/crypto/olm-utils.ts b/spec/integ/crypto/olm-utils.ts index 6052e81ac..0491bb37c 100644 --- a/spec/integ/crypto/olm-utils.ts +++ b/spec/integ/crypto/olm-utils.ts @@ -93,15 +93,15 @@ export function bootstrapCrossSigningTestOlmAccount( deviceId: string, keyBackupInfo: KeyBackupInfo[] = [], ): Partial { - const olmAliceMSK = new globalThis.Olm.PkSigning(); + const olmAliceMSK = new Olm.PkSigning(); const masterPrivkey = olmAliceMSK.generate_seed(); const masterPubkey = olmAliceMSK.init_with_seed(masterPrivkey); - const olmAliceUSK = new globalThis.Olm.PkSigning(); + const olmAliceUSK = new Olm.PkSigning(); const userPrivkey = olmAliceUSK.generate_seed(); const userPubkey = olmAliceUSK.init_with_seed(userPrivkey); - const olmAliceSSK = new globalThis.Olm.PkSigning(); + const olmAliceSSK = new Olm.PkSigning(); const sskPrivkey = olmAliceSSK.generate_seed(); const sskPubkey = olmAliceSSK.init_with_seed(sskPrivkey); @@ -189,7 +189,7 @@ export async function createOlmSession( const otkId = Object.keys(keys)[0]; const otk = keys[otkId]; - const session = new globalThis.Olm.Session(); + const session = new Olm.Session(); session.create_outbound(olmAccount, recipientTestClient.getDeviceKey(), otk.key); return session; } diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index 99c646ccd..b48cdc9b6 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -84,7 +84,7 @@ jest.useFakeTimers({ doNotFake: ["queueMicrotask"] }); beforeAll(async () => { // we use the libolm primitives in the test, so init the Olm library - await globalThis.Olm.init(); + await Olm.init(); }); // load the rust library. This can take a few seconds on a slow GH worker. @@ -110,7 +110,6 @@ const TEST_HOMESERVER_URL = "https://alice-server.com"; * These tests work by intercepting HTTP requests via fetch-mock rather than mocking out bits of the client, so as * to provide the most effective integration tests possible. */ -// we test with both crypto stacks... describe("verification", () => { /** the client under test */ let aliceClient: MatrixClient; @@ -254,7 +253,7 @@ describe("verification", () => { // The dummy device makes up a curve25519 keypair and sends the public bit back in an `m.key.verification.key' // We use the Curve25519, HMAC and HKDF implementations in libolm, for now - const olmSAS = new globalThis.Olm.SAS(); + const olmSAS = new Olm.SAS(); returnToDeviceMessageFromSync(buildSasKeyMessage(transactionId, olmSAS.get_pubkey())); // alice responds with a 'key' ... @@ -348,7 +347,7 @@ describe("verification", () => { // The dummy device makes up a curve25519 keypair and uses the hash in an 'm.key.verification.accept' // We use the Curve25519, HMAC and HKDF implementations in libolm, for now - const olmSAS = new globalThis.Olm.SAS(); + const olmSAS = new Olm.SAS(); const commitmentStr = olmSAS.get_pubkey() + anotherjson.stringify(toDeviceMessage); sendToDevicePromise = expectSendToDeviceMessage("m.key.verification.key"); diff --git a/spec/olm-loader.ts b/spec/olm-loader.ts deleted file mode 100644 index 5f12ca950..000000000 --- a/spec/olm-loader.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2017 Vector creations Ltd -Copyright 2019 The Matrix.org Foundation C.I.C. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -import { logger } from "../src/logger"; - -// try to load the olm library. -try { - // eslint-disable-next-line @typescript-eslint/no-require-imports - globalThis.Olm = require("@matrix-org/olm"); - logger.log("loaded libolm"); -} catch (e) { - logger.warn("unable to run crypto tests: libolm not available", e); -} diff --git a/spec/test-utils/test-utils.ts b/spec/test-utils/test-utils.ts index de45eeef8..d031cdcb8 100644 --- a/spec/test-utils/test-utils.ts +++ b/spec/test-utils/test-utils.ts @@ -1,6 +1,3 @@ -// load olm before the sdk if possible -import "../olm-loader"; - // eslint-disable-next-line no-restricted-imports import type EventEmitter from "events"; import { logger } from "../../src/logger";