Skip to content

Commit b76ccc6

Browse files
authored
Clean up integ test after legacy crypto removal (#4682)
* test(crypto): remove `newBackendOnly` test closure * test(crypto): fix duplicate test name * test(crypto): remove `oldBackendOnly` test closure * test(crypto): remove `rust-sdk` comparison * test(crypto): remove iteration on `CRYPTO_BACKEND` * test(crypto): remove old legacy comments and tests * test(crypto): fix documentations and removed unused expect
1 parent 07016bb commit b76ccc6

9 files changed

+231
-527
lines changed

.eslintrc.cjs

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ module.exports = {
8686
// Disabled tests are a reality for now but as soon as all of the xits are
8787
// eliminated, we should enforce this.
8888
"jest/no-disabled-tests": "off",
89-
// Also treat "oldBackendOnly" as a test function.
9089
// Used in some crypto tests.
9190
"jest/no-standalone-expect": [
9291
"error",
9392
{
94-
additionalTestBlockFunctions: ["beforeAll", "beforeEach", "oldBackendOnly", "newBackendOnly"],
93+
additionalTestBlockFunctions: ["beforeAll", "beforeEach"],
9594
},
9695
],
9796
},

spec/TestClient.ts

-10
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ import MockHttpBackend from "matrix-mock-request";
2626

2727
import type { IDeviceKeys, IOneTimeKey } from "../src/@types/crypto";
2828
import type { IE2EKeyReceiver } from "./test-utils/E2EKeyReceiver";
29-
import { LocalStorageCryptoStore } from "../src/crypto/store/localStorage-crypto-store";
3029
import { logger } from "../src/logger";
3130
import { syncPromise } from "./test-utils/test-utils";
3231
import { createClient, IStartClientOpts } from "../src/matrix";
3332
import { ICreateClientOpts, IDownloadKeyResult, MatrixClient, PendingEventOrdering } from "../src/client";
34-
import { MockStorageApi } from "./MockStorageApi";
3533
import { IKeysUploadResponse, IUploadKeysRequest } from "../src/client";
3634
import { ISyncResponder } from "./test-utils/SyncResponder";
3735

@@ -55,10 +53,6 @@ export class TestClient implements IE2EKeyReceiver, ISyncResponder {
5553
sessionStoreBackend?: Storage,
5654
options?: Partial<ICreateClientOpts>,
5755
) {
58-
if (sessionStoreBackend === undefined) {
59-
sessionStoreBackend = new MockStorageApi() as unknown as Storage;
60-
}
61-
6256
this.httpBackend = new MockHttpBackend();
6357

6458
const fullOptions: ICreateClientOpts = {
@@ -69,10 +63,6 @@ export class TestClient implements IE2EKeyReceiver, ISyncResponder {
6963
fetchFn: this.httpBackend.fetchFn as typeof globalThis.fetch,
7064
...options,
7165
};
72-
if (!fullOptions.cryptoStore) {
73-
// expose this so the tests can get to it
74-
fullOptions.cryptoStore = new LocalStorageCryptoStore(sessionStoreBackend);
75-
}
7666
this.client = createClient(fullOptions);
7767

7868
this.deviceKeys = null;

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

+6-14
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,11 +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) => {
59-
// newBackendOnly is the opposite to `oldBackendOnly`: it will skip the test if we are running against the legacy
60-
// backend. Once we drop support for legacy crypto, it will go away.
61-
const newBackendOnly = backend === "rust-sdk" ? test : test.skip;
62-
58+
describe("cross-signing", () => {
6359
let aliceClient: MatrixClient;
6460

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

111-
await initCrypto(aliceClient);
107+
await aliceClient.initRustCrypto();
112108
},
113109
/* it can take a while to initialise the crypto library on the first pass, so bump up the timeout. */
114110
10000,
@@ -163,7 +159,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s
163159
);
164160
});
165161

166-
newBackendOnly("get cross signing keys from secret storage and import them", async () => {
162+
it("get cross signing keys from secret storage and import them", async () => {
167163
// Return public cross signing keys
168164
e2eKeyResponder.addCrossSigningData(SIGNED_CROSS_SIGNING_KEYS_DATA);
169165

@@ -264,7 +260,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s
264260
expect(calls.length).toEqual(0);
265261
});
266262

267-
newBackendOnly("will upload existing cross-signing keys to an established secret storage", async () => {
263+
it("will upload existing cross-signing keys to an established secret storage", async () => {
268264
// This rather obscure codepath covers the case that:
269265
// - 4S is set up and working
270266
// - our device has private cross-signing keys, but has not published them to 4S
@@ -421,9 +417,8 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s
421417
function awaitCrossSigningKeysUpload() {
422418
return new Promise<any>((resolve) => {
423419
fetchMock.post(
424-
// legacy crypto uses /unstable/; /v3/ is correct
425420
{
426-
url: new RegExp("/_matrix/client/(unstable|v3)/keys/device_signing/upload"),
421+
url: new RegExp("/_matrix/client/v3/keys/device_signing/upload"),
427422
name: "upload-keys",
428423
},
429424
(url, options) => {
@@ -476,9 +471,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("cross-signing (%s)", (backend: s
476471
await aliceClient.startClient();
477472
await syncPromise(aliceClient);
478473

479-
// Wait for legacy crypto to find the device
480-
await jest.advanceTimersByTimeAsync(10);
481-
482474
const devices = await aliceClient.getCrypto()!.getUserDeviceInfo([aliceClient.getSafeUserId()]);
483475
expect(devices.get(aliceClient.getSafeUserId())!.has(testData.TEST_DEVICE_ID)).toBeTruthy();
484476
});

0 commit comments

Comments
 (0)