Skip to content

Commit b0c5dbe

Browse files
committed
tests for get|setGlobalErrorOnUnknownDevices
1 parent cb1a52d commit b0c5dbe

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

spec/integ/megolm-integ.spec.ts

+49
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,55 @@ describe("megolm", () => {
650650
]);
651651
});
652652

653+
describe("get|setGlobalErrorOnUnknownDevices", () => {
654+
it("should raise an error if crypto is disabled", () => {
655+
aliceTestClient.client["cryptoBackend"] = undefined;
656+
expect(() => aliceTestClient.client.setGlobalErrorOnUnknownDevices(true)).toThrowError(
657+
"encryption disabled",
658+
);
659+
expect(() => aliceTestClient.client.getGlobalErrorOnUnknownDevices()).toThrowError("encryption disabled");
660+
});
661+
662+
it("should permit sending to unknown devices", async () => {
663+
expect(aliceTestClient.client.getGlobalErrorOnUnknownDevices()).toBeTruthy();
664+
665+
aliceTestClient.expectKeyQuery({ device_keys: { "@alice:localhost": {} }, failures: {} });
666+
await aliceTestClient.start();
667+
const p2pSession = await establishOlmSession(aliceTestClient, testOlmAccount);
668+
669+
aliceTestClient.httpBackend.when("GET", "/sync").respond(200, getSyncResponse(["@bob:xyz"]));
670+
await aliceTestClient.flushSync();
671+
672+
// start out with the device unknown - the send should be rejected.
673+
aliceTestClient.httpBackend.when("POST", "/keys/query").respond(200, getTestKeysQueryResponse("@bob:xyz"));
674+
aliceTestClient.httpBackend.when("POST", "/keys/query").respond(200, getTestKeysQueryResponse("@bob:xyz"));
675+
676+
await Promise.all([
677+
aliceTestClient.client.sendTextMessage(ROOM_ID, "test").then(
678+
() => {
679+
throw new Error("sendTextMessage failed on an unknown device");
680+
},
681+
(e) => {
682+
expect(e.name).toEqual("UnknownDeviceError");
683+
},
684+
),
685+
aliceTestClient.httpBackend.flushAllExpected(),
686+
]);
687+
688+
// enable sending to unknown devices, and resend
689+
aliceTestClient.client.setGlobalErrorOnUnknownDevices(false);
690+
expect(aliceTestClient.client.getGlobalErrorOnUnknownDevices()).toBeFalsy();
691+
692+
const room = aliceTestClient.client.getRoom(ROOM_ID)!;
693+
const pendingMsg = room.getPendingEvents()[0];
694+
695+
await Promise.all([
696+
aliceTestClient.client.resendEvent(pendingMsg, room),
697+
expectSendKeyAndMessage(aliceTestClient.httpBackend, "@bob:xyz", testOlmAccount, p2pSession),
698+
]);
699+
});
700+
});
701+
653702
describe("get|setGlobalBlacklistUnverifiedDevices", () => {
654703
it("should raise an error if crypto is disabled", () => {
655704
aliceTestClient.client["cryptoBackend"] = undefined;

0 commit comments

Comments
 (0)