Skip to content

Commit 7daff1e

Browse files
committed
and update tests too
1 parent dd0fa87 commit 7daff1e

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

spec/integ/megolm-integ.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,9 @@ describe("megolm", function() {
618618
aliceTestClient.httpBackend.when(
619619
'PUT', '/sendToDevice/org.matrix.room_key.withheld/',
620620
).respond(200, {});
621+
aliceTestClient.httpBackend.when(
622+
'PUT', '/sendToDevice/m.room_key.withheld/',
623+
).respond(200, {});
621624

622625
return Promise.all([
623626
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
@@ -718,6 +721,9 @@ describe("megolm", function() {
718721
aliceTestClient.httpBackend.when(
719722
'PUT', '/sendToDevice/org.matrix.room_key.withheld/',
720723
).respond(200, {});
724+
aliceTestClient.httpBackend.when(
725+
'PUT', '/sendToDevice/m.room_key.withheld/',
726+
).respond(200, {});
721727

722728
return Promise.all([
723729
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test2'),

spec/unit/crypto/algorithms/megolm.spec.js

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ describe("MegolmDecryption", function() {
462462
let run = false;
463463
aliceClient.sendToDevice = async (msgtype, contentMap) => {
464464
run = true;
465-
expect(msgtype).toBe("org.matrix.room_key.withheld");
465+
expect(msgtype).toMatch(/^(org.matrix|m).room_key.withheld$/);
466466
delete contentMap["@bob:example.com"].bobdevice1.session_id;
467467
delete contentMap["@bob:example.com"].bobdevice2.session_id;
468468
expect(contentMap).toStrictEqual({
@@ -572,7 +572,7 @@ describe("MegolmDecryption", function() {
572572

573573
const sendPromise = new Promise((resolve, reject) => {
574574
aliceClient.sendToDevice = async (msgtype, contentMap) => {
575-
expect(msgtype).toBe("org.matrix.room_key.withheld");
575+
expect(msgtype).toMatch(/^(org.matrix|m).room_key.withheld$/);
576576
expect(contentMap).toStrictEqual({
577577
'@bob:example.com': {
578578
bobdevice: {
@@ -619,7 +619,7 @@ describe("MegolmDecryption", function() {
619619
content: {
620620
algorithm: "m.megolm.v1.aes-sha2",
621621
room_id: roomId,
622-
session_id: "session_id",
622+
session_id: "session_id1",
623623
sender_key: bobDevice.deviceCurve25519Key,
624624
code: "m.blacklisted",
625625
reason: "You have been blocked",
@@ -636,7 +636,34 @@ describe("MegolmDecryption", function() {
636636
ciphertext: "blablabla",
637637
device_id: "bobdevice",
638638
sender_key: bobDevice.deviceCurve25519Key,
639-
session_id: "session_id",
639+
session_id: "session_id1",
640+
},
641+
}))).rejects.toThrow("The sender has blocked you.");
642+
643+
aliceClient.crypto.onToDeviceEvent(new MatrixEvent({
644+
type: "m.room_key.withheld",
645+
sender: "@bob:example.com",
646+
content: {
647+
algorithm: "m.megolm.v1.aes-sha2",
648+
room_id: roomId,
649+
session_id: "session_id2",
650+
sender_key: bobDevice.deviceCurve25519Key,
651+
code: "m.blacklisted",
652+
reason: "You have been blocked",
653+
},
654+
}));
655+
656+
await expect(aliceClient.crypto.decryptEvent(new MatrixEvent({
657+
type: "m.room.encrypted",
658+
sender: "@bob:example.com",
659+
event_id: "$event",
660+
room_id: roomId,
661+
content: {
662+
algorithm: "m.megolm.v1.aes-sha2",
663+
ciphertext: "blablabla",
664+
device_id: "bobdevice",
665+
sender_key: bobDevice.deviceCurve25519Key,
666+
session_id: "session_id2",
640667
},
641668
}))).rejects.toThrow("The sender has blocked you.");
642669
});
@@ -665,7 +692,7 @@ describe("MegolmDecryption", function() {
665692
content: {
666693
algorithm: "m.megolm.v1.aes-sha2",
667694
room_id: roomId,
668-
session_id: "session_id",
695+
session_id: "session_id1",
669696
sender_key: bobDevice.deviceCurve25519Key,
670697
code: "m.no_olm",
671698
reason: "Unable to establish a secure channel.",
@@ -686,7 +713,39 @@ describe("MegolmDecryption", function() {
686713
ciphertext: "blablabla",
687714
device_id: "bobdevice",
688715
sender_key: bobDevice.deviceCurve25519Key,
689-
session_id: "session_id",
716+
session_id: "session_id1",
717+
},
718+
origin_server_ts: now,
719+
}))).rejects.toThrow("The sender was unable to establish a secure channel.");
720+
721+
aliceClient.crypto.onToDeviceEvent(new MatrixEvent({
722+
type: "m.room_key.withheld",
723+
sender: "@bob:example.com",
724+
content: {
725+
algorithm: "m.megolm.v1.aes-sha2",
726+
room_id: roomId,
727+
session_id: "session_id2",
728+
sender_key: bobDevice.deviceCurve25519Key,
729+
code: "m.no_olm",
730+
reason: "Unable to establish a secure channel.",
731+
},
732+
}));
733+
734+
await new Promise((resolve) => {
735+
setTimeout(resolve, 100);
736+
});
737+
738+
await expect(aliceClient.crypto.decryptEvent(new MatrixEvent({
739+
type: "m.room.encrypted",
740+
sender: "@bob:example.com",
741+
event_id: "$event",
742+
room_id: roomId,
743+
content: {
744+
algorithm: "m.megolm.v1.aes-sha2",
745+
ciphertext: "blablabla",
746+
device_id: "bobdevice",
747+
sender_key: bobDevice.deviceCurve25519Key,
748+
session_id: "session_id2",
690749
},
691750
origin_server_ts: now,
692751
}))).rejects.toThrow("The sender was unable to establish a secure channel.");

0 commit comments

Comments
 (0)