From ddb8e0aa3ae4d726a9b0e8c9b16c9d2d7e5db0d6 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Fri, 28 Jul 2023 10:24:28 +0100 Subject: [PATCH] Update `SecureBackupPanel` to use `getCrypto()` (#11322) `MatrixClient.crypto` is going away, so let's switch over to `getCrypto()`. There doesn't seem to be anything else relying on the `crypto` stub in `mockClientMethodsCrypto()`, so let's get rid of that. --- .../views/settings/SecureBackupPanel.tsx | 2 +- .../views/settings/SecureBackupPanel-test.tsx | 16 +++++++--------- test/test-utils/client.ts | 6 ++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/views/settings/SecureBackupPanel.tsx b/src/components/views/settings/SecureBackupPanel.tsx index d595de80e0..2f866aa183 100644 --- a/src/components/views/settings/SecureBackupPanel.tsx +++ b/src/components/views/settings/SecureBackupPanel.tsx @@ -146,7 +146,7 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> { private async getUpdatedDiagnostics(): Promise { const cli = MatrixClientPeg.safeGet(); - const crypto = cli.crypto; + const crypto = cli.getCrypto(); if (!crypto) return; const secretStorage = cli.secretStorage; diff --git a/test/components/views/settings/SecureBackupPanel-test.tsx b/test/components/views/settings/SecureBackupPanel-test.tsx index a59e76ff32..47d5d5c5c4 100644 --- a/test/components/views/settings/SecureBackupPanel-test.tsx +++ b/test/components/views/settings/SecureBackupPanel-test.tsx @@ -18,7 +18,12 @@ import React from "react"; import { fireEvent, render, screen, within } from "@testing-library/react"; import { mocked } from "jest-mock"; -import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../test-utils"; +import { + flushPromises, + getMockClientWithEventEmitter, + mockClientMethodsCrypto, + mockClientMethodsUser, +} from "../../../test-utils"; import SecureBackupPanel from "../../../../src/components/views/settings/SecureBackupPanel"; import { accessSecretStorage } from "../../../../src/SecurityManager"; @@ -30,20 +35,13 @@ describe("", () => { const userId = "@alice:server.org"; const client = getMockClientWithEventEmitter({ ...mockClientMethodsUser(userId), - checkKeyBackup: jest.fn(), - isKeyBackupKeyStored: jest.fn(), + ...mockClientMethodsCrypto(), getKeyBackupEnabled: jest.fn(), getKeyBackupVersion: jest.fn().mockReturnValue("1"), isKeyBackupTrusted: jest.fn().mockResolvedValue(true), getClientWellKnown: jest.fn(), deleteKeyBackupVersion: jest.fn(), - secretStorage: { hasKey: jest.fn() }, }); - // @ts-ignore allow it - client.crypto = { - getSessionBackupPrivateKey: jest.fn(), - isSecretStorageReady: jest.fn(), - } as unknown as Crypto; const getComponent = () => render(); diff --git a/test/test-utils/client.ts b/test/test-utils/client.ts index 056f18eee3..80bf9849ce 100644 --- a/test/test-utils/client.ts +++ b/test/test-utils/client.ts @@ -155,10 +155,6 @@ export const mockClientMethodsCrypto = (): Partial< getStoredCrossSigningForUser: jest.fn(), checkKeyBackup: jest.fn().mockReturnValue({}), secretStorage: { hasKey: jest.fn() }, - crypto: { - isSecretStorageReady: jest.fn(), - getSessionBackupPrivateKey: jest.fn(), - }, getCrypto: jest.fn().mockReturnValue({ getUserDeviceInfo: jest.fn(), getCrossSigningStatus: jest.fn().mockResolvedValue({ @@ -171,5 +167,7 @@ export const mockClientMethodsCrypto = (): Partial< }, }), isCrossSigningReady: jest.fn().mockResolvedValue(true), + isSecretStorageReady: jest.fn(), + getSessionBackupPrivateKey: jest.fn(), }), });