You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-06 12:02:40 +03:00
MatrixRTC: Refactor | Introduce a new Encryption manager (used with experimental to device transport) (#4799)
* refactor: New encryption manager BasicEncryptionManager for todevice fixup: bad do not commit * fix: ToDevice transport not setting the sent_ts * test: BasicEncryptionManager add statistics tests * code review * feat: Encryption manager just reshare on new joiner * refactor: Rename BasicEncryptionManger to RTCEncryptionManager * fixup: RTC experimental todevice should use new encryption mgr * fixup: use proper logger hierarchy * fixup: RTC rollout first key asap even if no members to send to * fixup: RTC add test for first key use * fixup! emitting outbound key before anyone registered * fix: quick patch for transport switch, need test * test: RTC encryption manager, add test for transport switch * post rebase fix * Remove bad corepack commit * review: cleaning, renaming * review: cleaning and renaming * stop using root logger in favor of a parent logger * post merge fix broken test * remove corepack again * fix reverted changes after a merge * review: Properly deprecate getEncryptionKeys * review: rename ensureMediaKeyDistribution to ensureKeyDistribution * review: use OutdatedKeyFilter instead of KeyBuffer
This commit is contained in:
@@ -21,6 +21,7 @@ import { MatrixRTCSession, MatrixRTCSessionEvent } from "../../../src/matrixrtc/
|
||||
import { type EncryptionKeysEventContent } from "../../../src/matrixrtc/types";
|
||||
import { secureRandomString } from "../../../src/randomstring";
|
||||
import { makeMockEvent, makeMockRoom, makeMockRoomState, membershipTemplate, makeKey } from "./mocks";
|
||||
import { RTCEncryptionManager } from "../../../src/matrixrtc/RTCEncryptionManager.ts";
|
||||
|
||||
const mockFocus = { type: "mock" };
|
||||
|
||||
@@ -745,11 +746,27 @@ describe("MatrixRTCSession", () => {
|
||||
expect(sendKeySpy).toHaveBeenCalledTimes(1);
|
||||
// check that we send the key with index 1 even though the send gets delayed when leaving.
|
||||
// this makes sure we do not use an index that is one too old.
|
||||
expect(sendKeySpy).toHaveBeenLastCalledWith(expect.any(String), 1, sess.memberships);
|
||||
expect(sendKeySpy).toHaveBeenLastCalledWith(
|
||||
expect.any(String),
|
||||
1,
|
||||
sess.memberships.map((m) => ({
|
||||
userId: m.sender,
|
||||
deviceId: m.deviceId,
|
||||
membershipTs: m.createdTs(),
|
||||
})),
|
||||
);
|
||||
// fake a condition in which we send another encryption key event.
|
||||
// this could happen do to someone joining the call.
|
||||
(sess as unknown as any).encryptionManager.sendEncryptionKeysEvent();
|
||||
expect(sendKeySpy).toHaveBeenLastCalledWith(expect.any(String), 1, sess.memberships);
|
||||
expect(sendKeySpy).toHaveBeenLastCalledWith(
|
||||
expect.any(String),
|
||||
1,
|
||||
sess.memberships.map((m) => ({
|
||||
userId: m.sender,
|
||||
deviceId: m.deviceId,
|
||||
membershipTs: m.createdTs(),
|
||||
})),
|
||||
);
|
||||
jest.advanceTimersByTime(7000);
|
||||
|
||||
const secondKeysPayload = await keysSentPromise2;
|
||||
@@ -862,10 +879,14 @@ describe("MatrixRTCSession", () => {
|
||||
manageMediaKeys: true,
|
||||
useExperimentalToDeviceTransport: true,
|
||||
});
|
||||
sess.onRTCSessionMemberUpdate();
|
||||
|
||||
await keySentPromise;
|
||||
|
||||
expect(sendToDeviceMock).toHaveBeenCalled();
|
||||
|
||||
// Access private to test
|
||||
expect(sess["encryptionManager"]).toBeInstanceOf(RTCEncryptionManager);
|
||||
} finally {
|
||||
jest.useRealTimers();
|
||||
}
|
||||
|
Reference in New Issue
Block a user