1
0
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:
Florian Duros
2023-10-09 15:23:45 +02:00
committed by GitHub
parent 223dfffdfb
commit bb8a894105
2 changed files with 20 additions and 4 deletions

View File

@@ -44,6 +44,7 @@ import {
EventShieldColour,
EventShieldReason,
ImportRoomKeysOpts,
KeyBackupCheck,
VerificationRequest,
} from "../../../src/crypto-api";
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 () => {
// 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>(), {
baseUrl: "http://server/",
prefix: "",
@@ -890,9 +906,6 @@ describe("RustCrypto", () => {
{} 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
const keyBackupStatusPromise = new Promise<boolean>((resolve) =>
rustCrypto.once(CryptoEvent.KeyBackupStatus, resolve),

View File

@@ -153,6 +153,9 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
]);
this.crossSigningIdentity = new CrossSigningIdentity(olmMachine, this.outgoingRequestProcessor, secretStorage);
// Check and start in background the key backup connection
this.checkKeyBackupAndEnable();
}
/**