Skip to content

Commit 7ec182e

Browse files
committed
Add a new test
1 parent d091127 commit 7ec182e

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

spec/integ/megolm-integ.spec.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,4 +1376,90 @@ describe("megolm", () => {
13761376

13771377
await beccaTestClient.stop();
13781378
});
1379+
1380+
it("allows sending an encrypted event as soon as room state arrives", async () => {
1381+
/* Empirically, clients expect to be able to send encrypted events as soon as the
1382+
* RoomStateEvent.NewMember notification is emitted, so test that works correctly.
1383+
*/
1384+
const testRoomId = "!testRoom:id";
1385+
await aliceTestClient.start();
1386+
1387+
aliceTestClient.httpBackend.when("POST", "/keys/query")
1388+
.respond(200, function(_path, content: IUploadKeysRequest) {
1389+
return { device_keys: {} };
1390+
});
1391+
1392+
/* Alice makes the /createRoom call */
1393+
aliceTestClient.httpBackend.when("POST", "/createRoom")
1394+
.respond(200, { room_id: testRoomId });
1395+
await Promise.all([
1396+
aliceTestClient.client.createRoom({
1397+
initial_state: [{
1398+
type: 'm.room.encryption',
1399+
state_key: '',
1400+
content: { algorithm: 'm.megolm.v1.aes-sha2' },
1401+
}],
1402+
}),
1403+
aliceTestClient.httpBackend.flushAllExpected(),
1404+
]);
1405+
1406+
/* The sync arrives in two parts; first the m.room.create... */
1407+
aliceTestClient.httpBackend.when("GET", "/sync").respond(200, {
1408+
rooms: { join: {
1409+
[testRoomId]: {
1410+
timeline: { events: [
1411+
{
1412+
type: 'm.room.create',
1413+
state_key: '',
1414+
event_id: "$create",
1415+
},
1416+
{
1417+
type: 'm.room.member',
1418+
state_key: aliceTestClient.getUserId(),
1419+
content: { membership: "join" },
1420+
event_id: "$alijoin",
1421+
},
1422+
] },
1423+
},
1424+
} },
1425+
});
1426+
await aliceTestClient.flushSync();
1427+
1428+
// ... and then the e2e event and an invite ...
1429+
aliceTestClient.httpBackend.when("GET", "/sync").respond(200, {
1430+
rooms: { join: {
1431+
[testRoomId]: {
1432+
timeline: { events: [
1433+
{
1434+
type: 'm.room.encryption',
1435+
state_key: '',
1436+
content: { algorithm: 'm.megolm.v1.aes-sha2' },
1437+
event_id: "$e2e",
1438+
},
1439+
{
1440+
type: 'm.room.member',
1441+
state_key: "@other:user",
1442+
content: { membership: "invite" },
1443+
event_id: "$otherinvite",
1444+
},
1445+
] },
1446+
},
1447+
} },
1448+
});
1449+
1450+
// as soon as the roomMember arrives, try to send a message
1451+
aliceTestClient.client.on(RoomStateEvent.NewMember, (_e, _s, member: RoomMember) => {
1452+
if (member.userId == "@other:user") {
1453+
aliceTestClient.client.sendMessage(testRoomId, { msgtype: "m.text", body: "Hello, World" });
1454+
}
1455+
});
1456+
1457+
// flush the sync and wait for the /send/ request.
1458+
aliceTestClient.httpBackend.when("PUT", "/send/m.room.encrypted/")
1459+
.respond(200, (_path, _content) => ({ event_id: "asdfgh" }));
1460+
await Promise.all([
1461+
aliceTestClient.flushSync(),
1462+
aliceTestClient.httpBackend.flush("/send/m.room.encrypted/", 1),
1463+
]);
1464+
});
13791465
});

0 commit comments

Comments
 (0)