Skip to content

Commit 004a3b0

Browse files
committed
test(crypto): remove old legacy comments and tests
1 parent 36a58e9 commit 004a3b0

File tree

5 files changed

+23
-53
lines changed

5 files changed

+23
-53
lines changed

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,8 @@ describe("cross-signing", () => {
417417
function awaitCrossSigningKeysUpload() {
418418
return new Promise<any>((resolve) => {
419419
fetchMock.post(
420-
// legacy crypto uses /unstable/; /v3/ is correct
421420
{
422-
url: new RegExp("/_matrix/client/(unstable|v3)/keys/device_signing/upload"),
421+
url: new RegExp("/_matrix/client/v3/keys/device_signing/upload"),
423422
name: "upload-keys",
424423
},
425424
(url, options) => {
@@ -472,9 +471,6 @@ describe("cross-signing", () => {
472471
await aliceClient.startClient();
473472
await syncPromise(aliceClient);
474473

475-
// Wait for legacy crypto to find the device
476-
await jest.advanceTimersByTimeAsync(10);
477-
478474
const devices = await aliceClient.getCrypto()!.getUserDeviceInfo([aliceClient.getSafeUserId()]);
479475
expect(devices.get(aliceClient.getSafeUserId())!.has(testData.TEST_DEVICE_ID)).toBeTruthy();
480476
});

spec/integ/crypto/crypto.spec.ts

+18-29
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import {
5151
IContent,
5252
IDownloadKeyResult,
5353
IEvent,
54-
IndexedDBCryptoStore,
5554
IStartClientOpts,
5655
MatrixClient,
5756
MatrixEvent,
@@ -1901,7 +1900,6 @@ describe("crypto", () => {
19011900
});
19021901

19031902
describe("bootstrapSecretStorage", () => {
1904-
// Doesn't work with legacy crypto, which will try to bootstrap even without private key, which is buggy.
19051903
it("should throw an error if we are unable to create a key because createSecretStorageKey is not set", async () => {
19061904
await expect(
19071905
aliceClient.getCrypto()!.bootstrapSecretStorage({ setupNewSecretStorage: true }),
@@ -1947,8 +1945,6 @@ describe("crypto", () => {
19471945
});
19481946

19491947
it("should do nothing if an AES key is already in the secret storage and setupNewSecretStorage is not set", async () => {
1950-
const awaitAccountDataClientUpdate = awaitAccountDataUpdate("m.secret_storage.default_key");
1951-
19521948
const bootstrapPromise = aliceClient.getCrypto()!.bootstrapSecretStorage({ createSecretStorageKey });
19531949

19541950
// Wait for the key to be uploaded in the account data
@@ -1960,9 +1956,6 @@ describe("crypto", () => {
19601956
// Wait for bootstrapSecretStorage to finished
19611957
await bootstrapPromise;
19621958

1963-
// On legacy crypto we need to wait for ClientEvent.AccountData before calling bootstrap again.
1964-
await awaitAccountDataClientUpdate;
1965-
19661959
// Call again bootstrapSecretStorage
19671960
await aliceClient.getCrypto()!.bootstrapSecretStorage({ createSecretStorageKey });
19681961

@@ -2210,7 +2203,6 @@ describe("crypto", () => {
22102203

22112204
await aliceClient.getCrypto()!.deleteKeyBackupVersion(nextVersion!);
22122205
await aliceClient.getCrypto()!.checkKeyBackupAndEnable();
2213-
// XXX Legacy crypto does not update 4S when doing that; should ensure that rust implem does it.
22142206
expect(await aliceClient.getCrypto()!.getActiveSessionBackupVersion()).toBeNull();
22152207
});
22162208
});
@@ -2313,7 +2305,7 @@ describe("crypto", () => {
23132305

23142306
/** Guards against downgrade attacks from servers hiding or manipulating the crypto settings. */
23152307
describe("Persistent encryption settings", () => {
2316-
let persistentStoreClient: MatrixClient;
2308+
let client1: MatrixClient;
23172309
let client2: MatrixClient;
23182310

23192311
beforeEach(async () => {
@@ -2326,26 +2318,27 @@ describe("crypto", () => {
23262318
// For legacy crypto, these tests only work properly with a proper (indexeddb-based) CryptoStore, so
23272319
// rather than using the existing `aliceClient`, create a new client. Once we drop legacy crypto, we can
23282320
// just use `aliceClient` here.
2329-
persistentStoreClient = await makeNewClient(homeserverurl, userId, "persistentStoreClient");
2330-
await persistentStoreClient.startClient({});
2321+
// XXX: Even with the rust-crypto, we need to create to a new client. The tests fail with a timeout error.
2322+
client1 = await makeNewClient(homeserverurl, userId, "client1");
2323+
await client1.startClient({});
23312324
});
23322325

23332326
afterEach(async () => {
2334-
persistentStoreClient.stopClient();
2327+
client1.stopClient();
23352328
client2?.stopClient();
23362329
});
23372330

23382331
test("Sending a message in a room where the server is hiding the state event does not send a plaintext event", async () => {
23392332
// Alice is in an encrypted room
23402333
const encryptionState = mkEncryptionEvent({ algorithm: "m.megolm.v1.aes-sha2" });
23412334
syncResponder.sendOrQueueSyncResponse(getSyncResponseWithState([encryptionState]));
2342-
await syncPromise(persistentStoreClient);
2335+
await syncPromise(client1);
23432336

23442337
// Send a message, and expect to get an `m.room.encrypted` event.
2345-
await Promise.all([persistentStoreClient.sendTextMessage(ROOM_ID, "test"), expectEncryptedSendMessage()]);
2338+
await Promise.all([client1.sendTextMessage(ROOM_ID, "test"), expectEncryptedSendMessage()]);
23462339

23472340
// We now replace the client, and allow the new one to resync, *without* the encryption event.
2348-
client2 = await replaceClient(persistentStoreClient);
2341+
client2 = await replaceClient(client1);
23492342
syncResponder.sendOrQueueSyncResponse(getSyncResponseWithState([]));
23502343
await client2.startClient({});
23512344
await syncPromise(client2);
@@ -2358,11 +2351,11 @@ describe("crypto", () => {
23582351
// Alice is in an encrypted room, where the rotation period is set to 2 messages
23592352
const encryptionState = mkEncryptionEvent({ algorithm: "m.megolm.v1.aes-sha2", rotation_period_msgs: 2 });
23602353
syncResponder.sendOrQueueSyncResponse(getSyncResponseWithState([encryptionState]));
2361-
await syncPromise(persistentStoreClient);
2354+
await syncPromise(client1);
23622355

23632356
// Send a message, and expect to get an `m.room.encrypted` event.
23642357
const [, msg1Content] = await Promise.all([
2365-
persistentStoreClient.sendTextMessage(ROOM_ID, "test1"),
2358+
client1.sendTextMessage(ROOM_ID, "test1"),
23662359
expectEncryptedSendMessage(),
23672360
]);
23682361

@@ -2376,17 +2369,17 @@ describe("crypto", () => {
23762369
next_batch: "1",
23772370
rooms: { join: { [TEST_ROOM_ID]: { timeline: { events: [encryptionState2], prev_batch: "" } } } },
23782371
});
2379-
await syncPromise(persistentStoreClient);
2372+
await syncPromise(client1);
23802373

23812374
// Send two more messages. The first should use the same megolm session as the first; the second should
23822375
// use a different one.
23832376
const [, msg2Content] = await Promise.all([
2384-
persistentStoreClient.sendTextMessage(ROOM_ID, "test2"),
2377+
client1.sendTextMessage(ROOM_ID, "test2"),
23852378
expectEncryptedSendMessage(),
23862379
]);
23872380
expect(msg2Content.session_id).toEqual(msg1Content.session_id);
23882381
const [, msg3Content] = await Promise.all([
2389-
persistentStoreClient.sendTextMessage(ROOM_ID, "test3"),
2382+
client1.sendTextMessage(ROOM_ID, "test3"),
23902383
expectEncryptedSendMessage(),
23912384
]);
23922385
expect(msg3Content.session_id).not.toEqual(msg1Content.session_id);
@@ -2396,13 +2389,13 @@ describe("crypto", () => {
23962389
// Alice is in an encrypted room, where the rotation period is set to 2 messages
23972390
const encryptionState = mkEncryptionEvent({ algorithm: "m.megolm.v1.aes-sha2", rotation_period_msgs: 2 });
23982391
syncResponder.sendOrQueueSyncResponse(getSyncResponseWithState([encryptionState]));
2399-
await syncPromise(persistentStoreClient);
2392+
await syncPromise(client1);
24002393

24012394
// Send a message, and expect to get an `m.room.encrypted` event.
2402-
await Promise.all([persistentStoreClient.sendTextMessage(ROOM_ID, "test1"), expectEncryptedSendMessage()]);
2395+
await Promise.all([client1.sendTextMessage(ROOM_ID, "test1"), expectEncryptedSendMessage()]);
24032396

24042397
// We now replace the client, and allow the new one to resync with a *different* encryption event.
2405-
client2 = await replaceClient(persistentStoreClient);
2398+
client2 = await replaceClient(client1);
24062399
const encryptionState2 = mkEncryptionEvent({
24072400
algorithm: "m.megolm.v1.aes-sha2",
24082401
rotation_period_msgs: 100,
@@ -2433,11 +2426,7 @@ describe("crypto", () => {
24332426
userId: userId,
24342427
accessToken: "akjgkrgjs",
24352428
deviceId: "xzcvb",
2436-
cryptoCallbacks: createCryptoCallbacks(),
24372429
logger: logger.getChild(loggerPrefix),
2438-
2439-
// For legacy crypto, these tests only work with a proper persistent cryptoStore.
2440-
cryptoStore: new IndexedDBCryptoStore(indexedDB, "test"),
24412430
});
24422431
await client.initRustCrypto();
24432432
mockInitialApiRequests(client.getHomeserverUrl());
@@ -2446,7 +2435,7 @@ describe("crypto", () => {
24462435

24472436
function mkEncryptionEvent(content: object) {
24482437
return mkEventCustom({
2449-
sender: persistentStoreClient.getSafeUserId(),
2438+
sender: client1.getSafeUserId(),
24502439
type: "m.room.encryption",
24512440
state_key: "",
24522441
content: content,
@@ -2463,7 +2452,7 @@ describe("crypto", () => {
24632452
events: [
24642453
mkMembershipCustom({
24652454
membership: KnownMembership.Join,
2466-
sender: persistentStoreClient.getSafeUserId(),
2455+
sender: client1.getSafeUserId(),
24672456
}),
24682457
...stateEvents,
24692458
],

spec/integ/crypto/verification.spec.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,8 @@ describe("verification", () => {
420420
expect(requests[0].transactionId).toEqual(transactionId);
421421
}
422422

423-
// legacy crypto picks devices individually; rust crypto uses a broadcast message
424-
const toDeviceMessage =
425-
requestBody.messages[TEST_USER_ID]["*"] ?? requestBody.messages[TEST_USER_ID][TEST_DEVICE_ID];
423+
// rust crypto uses a broadcast message
424+
const toDeviceMessage = requestBody.messages[TEST_USER_ID]["*"];
426425
expect(toDeviceMessage.from_device).toEqual(aliceClient.deviceId);
427426
expect(toDeviceMessage.transaction_id).toEqual(transactionId);
428427
});
@@ -510,10 +509,8 @@ describe("verification", () => {
510509
reciprocateQRCodeCallbacks.confirm();
511510
await sendToDevicePromise;
512511

513-
// at this point, on legacy crypto, the master key is already marked as trusted, and the request is "Done".
514512
// Rust crypto, on the other hand, waits for the 'done' to arrive from the other side.
515513
if (request.phase === VerificationPhase.Done) {
516-
// legacy crypto: we're all done
517514
const userVerificationStatus = await aliceClient.getCrypto()!.getUserVerificationStatus(TEST_USER_ID);
518515
// eslint-disable-next-line jest/no-conditional-expect
519516
expect(userVerificationStatus.isCrossSigningVerified()).toBeTruthy();

spec/integ/matrix-client-syncing.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
UNSTABLE_MSC2716_MARKER,
2828
MatrixClient,
2929
ClientEvent,
30-
IndexedDBCryptoStore,
3130
ISyncResponse,
3231
IRoomEvent,
3332
IJoinedRoom,
@@ -2571,9 +2570,8 @@ describe("MatrixClient syncing (IndexedDB version)", () => {
25712570
};
25722571

25732572
it("should emit ClientEvent.Room when invited while using indexeddb crypto store", async () => {
2574-
const idbTestClient = new TestClient(selfUserId, "DEVICE", selfAccessToken, undefined, {
2575-
cryptoStore: new IndexedDBCryptoStore(globalThis.indexedDB, "tests"),
2576-
});
2573+
// rust crypto uses by default indexeddb
2574+
const idbTestClient = new TestClient(selfUserId, "DEVICE", selfAccessToken);
25772575
const idbHttpBackend = idbTestClient.httpBackend;
25782576
const idbClient = idbTestClient.client;
25792577
idbHttpBackend.when("GET", "/versions").respond(200, {});

0 commit comments

Comments
 (0)