Skip to content

Commit d92d751

Browse files
committed
add back decryptEventIfNeeded
1 parent 15e1c2f commit d92d751

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

spec/unit/matrixrtc/MatrixRTCSession.spec.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import {
18-
encodeBase64,
19-
EventType,
20-
IRoomTimelineData,
21-
MatrixClient,
22-
RoomEvent,
23-
type MatrixError,
24-
type MatrixEvent,
25-
type Room,
26-
} from "../../../src";
17+
import { encodeBase64, EventType, MatrixClient, type MatrixError, type MatrixEvent, type Room } from "../../../src";
2718
import { KnownMembership } from "../../../src/@types/membership";
2819
import { DEFAULT_EXPIRE_DURATION, type SessionMembershipData } from "../../../src/matrixrtc/CallMembership";
29-
import { IKeyTransport } from "../../../src/matrixrtc/IKeyTransport";
3020
import { MatrixRTCSession, MatrixRTCSessionEvent } from "../../../src/matrixrtc/MatrixRTCSession";
3121
import { type EncryptionKeysEventContent } from "../../../src/matrixrtc/types";
3222
import { secureRandomString } from "../../../src/randomstring";
@@ -45,6 +35,9 @@ describe("MatrixRTCSession", () => {
4535
client.getUserId = jest.fn().mockReturnValue("@alice:example.org");
4636
client.getDeviceId = jest.fn().mockReturnValue("AAAAAAA");
4737
client.sendEvent = jest.fn().mockResolvedValue({ event_id: "success" });
38+
client.decryptEventIfNeeded = jest.fn().mockImplementation(() => {
39+
console.log("Fake decryptEventIfNeeded");
40+
});
4841
});
4942

5043
afterEach(async () => {
@@ -997,7 +990,7 @@ describe("MatrixRTCSession", () => {
997990
});
998991

999992
describe("receiving", () => {
1000-
it("collects keys from encryption events", () => {
993+
it("collects keys from encryption events", async () => {
1001994
const mockRoom = makeMockRoom([membershipTemplate]);
1002995
sess = MatrixRTCSession.roomSessionForRoom(client, mockRoom);
1003996
sess!.joinRoomSession([mockFocus], mockFocus, { manageMediaKeys: true });
@@ -1013,6 +1006,7 @@ describe("MatrixRTCSession", () => {
10131006
],
10141007
}),
10151008
);
1009+
await jest.advanceTimersToNextTimerAsync();
10161010
const encryptionKeyChangedListener = jest.fn();
10171011
sess!.on(MatrixRTCSessionEvent.EncryptionKeyChanged, encryptionKeyChangedListener);
10181012
sess!.reemitEncryptionKeys();
@@ -1026,7 +1020,7 @@ describe("MatrixRTCSession", () => {
10261020
expect(sess!.statistics.counters.roomEventEncryptionKeysReceived).toEqual(1);
10271021
});
10281022

1029-
it("collects keys at non-zero indices", () => {
1023+
it("collects keys at non-zero indices", async () => {
10301024
const mockRoom = makeMockRoom([membershipTemplate]);
10311025
sess = MatrixRTCSession.roomSessionForRoom(client, mockRoom);
10321026
sess!.joinRoomSession([mockFocus], mockFocus, { manageMediaKeys: true });
@@ -1042,6 +1036,7 @@ describe("MatrixRTCSession", () => {
10421036
],
10431037
}),
10441038
);
1039+
await jest.advanceTimersToNextTimerAsync();
10451040

10461041
const encryptionKeyChangedListener = jest.fn();
10471042
sess!.on(MatrixRTCSessionEvent.EncryptionKeyChanged, encryptionKeyChangedListener);
@@ -1056,7 +1051,7 @@ describe("MatrixRTCSession", () => {
10561051
expect(sess!.statistics.counters.roomEventEncryptionKeysReceived).toEqual(1);
10571052
});
10581053

1059-
it("collects keys by merging", () => {
1054+
it("collects keys by merging", async () => {
10601055
const mockRoom = makeMockRoom([membershipTemplate]);
10611056
sess = MatrixRTCSession.roomSessionForRoom(client, mockRoom);
10621057
sess!.joinRoomSession([mockFocus], mockFocus, { manageMediaKeys: true });
@@ -1072,6 +1067,7 @@ describe("MatrixRTCSession", () => {
10721067
],
10731068
}),
10741069
);
1070+
await jest.advanceTimersToNextTimerAsync();
10751071

10761072
const encryptionKeyChangedListener = jest.fn();
10771073
sess!.on(MatrixRTCSessionEvent.EncryptionKeyChanged, encryptionKeyChangedListener);
@@ -1097,6 +1093,7 @@ describe("MatrixRTCSession", () => {
10971093
],
10981094
}),
10991095
);
1096+
await jest.advanceTimersToNextTimerAsync();
11001097

11011098
encryptionKeyChangedListener.mockClear();
11021099
sess!.reemitEncryptionKeys();
@@ -1115,7 +1112,7 @@ describe("MatrixRTCSession", () => {
11151112
expect(sess!.statistics.counters.roomEventEncryptionKeysReceived).toEqual(2);
11161113
});
11171114

1118-
it("ignores older keys at same index", () => {
1115+
it("ignores older keys at same index", async () => {
11191116
const mockRoom = makeMockRoom([membershipTemplate]);
11201117
sess = MatrixRTCSession.roomSessionForRoom(client, mockRoom);
11211118
sess!.joinRoomSession([mockFocus], mockFocus, { manageMediaKeys: true });
@@ -1174,6 +1171,7 @@ describe("MatrixRTCSession", () => {
11741171
1000,
11751172
),
11761173
);
1174+
await jest.advanceTimersToNextTimerAsync();
11771175

11781176
const encryptionKeyChangedListener = jest.fn();
11791177
sess!.on(MatrixRTCSessionEvent.EncryptionKeyChanged, encryptionKeyChangedListener);
@@ -1188,7 +1186,7 @@ describe("MatrixRTCSession", () => {
11881186
expect(sess!.statistics.counters.roomEventEncryptionKeysReceived).toEqual(3);
11891187
});
11901188

1191-
it("key timestamps are treated as monotonic", () => {
1189+
it("key timestamps are treated as monotonic", async () => {
11921190
const mockRoom = makeMockRoom([membershipTemplate]);
11931191
sess = MatrixRTCSession.roomSessionForRoom(client, mockRoom);
11941192
sess!.joinRoomSession([mockFocus], mockFocus, { manageMediaKeys: true });
@@ -1229,6 +1227,7 @@ describe("MatrixRTCSession", () => {
12291227
1000,
12301228
),
12311229
);
1230+
await jest.advanceTimersToNextTimerAsync();
12321231

12331232
const encryptionKeyChangedListener = jest.fn();
12341233
sess!.on(MatrixRTCSessionEvent.EncryptionKeyChanged, encryptionKeyChangedListener);
@@ -1267,7 +1266,7 @@ describe("MatrixRTCSession", () => {
12671266
expect(sess!.statistics.counters.roomEventEncryptionKeysReceived).toEqual(0);
12681267
});
12691268

1270-
it("tracks total age statistics for collected keys", () => {
1269+
it("tracks total age statistics for collected keys", async () => {
12711270
jest.useFakeTimers();
12721271
try {
12731272
const mockRoom = makeMockRoom([membershipTemplate]);
@@ -1294,6 +1293,7 @@ describe("MatrixRTCSession", () => {
12941293
0,
12951294
),
12961295
);
1296+
await jest.advanceTimersToNextTimerAsync();
12971297

12981298
expect(sess!.statistics.totals.roomEventEncryptionKeysReceivedTotalAge).toEqual(1000);
12991299

@@ -1312,6 +1312,7 @@ describe("MatrixRTCSession", () => {
13121312
sent_ts: 0,
13131313
}),
13141314
);
1315+
await jest.advanceTimersToNextTimerAsync();
13151316

13161317
expect(sess!.statistics.totals.roomEventEncryptionKeysReceivedTotalAge).toEqual(3000);
13171318

@@ -1329,6 +1330,7 @@ describe("MatrixRTCSession", () => {
13291330
sent_ts: 1000,
13301331
}),
13311332
);
1333+
await jest.advanceTimersToNextTimerAsync();
13321334

13331335
expect(sess!.statistics.totals.roomEventEncryptionKeysReceivedTotalAge).toEqual(5000);
13341336
} finally {

src/matrixrtc/RoomKeyTransport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class RoomKeyTransport
5151
}
5252

5353
private async consumeCallEncryptionEvent(event: MatrixEvent, isRetry = false): Promise<void> {
54-
// await this.client.decryptEventIfNeeded(event);
54+
await this.client.decryptEventIfNeeded(event);
5555

5656
if (event.isDecryptionFailure()) {
5757
if (!isRetry) {

0 commit comments

Comments
 (0)