2018-06-15 14:33:07 +02:00
|
|
|
/*
|
2024-09-09 15:57:16 +02:00
|
|
|
Copyright 2018-2024 New Vector Ltd.
|
2018-06-15 14:33:07 +02:00
|
|
|
|
2024-09-09 15:57:16 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2018-06-15 14:33:07 +02:00
|
|
|
*/
|
|
|
|
|
2024-05-20 16:53:50 +02:00
|
|
|
import { mocked, Mocked, MockedObject } from "jest-mock";
|
2024-10-16 12:52:28 +02:00
|
|
|
import { HttpApiEvent, MatrixClient, MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/matrix";
|
2024-03-25 20:57:29 +01:00
|
|
|
import { decryptExistingEvent, mkDecryptionFailureMatrixEvent } from "matrix-js-sdk/src/testing";
|
2024-10-16 12:52:28 +02:00
|
|
|
import { CryptoApi, DecryptionFailureCode, UserVerificationStatus, CryptoEvent } from "matrix-js-sdk/src/crypto-api";
|
2024-05-16 02:25:58 +02:00
|
|
|
import { sleep } from "matrix-js-sdk/src/utils";
|
2018-06-15 14:33:07 +02:00
|
|
|
|
2024-10-15 15:57:26 +02:00
|
|
|
import { DecryptionFailureTracker, ErrorProperties } from "../../src/DecryptionFailureTracker";
|
|
|
|
import { stubClient } from "../test-utils";
|
|
|
|
import * as Lifecycle from "../../src/Lifecycle";
|
2021-10-23 00:23:32 +02:00
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
async function createFailedDecryptionEvent(opts: { sender?: string; code?: DecryptionFailureCode } = {}) {
|
2024-03-22 16:48:29 +01:00
|
|
|
return await mkDecryptionFailureMatrixEvent({
|
|
|
|
roomId: "!room:id",
|
2024-05-16 02:25:58 +02:00
|
|
|
sender: opts.sender ?? "@alice:example.com",
|
|
|
|
code: opts.code ?? DecryptionFailureCode.UNKNOWN_ERROR,
|
2024-03-22 16:48:29 +01:00
|
|
|
msg: ":(",
|
2018-06-15 14:33:07 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
// wrap tracker.eventDecrypted so that we don't need to have so many `ts-ignore`s
|
|
|
|
function eventDecrypted(tracker: DecryptionFailureTracker, e: MatrixEvent, nowTs: number): void {
|
|
|
|
// @ts-ignore access to private member
|
|
|
|
return tracker.eventDecrypted(e, nowTs);
|
|
|
|
}
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
describe("DecryptionFailureTracker", function () {
|
2024-05-20 16:53:50 +02:00
|
|
|
afterEach(() => {
|
|
|
|
localStorage.clear();
|
|
|
|
});
|
|
|
|
|
2024-03-22 16:48:29 +01:00
|
|
|
it("tracks a failed decryption for a visible event", async function () {
|
|
|
|
const failedDecryptionEvent = await createFailedDecryptionEvent();
|
2018-06-28 16:03:47 +02:00
|
|
|
|
|
|
|
let count = 0;
|
2024-03-25 20:57:29 +01:00
|
|
|
// @ts-ignore access to private constructor
|
2022-12-12 12:24:14 +01:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
() => count++,
|
2022-12-12 12:24:14 +01:00
|
|
|
() => "UnknownError",
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2022-12-12 12:24:14 +01:00
|
|
|
);
|
2018-06-15 14:33:07 +02:00
|
|
|
|
2022-01-19 20:31:43 +01:00
|
|
|
tracker.addVisibleEvent(failedDecryptionEvent);
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, failedDecryptionEvent, Date.now());
|
2018-06-15 14:33:07 +02:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
2024-03-25 20:57:29 +01:00
|
|
|
// should track a failure for an event that failed decryption
|
|
|
|
expect(count).not.toBe(0);
|
2018-06-15 14:33:07 +02:00
|
|
|
});
|
|
|
|
|
2024-03-22 16:48:29 +01:00
|
|
|
it("tracks a failed decryption with expected raw error for a visible event", async function () {
|
2024-05-16 02:25:58 +02:00
|
|
|
const failedDecryptionEvent = await createFailedDecryptionEvent({
|
|
|
|
code: DecryptionFailureCode.OLM_UNKNOWN_MESSAGE_INDEX,
|
|
|
|
});
|
2022-05-05 05:46:03 +02:00
|
|
|
|
|
|
|
let count = 0;
|
|
|
|
let reportedRawCode = "";
|
2024-03-25 20:57:29 +01:00
|
|
|
// @ts-ignore access to private constructor
|
2022-12-12 12:24:14 +01:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
(_errCode: string, rawCode: string) => {
|
|
|
|
count++;
|
2022-12-12 12:24:14 +01:00
|
|
|
reportedRawCode = rawCode;
|
|
|
|
},
|
|
|
|
() => "UnknownError",
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2022-12-12 12:24:14 +01:00
|
|
|
);
|
2022-05-05 05:46:03 +02:00
|
|
|
|
|
|
|
tracker.addVisibleEvent(failedDecryptionEvent);
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, failedDecryptionEvent, Date.now());
|
2022-05-05 05:46:03 +02:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
2024-03-25 20:57:29 +01:00
|
|
|
// should track a failure for an event that failed decryption
|
|
|
|
expect(count).not.toBe(0);
|
|
|
|
|
|
|
|
// Should add the rawCode to the event context
|
2024-04-17 14:36:01 +02:00
|
|
|
expect(reportedRawCode).toBe("OLM_UNKNOWN_MESSAGE_INDEX");
|
2022-05-05 05:46:03 +02:00
|
|
|
});
|
|
|
|
|
2024-03-22 16:48:29 +01:00
|
|
|
it("tracks a failed decryption for an event that becomes visible later", async function () {
|
|
|
|
const failedDecryptionEvent = await createFailedDecryptionEvent();
|
2022-01-19 20:31:43 +01:00
|
|
|
|
|
|
|
let count = 0;
|
2024-03-25 20:57:29 +01:00
|
|
|
// @ts-ignore access to private constructor
|
2022-12-12 12:24:14 +01:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
() => count++,
|
2022-12-12 12:24:14 +01:00
|
|
|
() => "UnknownError",
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2022-12-12 12:24:14 +01:00
|
|
|
);
|
2022-01-19 20:31:43 +01:00
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, failedDecryptionEvent, Date.now());
|
2022-01-19 20:31:43 +01:00
|
|
|
tracker.addVisibleEvent(failedDecryptionEvent);
|
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
2024-03-25 20:57:29 +01:00
|
|
|
// should track a failure for an event that failed decryption
|
|
|
|
expect(count).not.toBe(0);
|
2022-01-19 20:31:43 +01:00
|
|
|
});
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
it("tracks visible vs. not visible events", async () => {
|
|
|
|
const propertiesByErrorCode: Record<string, ErrorProperties> = {};
|
2024-03-25 20:57:29 +01:00
|
|
|
// @ts-ignore access to private constructor
|
2022-12-12 12:24:14 +01:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
(errorCode: string, rawError: string, properties: ErrorProperties) => {
|
|
|
|
propertiesByErrorCode[errorCode] = properties;
|
|
|
|
},
|
|
|
|
(error: string) => error,
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2022-12-12 12:24:14 +01:00
|
|
|
);
|
2022-01-19 20:31:43 +01:00
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
// use three different errors so that we can distinguish the reports
|
|
|
|
const error1 = DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID;
|
|
|
|
const error2 = DecryptionFailureCode.MEGOLM_BAD_ROOM;
|
|
|
|
const error3 = DecryptionFailureCode.MEGOLM_MISSING_FIELDS;
|
|
|
|
|
|
|
|
// event that will be marked as visible before it's marked as undecryptable
|
|
|
|
const markedVisibleFirst = await createFailedDecryptionEvent({ code: error1 });
|
|
|
|
// event that will be marked as undecryptable before it's marked as visible
|
|
|
|
const markedUndecryptableFirst = await createFailedDecryptionEvent({ code: error2 });
|
|
|
|
// event that is never marked as visible
|
|
|
|
const neverVisible = await createFailedDecryptionEvent({ code: error3 });
|
|
|
|
|
|
|
|
tracker.addVisibleEvent(markedVisibleFirst);
|
|
|
|
|
|
|
|
const now = Date.now();
|
|
|
|
eventDecrypted(tracker, markedVisibleFirst, now);
|
|
|
|
eventDecrypted(tracker, markedUndecryptableFirst, now);
|
|
|
|
eventDecrypted(tracker, neverVisible, now);
|
|
|
|
|
|
|
|
tracker.addVisibleEvent(markedUndecryptableFirst);
|
2022-01-19 20:31:43 +01:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
expect(propertiesByErrorCode[error1].wasVisibleToUser).toBe(true);
|
|
|
|
expect(propertiesByErrorCode[error2].wasVisibleToUser).toBe(true);
|
|
|
|
expect(propertiesByErrorCode[error3].wasVisibleToUser).toBe(false);
|
2022-01-19 20:31:43 +01:00
|
|
|
});
|
|
|
|
|
2024-03-22 16:48:29 +01:00
|
|
|
it("does not track a failed decryption where the event is subsequently successfully decrypted", async () => {
|
|
|
|
const decryptedEvent = await createFailedDecryptionEvent();
|
2024-03-25 20:57:29 +01:00
|
|
|
// @ts-ignore access to private constructor
|
2022-12-12 12:24:14 +01:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
() => {
|
2024-03-25 20:57:29 +01:00
|
|
|
// should not track an event that has since been decrypted correctly
|
|
|
|
expect(true).toBe(false);
|
2022-12-12 12:24:14 +01:00
|
|
|
},
|
|
|
|
() => "UnknownError",
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2022-12-12 12:24:14 +01:00
|
|
|
);
|
2018-06-15 14:33:07 +02:00
|
|
|
|
2022-01-19 20:31:43 +01:00
|
|
|
tracker.addVisibleEvent(decryptedEvent);
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
2018-06-15 14:33:07 +02:00
|
|
|
|
2024-03-25 20:57:29 +01:00
|
|
|
// Indicate successful decryption.
|
|
|
|
await decryptExistingEvent(decryptedEvent, {
|
|
|
|
plainType: "m.room.message",
|
|
|
|
plainContent: { body: "success" },
|
|
|
|
});
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
2018-06-15 14:33:07 +02:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it(
|
|
|
|
"does not track a failed decryption where the event is subsequently successfully decrypted " +
|
|
|
|
"and later becomes visible",
|
2024-03-22 16:48:29 +01:00
|
|
|
async () => {
|
|
|
|
const decryptedEvent = await createFailedDecryptionEvent();
|
2024-03-25 20:57:29 +01:00
|
|
|
// @ts-ignore access to private constructor
|
2022-12-12 12:24:14 +01:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
() => {
|
2024-03-25 20:57:29 +01:00
|
|
|
// should not track an event that has since been decrypted correctly
|
|
|
|
expect(true).toBe(false);
|
2022-12-12 12:24:14 +01:00
|
|
|
},
|
|
|
|
() => "UnknownError",
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2022-12-12 12:24:14 +01:00
|
|
|
);
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
2022-12-12 12:24:14 +01:00
|
|
|
|
2024-03-25 20:57:29 +01:00
|
|
|
// Indicate successful decryption.
|
|
|
|
await decryptExistingEvent(decryptedEvent, {
|
|
|
|
plainType: "m.room.message",
|
|
|
|
plainContent: { body: "success" },
|
|
|
|
});
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
2022-12-12 12:24:14 +01:00
|
|
|
|
|
|
|
tracker.addVisibleEvent(decryptedEvent);
|
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
},
|
|
|
|
);
|
2022-01-19 20:31:43 +01:00
|
|
|
|
2024-03-22 16:48:29 +01:00
|
|
|
it("only tracks a single failure per event, despite multiple failed decryptions for multiple events", async () => {
|
|
|
|
const decryptedEvent = await createFailedDecryptionEvent();
|
|
|
|
const decryptedEvent2 = await createFailedDecryptionEvent();
|
2018-06-15 14:33:07 +02:00
|
|
|
|
|
|
|
let count = 0;
|
2024-03-25 20:57:29 +01:00
|
|
|
// @ts-ignore access to private constructor
|
2022-12-12 12:24:14 +01:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
() => count++,
|
2022-12-12 12:24:14 +01:00
|
|
|
() => "UnknownError",
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2022-12-12 12:24:14 +01:00
|
|
|
);
|
2018-06-15 14:33:07 +02:00
|
|
|
|
2022-01-19 20:31:43 +01:00
|
|
|
tracker.addVisibleEvent(decryptedEvent);
|
|
|
|
|
2018-06-15 14:33:07 +02:00
|
|
|
// Arbitrary number of failed decryptions for both events
|
2024-05-16 02:25:58 +02:00
|
|
|
const now = Date.now();
|
|
|
|
eventDecrypted(tracker, decryptedEvent, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent2, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent2, now);
|
2022-01-19 20:31:43 +01:00
|
|
|
tracker.addVisibleEvent(decryptedEvent2);
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, decryptedEvent2, now);
|
2018-06-15 14:33:07 +02:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
2024-05-17 18:19:31 +02:00
|
|
|
// Simulated polling of `checkFailures`, an arbitrary number ( > 2 ) times
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
tracker.checkFailures(Infinity);
|
2018-06-15 14:33:07 +02:00
|
|
|
|
2024-03-25 20:57:29 +01:00
|
|
|
// should only track a single failure per event
|
|
|
|
expect(count).toBe(2);
|
2018-06-15 14:33:07 +02:00
|
|
|
});
|
|
|
|
|
2024-03-22 16:48:29 +01:00
|
|
|
it("should not track a failure for an event that was tracked previously", async () => {
|
|
|
|
const decryptedEvent = await createFailedDecryptionEvent();
|
2018-06-15 15:48:20 +02:00
|
|
|
|
2018-06-28 16:03:47 +02:00
|
|
|
let count = 0;
|
2024-03-25 20:57:29 +01:00
|
|
|
// @ts-ignore access to private constructor
|
2022-12-12 12:24:14 +01:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
() => count++,
|
2022-12-12 12:24:14 +01:00
|
|
|
() => "UnknownError",
|
|
|
|
);
|
2024-05-20 16:53:50 +02:00
|
|
|
await tracker.start(mockClient());
|
2018-06-15 15:48:20 +02:00
|
|
|
|
2022-01-19 20:31:43 +01:00
|
|
|
tracker.addVisibleEvent(decryptedEvent);
|
|
|
|
|
2018-06-15 15:48:20 +02:00
|
|
|
// Indicate decryption
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
2018-06-15 15:48:20 +02:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
|
|
|
// Indicate a second decryption, after having tracked the failure
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
2024-05-17 18:19:31 +02:00
|
|
|
tracker.checkFailures(Infinity);
|
2018-06-15 15:48:20 +02:00
|
|
|
|
2024-03-25 20:57:29 +01:00
|
|
|
// should only track a single failure per event
|
|
|
|
expect(count).toBe(1);
|
2018-06-15 15:48:20 +02:00
|
|
|
});
|
2018-06-15 16:26:53 +02:00
|
|
|
|
2024-05-20 16:53:50 +02:00
|
|
|
it("should not report a failure for an event that was reported in a previous session", async () => {
|
2024-03-22 16:48:29 +01:00
|
|
|
const decryptedEvent = await createFailedDecryptionEvent();
|
2018-06-15 16:26:53 +02:00
|
|
|
|
2018-06-28 16:03:47 +02:00
|
|
|
let count = 0;
|
2024-03-25 20:57:29 +01:00
|
|
|
// @ts-ignore access to private constructor
|
2022-12-12 12:24:14 +01:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
() => count++,
|
2022-12-12 12:24:14 +01:00
|
|
|
() => "UnknownError",
|
|
|
|
);
|
2024-05-20 16:53:50 +02:00
|
|
|
await tracker.start(mockClient());
|
2018-06-15 16:26:53 +02:00
|
|
|
|
2022-01-19 20:31:43 +01:00
|
|
|
tracker.addVisibleEvent(decryptedEvent);
|
|
|
|
|
2018-06-15 16:26:53 +02:00
|
|
|
// Indicate decryption
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
2018-06-15 16:26:53 +02:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
// NB: This saves to localStorage specific to DFT
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
|
|
|
// Simulate the browser refreshing by destroying tracker and creating a new tracker
|
2024-03-25 20:57:29 +01:00
|
|
|
// @ts-ignore access to private constructor
|
2022-12-12 12:24:14 +01:00
|
|
|
const secondTracker = new DecryptionFailureTracker(
|
2024-05-20 16:53:50 +02:00
|
|
|
() => count++,
|
2022-12-12 12:24:14 +01:00
|
|
|
() => "UnknownError",
|
|
|
|
);
|
2024-05-20 16:53:50 +02:00
|
|
|
await secondTracker.start(mockClient());
|
2018-06-15 18:08:11 +02:00
|
|
|
|
2022-01-19 20:31:43 +01:00
|
|
|
secondTracker.addVisibleEvent(decryptedEvent);
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(secondTracker, decryptedEvent, Date.now());
|
2018-06-15 16:26:53 +02:00
|
|
|
secondTracker.checkFailures(Infinity);
|
|
|
|
|
2024-03-25 20:57:29 +01:00
|
|
|
// should only track a single failure per event
|
|
|
|
expect(count).toBe(1);
|
2018-06-15 16:26:53 +02:00
|
|
|
});
|
2018-07-05 14:54:44 +02:00
|
|
|
|
2024-05-20 16:53:50 +02:00
|
|
|
it("should report a failure for an event that was tracked but not reported in a previous session", async () => {
|
|
|
|
const decryptedEvent = await createFailedDecryptionEvent();
|
|
|
|
|
|
|
|
let count = 0;
|
|
|
|
|
|
|
|
// @ts-ignore access to private constructor
|
|
|
|
const tracker = new DecryptionFailureTracker(
|
|
|
|
() => count++,
|
|
|
|
() => "UnknownError",
|
|
|
|
);
|
|
|
|
await tracker.start(mockClient());
|
|
|
|
|
|
|
|
tracker.addVisibleEvent(decryptedEvent);
|
|
|
|
|
|
|
|
// Indicate decryption
|
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
|
|
|
|
|
|
|
// we do *not* call `checkFailures` here
|
|
|
|
expect(count).toBe(0);
|
|
|
|
|
|
|
|
// Simulate the browser refreshing by destroying tracker and creating a new tracker
|
|
|
|
// @ts-ignore access to private constructor
|
|
|
|
const secondTracker = new DecryptionFailureTracker(
|
|
|
|
() => count++,
|
|
|
|
() => "UnknownError",
|
|
|
|
);
|
|
|
|
await secondTracker.start(mockClient());
|
|
|
|
|
|
|
|
secondTracker.addVisibleEvent(decryptedEvent);
|
|
|
|
|
|
|
|
eventDecrypted(secondTracker, decryptedEvent, Date.now());
|
|
|
|
secondTracker.checkFailures(Infinity);
|
|
|
|
expect(count).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should report a failure for an event that was reported before a logout/login cycle", async () => {
|
|
|
|
const decryptedEvent = await createFailedDecryptionEvent();
|
|
|
|
|
|
|
|
let count = 0;
|
|
|
|
|
|
|
|
// @ts-ignore access to private constructor
|
|
|
|
const tracker = new DecryptionFailureTracker(
|
|
|
|
() => count++,
|
|
|
|
() => "UnknownError",
|
|
|
|
);
|
|
|
|
await tracker.start(mockClient());
|
|
|
|
|
|
|
|
tracker.addVisibleEvent(decryptedEvent);
|
|
|
|
|
|
|
|
// Indicate decryption
|
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
expect(count).toBe(1);
|
|
|
|
|
|
|
|
// Simulate a logout/login cycle
|
|
|
|
await Lifecycle.onLoggedOut();
|
|
|
|
await tracker.start(mockClient());
|
|
|
|
|
|
|
|
tracker.addVisibleEvent(decryptedEvent);
|
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
expect(count).toBe(2);
|
|
|
|
});
|
|
|
|
|
2024-03-22 16:48:29 +01:00
|
|
|
it("should count different error codes separately for multiple failures with different error codes", async () => {
|
2024-03-25 20:57:29 +01:00
|
|
|
const counts: Record<string, number> = {};
|
|
|
|
|
|
|
|
// @ts-ignore access to private constructor
|
2018-07-05 14:54:44 +02:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
(errorCode: string) => (counts[errorCode] = (counts[errorCode] || 0) + 1),
|
2024-04-17 14:36:01 +02:00
|
|
|
(error: DecryptionFailureCode) =>
|
|
|
|
error === DecryptionFailureCode.UNKNOWN_ERROR ? "UnknownError" : "OlmKeysNotSentError",
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2018-07-05 14:54:44 +02:00
|
|
|
);
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
const decryptedEvent1 = await createFailedDecryptionEvent({
|
|
|
|
code: DecryptionFailureCode.UNKNOWN_ERROR,
|
|
|
|
});
|
|
|
|
const decryptedEvent2 = await createFailedDecryptionEvent({
|
|
|
|
code: DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID,
|
|
|
|
});
|
|
|
|
const decryptedEvent3 = await createFailedDecryptionEvent({
|
|
|
|
code: DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID,
|
|
|
|
});
|
2022-01-19 20:31:43 +01:00
|
|
|
|
|
|
|
tracker.addVisibleEvent(decryptedEvent1);
|
|
|
|
tracker.addVisibleEvent(decryptedEvent2);
|
|
|
|
tracker.addVisibleEvent(decryptedEvent3);
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
// One failure of UNKNOWN_ERROR, and effectively two for MEGOLM_UNKNOWN_INBOUND_SESSION_ID
|
|
|
|
const now = Date.now();
|
|
|
|
eventDecrypted(tracker, decryptedEvent1, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent2, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent2, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent3, now);
|
2018-07-05 14:54:44 +02:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
2022-01-19 20:31:43 +01:00
|
|
|
//expect(counts['UnknownError']).toBe(1, 'should track one UnknownError');
|
2024-03-25 20:57:29 +01:00
|
|
|
expect(counts["OlmKeysNotSentError"]).toBe(2);
|
2018-07-05 14:54:44 +02:00
|
|
|
});
|
|
|
|
|
2024-03-22 16:48:29 +01:00
|
|
|
it("should aggregate error codes correctly", async () => {
|
2024-03-25 20:57:29 +01:00
|
|
|
const counts: Record<string, number> = {};
|
|
|
|
|
|
|
|
// @ts-ignore access to private constructor
|
2018-07-05 14:54:44 +02:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
(errorCode: string) => (counts[errorCode] = (counts[errorCode] || 0) + 1),
|
2024-03-25 20:57:29 +01:00
|
|
|
(_errorCode: string) => "OlmUnspecifiedError",
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2018-07-05 14:54:44 +02:00
|
|
|
);
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
const decryptedEvent1 = await createFailedDecryptionEvent({
|
|
|
|
code: DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID,
|
|
|
|
});
|
|
|
|
const decryptedEvent2 = await createFailedDecryptionEvent({
|
|
|
|
code: DecryptionFailureCode.OLM_UNKNOWN_MESSAGE_INDEX,
|
|
|
|
});
|
|
|
|
const decryptedEvent3 = await createFailedDecryptionEvent({
|
|
|
|
code: DecryptionFailureCode.UNKNOWN_ERROR,
|
|
|
|
});
|
2022-01-19 20:31:43 +01:00
|
|
|
|
|
|
|
tracker.addVisibleEvent(decryptedEvent1);
|
|
|
|
tracker.addVisibleEvent(decryptedEvent2);
|
|
|
|
tracker.addVisibleEvent(decryptedEvent3);
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
const now = Date.now();
|
|
|
|
eventDecrypted(tracker, decryptedEvent1, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent2, now);
|
|
|
|
eventDecrypted(tracker, decryptedEvent3, now);
|
2018-07-05 14:54:44 +02:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
2024-03-25 20:57:29 +01:00
|
|
|
expect(counts["OlmUnspecifiedError"]).toBe(3);
|
2018-07-05 14:54:44 +02:00
|
|
|
});
|
2022-01-19 20:31:43 +01:00
|
|
|
|
2024-03-22 16:48:29 +01:00
|
|
|
it("should remap error codes correctly", async () => {
|
2024-03-25 20:57:29 +01:00
|
|
|
const counts: Record<string, number> = {};
|
|
|
|
|
|
|
|
// @ts-ignore access to private constructor
|
2022-01-19 20:31:43 +01:00
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
(errorCode: string) => (counts[errorCode] = (counts[errorCode] || 0) + 1),
|
2024-03-25 20:57:29 +01:00
|
|
|
(errorCode: string) => Array.from(errorCode).reverse().join(""),
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2022-01-19 20:31:43 +01:00
|
|
|
);
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
const decryptedEvent = await createFailedDecryptionEvent({
|
|
|
|
code: DecryptionFailureCode.OLM_UNKNOWN_MESSAGE_INDEX,
|
|
|
|
});
|
2022-01-19 20:31:43 +01:00
|
|
|
tracker.addVisibleEvent(decryptedEvent);
|
2024-05-16 02:25:58 +02:00
|
|
|
eventDecrypted(tracker, decryptedEvent, Date.now());
|
2022-01-19 20:31:43 +01:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
2024-03-25 20:57:29 +01:00
|
|
|
// should track remapped error code
|
2024-04-17 14:36:01 +02:00
|
|
|
expect(counts["XEDNI_EGASSEM_NWONKNU_MLO"]).toBe(1);
|
2022-01-19 20:31:43 +01:00
|
|
|
});
|
2024-04-29 19:18:57 +02:00
|
|
|
|
|
|
|
it("default error code mapper maps error codes correctly", async () => {
|
|
|
|
const errorCodes: string[] = [];
|
|
|
|
|
|
|
|
// @ts-ignore access to private constructor
|
|
|
|
const tracker = new DecryptionFailureTracker(
|
2024-05-16 02:25:58 +02:00
|
|
|
(errorCode: string) => {
|
2024-04-29 19:18:57 +02:00
|
|
|
errorCodes.push(errorCode);
|
|
|
|
},
|
|
|
|
// @ts-ignore access to private member
|
|
|
|
DecryptionFailureTracker.instance.errorCodeMapFn,
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2024-04-29 19:18:57 +02:00
|
|
|
);
|
|
|
|
|
2024-05-16 02:25:58 +02:00
|
|
|
const now = Date.now();
|
|
|
|
|
2024-07-10 11:22:59 +02:00
|
|
|
async function createAndTrackEventWithError(code: DecryptionFailureCode) {
|
|
|
|
const event = await createFailedDecryptionEvent({ code });
|
|
|
|
tracker.addVisibleEvent(event);
|
|
|
|
eventDecrypted(tracker, event, now);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID);
|
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.OLM_UNKNOWN_MESSAGE_INDEX);
|
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.HISTORICAL_MESSAGE_NO_KEY_BACKUP);
|
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED);
|
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.HISTORICAL_MESSAGE_WORKING_BACKUP);
|
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.HISTORICAL_MESSAGE_USER_NOT_JOINED);
|
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.MEGOLM_KEY_WITHHELD);
|
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.MEGOLM_KEY_WITHHELD_FOR_UNVERIFIED_DEVICE);
|
2024-10-28 14:16:48 +01:00
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.SENDER_IDENTITY_PREVIOUSLY_VERIFIED);
|
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.UNSIGNED_SENDER_DEVICE);
|
2024-07-10 11:22:59 +02:00
|
|
|
await createAndTrackEventWithError(DecryptionFailureCode.UNKNOWN_ERROR);
|
2024-04-29 19:18:57 +02:00
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
|
|
|
expect(errorCodes).toEqual([
|
|
|
|
"OlmKeysNotSentError",
|
|
|
|
"OlmIndexError",
|
|
|
|
"HistoricalMessage",
|
|
|
|
"HistoricalMessage",
|
|
|
|
"HistoricalMessage",
|
|
|
|
"ExpectedDueToMembership",
|
2024-07-10 11:22:59 +02:00
|
|
|
"OlmKeysNotSentError",
|
|
|
|
"RoomKeysWithheldForUnverifiedDevice",
|
2024-10-28 14:16:48 +01:00
|
|
|
"ExpectedVerificationViolation",
|
|
|
|
"ExpectedSentByInsecureDevice",
|
2024-04-29 19:18:57 +02:00
|
|
|
"UnknownError",
|
|
|
|
]);
|
|
|
|
});
|
2024-05-16 02:25:58 +02:00
|
|
|
|
|
|
|
it("tracks late decryptions vs. undecryptable", async () => {
|
|
|
|
const propertiesByErrorCode: Record<string, ErrorProperties> = {};
|
|
|
|
// @ts-ignore access to private constructor
|
|
|
|
const tracker = new DecryptionFailureTracker(
|
|
|
|
(errorCode: string, rawError: string, properties: ErrorProperties) => {
|
|
|
|
propertiesByErrorCode[errorCode] = properties;
|
|
|
|
},
|
|
|
|
(error: string) => error,
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2024-05-16 02:25:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// use three different errors so that we can distinguish the reports
|
|
|
|
const error1 = DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID;
|
|
|
|
const error2 = DecryptionFailureCode.MEGOLM_BAD_ROOM;
|
|
|
|
const error3 = DecryptionFailureCode.MEGOLM_MISSING_FIELDS;
|
|
|
|
|
|
|
|
// event that will be slow to decrypt
|
|
|
|
const lateDecryption = await createFailedDecryptionEvent({ code: error1 });
|
|
|
|
// event that will be so slow to decrypt, it gets counted as undecryptable
|
|
|
|
const veryLateDecryption = await createFailedDecryptionEvent({ code: error2 });
|
|
|
|
// event that never gets decrypted
|
|
|
|
const neverDecrypted = await createFailedDecryptionEvent({ code: error3 });
|
|
|
|
|
|
|
|
tracker.addVisibleEvent(lateDecryption);
|
|
|
|
tracker.addVisibleEvent(veryLateDecryption);
|
|
|
|
tracker.addVisibleEvent(neverDecrypted);
|
|
|
|
|
|
|
|
const now = Date.now();
|
|
|
|
eventDecrypted(tracker, lateDecryption, now);
|
|
|
|
eventDecrypted(tracker, veryLateDecryption, now);
|
|
|
|
eventDecrypted(tracker, neverDecrypted, now);
|
|
|
|
|
|
|
|
await decryptExistingEvent(lateDecryption, {
|
|
|
|
plainType: "m.room.message",
|
|
|
|
plainContent: { body: "success" },
|
|
|
|
});
|
|
|
|
await decryptExistingEvent(veryLateDecryption, {
|
|
|
|
plainType: "m.room.message",
|
|
|
|
plainContent: { body: "success" },
|
|
|
|
});
|
|
|
|
eventDecrypted(tracker, lateDecryption, now + 40000);
|
|
|
|
eventDecrypted(tracker, veryLateDecryption, now + 100000);
|
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
|
|
|
expect(propertiesByErrorCode[error1].timeToDecryptMillis).toEqual(40000);
|
|
|
|
expect(propertiesByErrorCode[error2].timeToDecryptMillis).toEqual(-1);
|
|
|
|
expect(propertiesByErrorCode[error3].timeToDecryptMillis).toEqual(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("listens for client events", async () => {
|
|
|
|
// Test that the decryption failure tracker registers the right event
|
|
|
|
// handlers on start, and unregisters them when the client logs out.
|
2024-05-20 16:53:50 +02:00
|
|
|
const client = mockClient();
|
2024-05-16 02:25:58 +02:00
|
|
|
|
|
|
|
let errorCount: number = 0;
|
|
|
|
// @ts-ignore access to private constructor
|
|
|
|
const tracker = new DecryptionFailureTracker(
|
|
|
|
(errorCode: string, rawError: string, properties: ErrorProperties) => {
|
|
|
|
errorCount++;
|
|
|
|
},
|
|
|
|
(error: string) => error,
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2024-05-16 02:25:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// Calling .start will start some intervals. This test shouldn't run
|
|
|
|
// long enough for the timers to fire, but we'll use fake timers just
|
|
|
|
// to be safe.
|
|
|
|
jest.useFakeTimers();
|
2024-05-17 18:19:31 +02:00
|
|
|
await tracker.start(client);
|
2024-05-16 02:25:58 +02:00
|
|
|
|
|
|
|
// If the client fails to decrypt, it should get tracked
|
|
|
|
const failedDecryption = await createFailedDecryptionEvent();
|
|
|
|
client.emit(MatrixEventEvent.Decrypted, failedDecryption);
|
|
|
|
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
|
|
|
expect(errorCount).toEqual(1);
|
|
|
|
|
|
|
|
client.emit(HttpApiEvent.SessionLoggedOut, {} as any);
|
|
|
|
|
|
|
|
// After the client has logged out, we shouldn't be listening to events
|
|
|
|
// any more, so even if the client emits an event regarding a failed
|
|
|
|
// decryption, we won't track it.
|
|
|
|
const anotherFailedDecryption = await createFailedDecryptionEvent();
|
|
|
|
client.emit(MatrixEventEvent.Decrypted, anotherFailedDecryption);
|
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
|
|
|
expect(errorCount).toEqual(1);
|
|
|
|
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("tracks client information", async () => {
|
2024-05-20 16:53:50 +02:00
|
|
|
const client = mockClient();
|
2024-05-16 02:25:58 +02:00
|
|
|
const propertiesByErrorCode: Record<string, ErrorProperties> = {};
|
|
|
|
// @ts-ignore access to private constructor
|
|
|
|
const tracker = new DecryptionFailureTracker(
|
|
|
|
(errorCode: string, rawError: string, properties: ErrorProperties) => {
|
|
|
|
propertiesByErrorCode[errorCode] = properties;
|
|
|
|
},
|
|
|
|
(error: string) => error,
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2024-05-16 02:25:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// @ts-ignore access to private method
|
|
|
|
await tracker.calculateClientProperties(client);
|
|
|
|
// @ts-ignore access to private method
|
|
|
|
await tracker.registerHandlers(client);
|
|
|
|
|
|
|
|
// use three different errors so that we can distinguish the reports
|
|
|
|
const error1 = DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID;
|
|
|
|
const error2 = DecryptionFailureCode.MEGOLM_BAD_ROOM;
|
|
|
|
const error3 = DecryptionFailureCode.MEGOLM_MISSING_FIELDS;
|
|
|
|
|
|
|
|
// event from a federated user (@alice:example.com)
|
|
|
|
const federatedDecryption = await createFailedDecryptionEvent({
|
|
|
|
code: error1,
|
|
|
|
});
|
|
|
|
// event from a local user
|
|
|
|
const localDecryption = await createFailedDecryptionEvent({
|
|
|
|
sender: "@bob:matrix.org",
|
|
|
|
code: error2,
|
|
|
|
});
|
|
|
|
|
|
|
|
tracker.addVisibleEvent(federatedDecryption);
|
|
|
|
tracker.addVisibleEvent(localDecryption);
|
|
|
|
|
|
|
|
const now = Date.now();
|
|
|
|
eventDecrypted(tracker, federatedDecryption, now);
|
|
|
|
|
2024-05-20 16:53:50 +02:00
|
|
|
mocked(client.getCrypto()!.getUserVerificationStatus).mockResolvedValue(
|
|
|
|
new UserVerificationStatus(true, true, false),
|
|
|
|
);
|
2024-05-16 02:25:58 +02:00
|
|
|
client.emit(CryptoEvent.KeysChanged, {});
|
|
|
|
await sleep(100);
|
|
|
|
eventDecrypted(tracker, localDecryption, now);
|
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
|
|
|
expect(propertiesByErrorCode[error1].isMatrixDotOrg).toBe(true);
|
|
|
|
expect(propertiesByErrorCode[error1].cryptoSDK).toEqual("Rust");
|
|
|
|
|
|
|
|
expect(propertiesByErrorCode[error1].isFederated).toBe(true);
|
|
|
|
expect(propertiesByErrorCode[error1].userTrustsOwnIdentity).toEqual(false);
|
|
|
|
expect(propertiesByErrorCode[error2].isFederated).toBe(false);
|
|
|
|
expect(propertiesByErrorCode[error2].userTrustsOwnIdentity).toEqual(true);
|
|
|
|
|
|
|
|
// change client params, and make sure the reports the right values
|
|
|
|
client.getDomain.mockReturnValue("example.com");
|
2024-05-20 16:53:50 +02:00
|
|
|
mocked(client.getCrypto()!.getVersion).mockReturnValue("Olm 0.0.0");
|
2024-05-16 02:25:58 +02:00
|
|
|
// @ts-ignore access to private method
|
|
|
|
await tracker.calculateClientProperties(client);
|
|
|
|
|
|
|
|
const anotherFailure = await createFailedDecryptionEvent({
|
|
|
|
code: error3,
|
|
|
|
});
|
|
|
|
tracker.addVisibleEvent(anotherFailure);
|
|
|
|
eventDecrypted(tracker, anotherFailure, now);
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
expect(propertiesByErrorCode[error3].isMatrixDotOrg).toBe(false);
|
|
|
|
expect(propertiesByErrorCode[error3].cryptoSDK).toEqual("Legacy");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("keeps the original timestamp after repeated decryption failures", async () => {
|
|
|
|
const failedDecryptionEvent = await createFailedDecryptionEvent();
|
|
|
|
|
|
|
|
let failure: ErrorProperties | undefined;
|
|
|
|
// @ts-ignore access to private constructor
|
|
|
|
const tracker = new DecryptionFailureTracker(
|
|
|
|
(errorCode: string, rawError: string, properties: ErrorProperties) => {
|
|
|
|
failure = properties;
|
|
|
|
},
|
|
|
|
() => "UnknownError",
|
2024-06-06 15:02:34 +02:00
|
|
|
false,
|
2024-05-16 02:25:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
tracker.addVisibleEvent(failedDecryptionEvent);
|
|
|
|
|
|
|
|
const now = Date.now();
|
|
|
|
eventDecrypted(tracker, failedDecryptionEvent, now);
|
|
|
|
eventDecrypted(tracker, failedDecryptionEvent, now + 20000);
|
|
|
|
await decryptExistingEvent(failedDecryptionEvent, {
|
|
|
|
plainType: "m.room.message",
|
|
|
|
plainContent: { body: "success" },
|
|
|
|
});
|
|
|
|
eventDecrypted(tracker, failedDecryptionEvent, now + 50000);
|
|
|
|
|
|
|
|
// Pretend "now" is Infinity
|
|
|
|
tracker.checkFailures(Infinity);
|
|
|
|
|
|
|
|
// the time to decrypt should be relative to the first time we failed
|
|
|
|
// to decrypt, not the second
|
|
|
|
expect(failure?.timeToDecryptMillis).toEqual(50000);
|
|
|
|
});
|
2018-06-15 14:33:07 +02:00
|
|
|
});
|
2024-05-20 16:53:50 +02:00
|
|
|
|
|
|
|
function mockClient(): MockedObject<MatrixClient> {
|
|
|
|
const client = mocked(stubClient());
|
|
|
|
const mockCrypto = {
|
|
|
|
getVersion: jest.fn().mockReturnValue("Rust SDK 0.7.0 (61b175b), Vodozemac 0.5.1"),
|
|
|
|
getUserVerificationStatus: jest.fn().mockResolvedValue(new UserVerificationStatus(false, false, false)),
|
|
|
|
} as unknown as Mocked<CryptoApi>;
|
|
|
|
client.getCrypto.mockReturnValue(mockCrypto);
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
client.stopClient = jest.fn(() => {});
|
|
|
|
// @ts-ignore
|
|
|
|
client.removeAllListeners = jest.fn(() => {});
|
|
|
|
|
|
|
|
client.store = { destroy: jest.fn(() => {}) } as any;
|
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|