Skip to content

Commit c849533

Browse files
committed
tests for get|setGlobalErrorOnUnknownDevices
1 parent 36c29c6 commit c849533

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
@@ -532,6 +532,55 @@ describe("megolm", () => {
532532
]);
533533
});
534534

535+
describe("get|setGlobalErrorOnUnknownDevices", () => {
536+
it("should raise an error if crypto is disabled", () => {
537+
aliceTestClient.client["cryptoBackend"] = undefined;
538+
expect(() => aliceTestClient.client.setGlobalErrorOnUnknownDevices(true)).toThrowError(
539+
"encryption disabled",
540+
);
541+
expect(() => aliceTestClient.client.getGlobalErrorOnUnknownDevices()).toThrowError("encryption disabled");
542+
});
543+
544+
it("should permit sending to unknown devices", async () => {
545+
expect(aliceTestClient.client.getGlobalErrorOnUnknownDevices()).toBeTruthy();
546+
547+
aliceTestClient.expectKeyQuery({ device_keys: { "@alice:localhost": {} }, failures: {} });
548+
await aliceTestClient.start();
549+
const p2pSession = await establishOlmSession(aliceTestClient, testOlmAccount);
550+
551+
aliceTestClient.httpBackend.when("GET", "/sync").respond(200, getSyncResponse(["@bob:xyz"]));
552+
await aliceTestClient.flushSync();
553+
554+
// start out with the device unknown - the send should be rejected.
555+
aliceTestClient.httpBackend.when("POST", "/keys/query").respond(200, getTestKeysQueryResponse("@bob:xyz"));
556+
aliceTestClient.httpBackend.when("POST", "/keys/query").respond(200, getTestKeysQueryResponse("@bob:xyz"));
557+
558+
await Promise.all([
559+
aliceTestClient.client.sendTextMessage(ROOM_ID, "test").then(
560+
() => {
561+
throw new Error("sendTextMessage failed on an unknown device");
562+
},
563+
(e) => {
564+
expect(e.name).toEqual("UnknownDeviceError");
565+
},
566+
),
567+
aliceTestClient.httpBackend.flushAllExpected(),
568+
]);
569+
570+
// enable sending to unknown devices, and resend
571+
aliceTestClient.client.setGlobalErrorOnUnknownDevices(false);
572+
expect(aliceTestClient.client.getGlobalErrorOnUnknownDevices()).toBeFalsy();
573+
574+
const room = aliceTestClient.client.getRoom(ROOM_ID)!;
575+
const pendingMsg = room.getPendingEvents()[0];
576+
577+
await Promise.all([
578+
aliceTestClient.client.resendEvent(pendingMsg, room),
579+
expectSendKeyAndMessage(aliceTestClient.httpBackend, "@bob:xyz", testOlmAccount, p2pSession),
580+
]);
581+
});
582+
});
583+
535584
describe("get|setGlobalBlacklistUnverifiedDevices", () => {
536585
it("should raise an error if crypto is disabled", () => {
537586
aliceTestClient.client["cryptoBackend"] = undefined;

0 commit comments

Comments
 (0)