You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
Call RustBackupManager.checkKeyBackupAndEnable when RustCrypto is created (#3784)
This commit is contained in:
@@ -44,6 +44,7 @@ import {
|
|||||||
EventShieldColour,
|
EventShieldColour,
|
||||||
EventShieldReason,
|
EventShieldReason,
|
||||||
ImportRoomKeysOpts,
|
ImportRoomKeysOpts,
|
||||||
|
KeyBackupCheck,
|
||||||
VerificationRequest,
|
VerificationRequest,
|
||||||
} from "../../../src/crypto-api";
|
} from "../../../src/crypto-api";
|
||||||
import * as testData from "../../test-utils/test-data";
|
import * as testData from "../../test-utils/test-data";
|
||||||
@@ -864,8 +865,23 @@ describe("RustCrypto", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("onUserIdentityUpdated", () => {
|
describe("key backup", () => {
|
||||||
|
it("is started when rust crypto is created", async () => {
|
||||||
|
// `RustCrypto.checkKeyBackupAndEnable` async call is made in background in the RustCrypto constructor.
|
||||||
|
// We don't have an instance of the rust crypto yet, we spy directly in the prototype.
|
||||||
|
const spyCheckKeyBackupAndEnable = jest
|
||||||
|
.spyOn(RustCrypto.prototype, "checkKeyBackupAndEnable")
|
||||||
|
.mockResolvedValue({} as KeyBackupCheck);
|
||||||
|
|
||||||
|
await makeTestRustCrypto();
|
||||||
|
|
||||||
|
expect(spyCheckKeyBackupAndEnable).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("raises KeyBackupStatus event when identify change", async () => {
|
it("raises KeyBackupStatus event when identify change", async () => {
|
||||||
|
// Return the key backup
|
||||||
|
fetchMock.get("path:/_matrix/client/v3/room_keys/version", testData.SIGNED_BACKUP_DATA);
|
||||||
|
|
||||||
const mockHttpApi = new MatrixHttpApi(new TypedEventEmitter<HttpApiEvent, HttpApiEventHandlerMap>(), {
|
const mockHttpApi = new MatrixHttpApi(new TypedEventEmitter<HttpApiEvent, HttpApiEventHandlerMap>(), {
|
||||||
baseUrl: "http://server/",
|
baseUrl: "http://server/",
|
||||||
prefix: "",
|
prefix: "",
|
||||||
@@ -890,9 +906,6 @@ describe("RustCrypto", () => {
|
|||||||
{} as CryptoCallbacks,
|
{} as CryptoCallbacks,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Return the key backup
|
|
||||||
fetchMock.get("path:/_matrix/client/v3/room_keys/version", testData.SIGNED_BACKUP_DATA);
|
|
||||||
|
|
||||||
// Wait for the key backup to be available
|
// Wait for the key backup to be available
|
||||||
const keyBackupStatusPromise = new Promise<boolean>((resolve) =>
|
const keyBackupStatusPromise = new Promise<boolean>((resolve) =>
|
||||||
rustCrypto.once(CryptoEvent.KeyBackupStatus, resolve),
|
rustCrypto.once(CryptoEvent.KeyBackupStatus, resolve),
|
||||||
|
|||||||
@@ -153,6 +153,9 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
this.crossSigningIdentity = new CrossSigningIdentity(olmMachine, this.outgoingRequestProcessor, secretStorage);
|
this.crossSigningIdentity = new CrossSigningIdentity(olmMachine, this.outgoingRequestProcessor, secretStorage);
|
||||||
|
|
||||||
|
// Check and start in background the key backup connection
|
||||||
|
this.checkKeyBackupAndEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user