Skip to content

Commit 940d358

Browse files
authored
Test: stop loading Olm into global namespace (#4895)
* Test: stop loading Olm into global namespace Now that the js-sdk no longer relies on libolm, there is no need to populate `globalThis.Olm`. Remove the code that did so (or relied on it being done). * fix lint
1 parent 161c12f commit 940d358

File tree

6 files changed

+8
-51
lines changed

6 files changed

+8
-51
lines changed

spec/TestClient.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ limitations under the License.
1919
// `expect` is allowed in helper functions which are called within `test`/`it` blocks
2020
/* eslint-disable jest/no-standalone-expect */
2121

22-
// load olm before the sdk if possible
23-
import "./olm-loader";
24-
2522
import MockHttpBackend from "matrix-mock-request";
2623

2724
import type { IDeviceKeys, IOneTimeKey } from "../src/@types/crypto";

spec/integ/crypto/crypto.spec.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import anotherjson from "another-json";
1919
import fetchMock from "fetch-mock-jest";
2020
import "fake-indexeddb/auto";
2121
import { IDBFactory } from "fake-indexeddb";
22+
import Olm from "@matrix-org/olm";
2223

2324
import type FetchMock from "fetch-mock";
24-
import type Olm from "@matrix-org/olm";
2525
import * as testUtils from "../../test-utils/test-utils";
2626
import {
2727
emitPromise,
@@ -124,7 +124,6 @@ async function expectSendRoomKey(
124124
recipientOlmAccount: Olm.Account,
125125
recipientOlmSession: Olm.Session | null = null,
126126
): Promise<Olm.InboundGroupSession> {
127-
const Olm = globalThis.Olm;
128127
const testRecipientKey = JSON.parse(recipientOlmAccount.identity_keys())["curve25519"];
129128

130129
function onSendRoomKey(content: any): Olm.InboundGroupSession {
@@ -207,14 +206,6 @@ async function expectSendMegolmMessage(
207206
}
208207

209208
describe("crypto", () => {
210-
if (!globalThis.Olm) {
211-
// currently we use libolm to implement the crypto in the tests, so need it to be present.
212-
logger.warn("not running megolm tests: Olm not present");
213-
return;
214-
}
215-
216-
const Olm = globalThis.Olm;
217-
218209
let testOlmAccount = {} as unknown as Olm.Account;
219210
let testSenderKey = "";
220211

spec/integ/crypto/olm-utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ export function bootstrapCrossSigningTestOlmAccount(
9393
deviceId: string,
9494
keyBackupInfo: KeyBackupInfo[] = [],
9595
): Partial<IDownloadKeyResult> {
96-
const olmAliceMSK = new globalThis.Olm.PkSigning();
96+
const olmAliceMSK = new Olm.PkSigning();
9797
const masterPrivkey = olmAliceMSK.generate_seed();
9898
const masterPubkey = olmAliceMSK.init_with_seed(masterPrivkey);
9999

100-
const olmAliceUSK = new globalThis.Olm.PkSigning();
100+
const olmAliceUSK = new Olm.PkSigning();
101101
const userPrivkey = olmAliceUSK.generate_seed();
102102
const userPubkey = olmAliceUSK.init_with_seed(userPrivkey);
103103

104-
const olmAliceSSK = new globalThis.Olm.PkSigning();
104+
const olmAliceSSK = new Olm.PkSigning();
105105
const sskPrivkey = olmAliceSSK.generate_seed();
106106
const sskPubkey = olmAliceSSK.init_with_seed(sskPrivkey);
107107

@@ -189,7 +189,7 @@ export async function createOlmSession(
189189
const otkId = Object.keys(keys)[0];
190190
const otk = keys[otkId];
191191

192-
const session = new globalThis.Olm.Session();
192+
const session = new Olm.Session();
193193
session.create_outbound(olmAccount, recipientTestClient.getDeviceKey(), otk.key);
194194
return session;
195195
}

spec/integ/crypto/verification.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jest.useFakeTimers({ doNotFake: ["queueMicrotask"] });
8484

8585
beforeAll(async () => {
8686
// we use the libolm primitives in the test, so init the Olm library
87-
await globalThis.Olm.init();
87+
await Olm.init();
8888
});
8989

9090
// 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";
110110
* These tests work by intercepting HTTP requests via fetch-mock rather than mocking out bits of the client, so as
111111
* to provide the most effective integration tests possible.
112112
*/
113-
// we test with both crypto stacks...
114113
describe("verification", () => {
115114
/** the client under test */
116115
let aliceClient: MatrixClient;
@@ -254,7 +253,7 @@ describe("verification", () => {
254253

255254
// The dummy device makes up a curve25519 keypair and sends the public bit back in an `m.key.verification.key'
256255
// We use the Curve25519, HMAC and HKDF implementations in libolm, for now
257-
const olmSAS = new globalThis.Olm.SAS();
256+
const olmSAS = new Olm.SAS();
258257
returnToDeviceMessageFromSync(buildSasKeyMessage(transactionId, olmSAS.get_pubkey()));
259258

260259
// alice responds with a 'key' ...
@@ -348,7 +347,7 @@ describe("verification", () => {
348347

349348
// The dummy device makes up a curve25519 keypair and uses the hash in an 'm.key.verification.accept'
350349
// We use the Curve25519, HMAC and HKDF implementations in libolm, for now
351-
const olmSAS = new globalThis.Olm.SAS();
350+
const olmSAS = new Olm.SAS();
352351
const commitmentStr = olmSAS.get_pubkey() + anotherjson.stringify(toDeviceMessage);
353352

354353
sendToDevicePromise = expectSendToDeviceMessage("m.key.verification.key");

spec/olm-loader.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

spec/test-utils/test-utils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// load olm before the sdk if possible
2-
import "../olm-loader";
3-
41
// eslint-disable-next-line no-restricted-imports
52
import type EventEmitter from "events";
63
import { logger } from "../../src/logger";

0 commit comments

Comments
 (0)