Skip to content

Commit 0cdaa04

Browse files
committed
update tests
1 parent 10ef73b commit 0cdaa04

File tree

5 files changed

+161
-126
lines changed

5 files changed

+161
-126
lines changed

spec/unit/matrixrtc/MatrixRTCSession.spec.ts

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
import { RTCEncryptionManager } from "../../../src/matrixrtc/RTCEncryptionManager.ts";
3939
import { RoomStickyEventsEvent, type StickyMatrixEvent } from "../../../src/models/room-sticky-events.ts";
4040
import { StickyEventMembershipManager } from "../../../src/matrixrtc/MembershipManager.ts";
41+
import { type CallMembershipIdentityParts } from "src/matrixrtc/EncryptionManager.ts";
4142

4243
const mockFocus = { type: "mock" };
4344

@@ -803,11 +804,11 @@ describe("MatrixRTCSession", () => {
803804
sess!.on(MatrixRTCSessionEvent.EncryptionKeyChanged, encryptionKeyChangedListener);
804805
sess?.reemitEncryptionKeys();
805806
expect(encryptionKeyChangedListener).toHaveBeenCalledTimes(1);
806-
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(
807-
expect.any(Uint8Array),
808-
0,
809-
"@alice:example.org:AAAAAAA",
810-
);
807+
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(expect.any(Uint8Array), 0, {
808+
deviceId: "AAAAAAA",
809+
memberId: "@alice:example.org:AAAAAAA",
810+
userId: "@alice:example.org",
811+
});
811812
});
812813

813814
it("sends keys when joining", async () => {
@@ -1122,8 +1123,11 @@ describe("MatrixRTCSession", () => {
11221123
const onMyEncryptionKeyChanged = jest.fn();
11231124
sess.on(
11241125
MatrixRTCSessionEvent.EncryptionKeyChanged,
1125-
(_key: Uint8Array, _idx: number, participantId: string) => {
1126-
if (participantId === `${client.getUserId()}:${client.getDeviceId()}`) {
1126+
(_key: Uint8Array, _idx: number, membership: CallMembershipIdentityParts) => {
1127+
if (
1128+
membership.userId === client.getUserId() &&
1129+
membership.deviceId === client.getDeviceId()
1130+
) {
11271131
onMyEncryptionKeyChanged();
11281132
}
11291133
},
@@ -1312,11 +1316,11 @@ describe("MatrixRTCSession", () => {
13121316
sess!.reemitEncryptionKeys();
13131317

13141318
expect(encryptionKeyChangedListener).toHaveBeenCalledTimes(2);
1315-
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(
1316-
textEncoder.encode("this is the key"),
1317-
0,
1318-
"@bob:example.org:bobsphone",
1319-
);
1319+
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(textEncoder.encode("this is the key"), 0, {
1320+
deviceId: "bobsphone",
1321+
memberId: "@bob:example.org:bobsphone",
1322+
userId: "@bob:example.org",
1323+
});
13201324
expect(sess!.statistics.counters.roomEventEncryptionKeysReceived).toEqual(1);
13211325
});
13221326

@@ -1337,11 +1341,11 @@ describe("MatrixRTCSession", () => {
13371341
sess!.on(MatrixRTCSessionEvent.EncryptionKeyChanged, encryptionKeyChangedListener);
13381342
sess!.reemitEncryptionKeys();
13391343
expect(encryptionKeyChangedListener).toHaveBeenCalledTimes(2);
1340-
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(
1341-
textEncoder.encode("this is the key"),
1342-
4,
1343-
"@bob:example.org:bobsphone",
1344-
);
1344+
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(textEncoder.encode("this is the key"), 4, {
1345+
deviceId: "bobsphone",
1346+
memberId: "@bob:example.org:bobsphone",
1347+
userId: "@bob:example.org",
1348+
});
13451349

13461350
expect(sess!.statistics.counters.roomEventEncryptionKeysReceived).toEqual(1);
13471351
});
@@ -1363,11 +1367,11 @@ describe("MatrixRTCSession", () => {
13631367
sess!.on(MatrixRTCSessionEvent.EncryptionKeyChanged, encryptionKeyChangedListener);
13641368
sess!.reemitEncryptionKeys();
13651369
expect(encryptionKeyChangedListener).toHaveBeenCalledTimes(2);
1366-
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(
1367-
textEncoder.encode("this is the key"),
1368-
0,
1369-
"@bob:example.org:bobsphone",
1370-
);
1370+
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(textEncoder.encode("this is the key"), 0, {
1371+
deviceId: "bobsphone",
1372+
memberId: "@bob:example.org:bobsphone",
1373+
userId: "@bob:example.org",
1374+
});
13711375

13721376
expect(sess!.statistics.counters.roomEventEncryptionKeysReceived).toEqual(1);
13731377

@@ -1383,16 +1387,16 @@ describe("MatrixRTCSession", () => {
13831387
encryptionKeyChangedListener.mockClear();
13841388
sess!.reemitEncryptionKeys();
13851389
expect(encryptionKeyChangedListener).toHaveBeenCalledTimes(3);
1386-
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(
1387-
textEncoder.encode("this is the key"),
1388-
0,
1389-
"@bob:example.org:bobsphone",
1390-
);
1391-
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(
1392-
textEncoder.encode("this is the key"),
1393-
4,
1394-
"@bob:example.org:bobsphone",
1395-
);
1390+
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(textEncoder.encode("this is the key"), 0, {
1391+
deviceId: "bobsphone",
1392+
memberId: "@bob:example.org:bobsphone",
1393+
userId: "@bob:example.org",
1394+
});
1395+
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(textEncoder.encode("this is the key"), 4, {
1396+
deviceId: "bobsphone",
1397+
memberId: "@bob:example.org:bobsphone",
1398+
userId: "@bob:example.org",
1399+
});
13961400

13971401
expect(sess!.statistics.counters.roomEventEncryptionKeysReceived).toEqual(2);
13981402
});
@@ -1447,11 +1451,11 @@ describe("MatrixRTCSession", () => {
14471451
sess!.on(MatrixRTCSessionEvent.EncryptionKeyChanged, encryptionKeyChangedListener);
14481452
sess!.reemitEncryptionKeys();
14491453
expect(encryptionKeyChangedListener).toHaveBeenCalledTimes(2);
1450-
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(
1451-
textEncoder.encode("newer key"),
1452-
0,
1453-
"@bob:example.org:bobsphone",
1454-
);
1454+
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(textEncoder.encode("newer key"), 0, {
1455+
deviceId: "bobsphone",
1456+
memberId: "@bob:example.org:bobsphone",
1457+
userId: "@bob:example.org",
1458+
});
14551459

14561460
expect(sess!.statistics.counters.roomEventEncryptionKeysReceived).toEqual(3);
14571461
});
@@ -1493,11 +1497,11 @@ describe("MatrixRTCSession", () => {
14931497
sess!.on(MatrixRTCSessionEvent.EncryptionKeyChanged, encryptionKeyChangedListener);
14941498
sess!.reemitEncryptionKeys();
14951499
expect(encryptionKeyChangedListener).toHaveBeenCalledTimes(2);
1496-
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(
1497-
textEncoder.encode("second key"),
1498-
0,
1499-
"@bob:example.org:bobsphone",
1500-
);
1500+
expect(encryptionKeyChangedListener).toHaveBeenCalledWith(textEncoder.encode("second key"), 0, {
1501+
deviceId: "bobsphone",
1502+
memberId: "@bob:example.org:bobsphone",
1503+
userId: "@bob:example.org",
1504+
});
15011505
});
15021506

15031507
it("ignores keys event for the local participant", () => {

spec/unit/matrixrtc/MembershipManager.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,13 @@ describe("MembershipManager", () => {
918918
const restartScheduledDelayedEventHandle = createAsyncHandle<void>(
919919
client._unstable_restartScheduledDelayedEvent as Mock,
920920
);
921-
const memberManager = new StickyEventMembershipManager(undefined, room, client, callSession);
921+
const memberManager = new StickyEventMembershipManager(
922+
undefined,
923+
room,
924+
client,
925+
callSession,
926+
"@alice:example.org:AAAAAAA_m.call",
927+
);
922928

923929
memberManager.join([], focus);
924930

@@ -933,13 +939,13 @@ describe("MembershipManager", () => {
933939
application: { type: "m.call" },
934940
member: {
935941
user_id: "@alice:example.org",
936-
id: "_@alice:example.org_AAAAAAA_m.call",
942+
id: "@alice:example.org:AAAAAAA_m.call",
937943
device_id: "AAAAAAA",
938944
},
939945
slot_id: "m.call#",
940946
rtc_transports: [focus],
941947
versions: [],
942-
msc4354_sticky_key: "_@alice:example.org_AAAAAAA_m.call",
948+
msc4354_sticky_key: "@alice:example.org:AAAAAAA_m.call",
943949
},
944950
);
945951
restartScheduledDelayedEventHandle.resolve?.();
@@ -952,7 +958,7 @@ describe("MembershipManager", () => {
952958
null,
953959
"org.matrix.msc4143.rtc.member",
954960
{
955-
msc4354_sticky_key: "_@alice:example.org_AAAAAAA_m.call",
961+
msc4354_sticky_key: "@alice:example.org:AAAAAAA_m.call",
956962
},
957963
);
958964
// ..once

spec/unit/matrixrtc/OutdatedKeyFilter.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ describe("OutdatedKeyFilter Test", () => {
2525
const olderKey = fakeInboundSessionWithTimestamp(300);
2626
// Simulate receiving out of order keys
2727

28-
expect(filter.isOutdated(aKey.participantId, aKey)).toBe(false);
28+
expect(filter.isOutdated(aKey.membership, aKey)).toBe(false);
2929
// Then we receive the most recent key out of order
30-
const isOutdated = filter.isOutdated(aKey.participantId, olderKey);
30+
const isOutdated = filter.isOutdated(aKey.membership, olderKey);
3131
// this key is older and should be ignored even if received after
3232
expect(isOutdated).toBe(true);
3333
});
@@ -36,7 +36,7 @@ describe("OutdatedKeyFilter Test", () => {
3636
return {
3737
keyIndex: 0,
3838
creationTS: ts,
39-
participantId: "@alice:localhost|ABCDE",
39+
membership: { userId: "@alice:localhost", deviceId: "ABDE", memberId: "@alice:localhost:ABCDE" },
4040
key: new Uint8Array(16),
4141
};
4242
}

0 commit comments

Comments
 (0)