Skip to content

Commit 36a58e9

Browse files
committed
test(crypto): remove iteration on CRYPTO_BACKEND
1 parent c109e05 commit 36a58e9

File tree

6 files changed

+15
-39
lines changed

6 files changed

+15
-39
lines changed

spec/integ/crypto/cross-signing.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import fetchMock from "fetch-mock-jest";
1818
import "fake-indexeddb/auto";
1919
import { IDBFactory } from "fake-indexeddb";
2020

21-
import { CRYPTO_BACKENDS, InitCrypto, syncPromise } from "../../test-utils/test-utils";
21+
import { syncPromise } from "../../test-utils/test-utils";
2222
import { AuthDict, createClient, MatrixClient } from "../../../src";
2323
import { mockInitialApiRequests, mockSetupCrossSigningRequests } from "../../test-utils/mockEndpoints";
2424
import encryptAESSecretStorageItem from "../../../src/utils/encryptAESSecretStorageItem.ts";
@@ -55,7 +55,7 @@ const TEST_DEVICE_ID = "xzcvb";
5555
* These tests work by intercepting HTTP requests via fetch-mock rather than mocking out bits of the client, so as
5656
* to provide the most effective integration tests possible.
5757
*/
58-
describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: string, initCrypto: InitCrypto) => {
58+
describe("cross-signing", () => {
5959
let aliceClient: MatrixClient;
6060

6161
/** an object which intercepts `/sync` requests from {@link #aliceClient} */
@@ -104,7 +104,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s
104104
body: { errcode: "M_NOT_FOUND" },
105105
});
106106

107-
await initCrypto(aliceClient);
107+
await aliceClient.initRustCrypto();
108108
},
109109
/* it can take a while to initialise the crypto library on the first pass, so bump up the timeout. */
110110
10000,

spec/integ/crypto/crypto.spec.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ import Olm from "@matrix-org/olm";
2424

2525
import * as testUtils from "../../test-utils/test-utils";
2626
import {
27-
CRYPTO_BACKENDS,
2827
emitPromise,
2928
getSyncResponse,
30-
InitCrypto,
3129
mkEventCustom,
3230
mkMembershipCustom,
3331
syncPromise,
@@ -209,7 +207,7 @@ async function expectSendMegolmMessage(
209207
return JSON.parse(r.plaintext);
210208
}
211209

212-
describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, initCrypto: InitCrypto) => {
210+
describe("crypto", () => {
213211
if (!globalThis.Olm) {
214212
// currently we use libolm to implement the crypto in the tests, so need it to be present.
215213
logger.warn("not running megolm tests: Olm not present");
@@ -369,7 +367,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
369367
keyReceiver = new E2EKeyReceiver(homeserverUrl);
370368
syncResponder = new SyncResponder(homeserverUrl);
371369

372-
await initCrypto(aliceClient);
370+
await aliceClient.initRustCrypto();
373371

374372
// create a test olm device which we will use to communicate with alice. We use libolm to implement this.
375373
testOlmAccount = await createOlmAccount();
@@ -2441,7 +2439,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
24412439
// For legacy crypto, these tests only work with a proper persistent cryptoStore.
24422440
cryptoStore: new IndexedDBCryptoStore(indexedDB, "test"),
24432441
});
2444-
await initCrypto(client);
2442+
await client.initRustCrypto();
24452443
mockInitialApiRequests(client.getHomeserverUrl());
24462444
return client;
24472445
}

spec/integ/crypto/megolm-backup.spec.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ import { SyncResponder } from "../../test-utils/SyncResponder";
3232
import { E2EKeyReceiver } from "../../test-utils/E2EKeyReceiver";
3333
import { E2EKeyResponder } from "../../test-utils/E2EKeyResponder";
3434
import { mockInitialApiRequests } from "../../test-utils/mockEndpoints";
35-
import {
36-
advanceTimersUntil,
37-
awaitDecryption,
38-
CRYPTO_BACKENDS,
39-
InitCrypto,
40-
syncPromise,
41-
} from "../../test-utils/test-utils";
35+
import { advanceTimersUntil, awaitDecryption, syncPromise } from "../../test-utils/test-utils";
4236
import * as testData from "../../test-utils/test-data";
4337
import { KeyBackupInfo, KeyBackupSession } from "../../../src/crypto-api/keybackup";
4438
import { flushPromises } from "../../test-utils/flushPromises";
@@ -113,7 +107,7 @@ function mockUploadEmitter(
113107
return emitter;
114108
}
115109

116-
describe.each(Object.entries(CRYPTO_BACKENDS))("megolm-keys backup (%s)", (backend: string, initCrypto: InitCrypto) => {
110+
describe("megolm-keys backup", () => {
117111
let aliceClient: MatrixClient;
118112
/** an object which intercepts `/sync` requests on the test homeserver */
119113
let syncResponder: SyncResponder;
@@ -159,7 +153,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("megolm-keys backup (%s)", (backe
159153
deviceId: TEST_DEVICE_ID,
160154
...opts,
161155
});
162-
await initCrypto(client);
156+
await client.initRustCrypto();
163157

164158
return client;
165159
}

spec/integ/crypto/to-device-messages.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import fetchMock from "fetch-mock-jest";
1818
import "fake-indexeddb/auto";
1919
import { IDBFactory } from "fake-indexeddb";
2020

21-
import { CRYPTO_BACKENDS, getSyncResponse, InitCrypto, syncPromise } from "../../test-utils/test-utils";
21+
import { getSyncResponse, syncPromise } from "../../test-utils/test-utils";
2222
import { createClient, MatrixClient } from "../../../src";
2323
import * as testData from "../../test-utils/test-data";
2424
import { E2EKeyResponder } from "../../test-utils/E2EKeyResponder";
@@ -38,7 +38,7 @@ afterEach(() => {
3838
* These tests work by intercepting HTTP requests via fetch-mock rather than mocking out bits of the client, so as
3939
* to provide the most effective integration tests possible.
4040
*/
41-
describe.each(Object.entries(CRYPTO_BACKENDS))("to-device-messages (%s)", (backend: string, initCrypto: InitCrypto) => {
41+
describe("to-device-messages", () => {
4242
let aliceClient: MatrixClient;
4343

4444
/** an object which intercepts `/keys/query` requests on the test homeserver */
@@ -81,7 +81,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("to-device-messages (%s)", (backe
8181
{ filter_id: "fid" },
8282
);
8383

84-
await initCrypto(aliceClient);
84+
await aliceClient.initRustCrypto();
8585
},
8686
/* it can take a while to initialise the crypto library on the first pass, so bump up the timeout. */
8787
10000,

spec/integ/crypto/verification.spec.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,7 @@ import {
4444
VerifierEvent,
4545
} from "../../../src/crypto-api/verification";
4646
import { defer, escapeRegExp } from "../../../src/utils";
47-
import {
48-
awaitDecryption,
49-
CRYPTO_BACKENDS,
50-
emitPromise,
51-
getSyncResponse,
52-
InitCrypto,
53-
syncPromise,
54-
} from "../../test-utils/test-utils";
47+
import { awaitDecryption, emitPromise, getSyncResponse, syncPromise } from "../../test-utils/test-utils";
5548
import { SyncResponder } from "../../test-utils/SyncResponder";
5649
import {
5750
BACKUP_DECRYPTION_KEY_BASE64,
@@ -117,7 +110,7 @@ const TEST_HOMESERVER_URL = "https://alice-server.com";
117110
* to provide the most effective integration tests possible.
118111
*/
119112
// we test with both crypto stacks...
120-
describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: string, initCrypto: InitCrypto) => {
113+
describe("verification", () => {
121114
/** the client under test */
122115
let aliceClient: MatrixClient;
123116

@@ -1470,7 +1463,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
14701463
deviceId: "device_under_test",
14711464
...opts,
14721465
});
1473-
await initCrypto(client);
1466+
await client.initRustCrypto();
14741467
await client.startClient();
14751468
return client;
14761469
}

spec/test-utils/test-utils.ts

-9
Original file line numberDiff line numberDiff line change
@@ -552,15 +552,6 @@ export const mkPusher = (extra: Partial<IPusher> = {}): IPusher => ({
552552
...extra,
553553
});
554554

555-
/**
556-
* a list of the supported crypto implementations, each with a callback to initialise that implementation
557-
* for the given client
558-
*/
559-
export const CRYPTO_BACKENDS: Record<string, InitCrypto> = {};
560-
export type InitCrypto = (_: MatrixClient) => Promise<void>;
561-
562-
CRYPTO_BACKENDS["rust-sdk"] = (client: MatrixClient) => client.initRustCrypto();
563-
564555
export const emitPromise = (e: EventEmitter, k: string): Promise<any> => new Promise((r) => e.once(k, r));
565556

566557
/**

0 commit comments

Comments
 (0)