Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Update SecureBackupPanel to use getCrypto() (#11322)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
richvdh authored Jul 28, 2023
1 parent b284fbc commit ddb8e0a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/components/views/settings/SecureBackupPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {

private async getUpdatedDiagnostics(): Promise<void> {
const cli = MatrixClientPeg.safeGet();
const crypto = cli.crypto;
const crypto = cli.getCrypto();
if (!crypto) return;

const secretStorage = cli.secretStorage;
Expand Down
16 changes: 7 additions & 9 deletions test/components/views/settings/SecureBackupPanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -30,20 +35,13 @@ describe("<SecureBackupPanel />", () => {
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(<SecureBackupPanel />);

Expand Down
6 changes: 2 additions & 4 deletions test/test-utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -171,5 +167,7 @@ export const mockClientMethodsCrypto = (): Partial<
},
}),
isCrossSigningReady: jest.fn().mockResolvedValue(true),
isSecretStorageReady: jest.fn(),
getSessionBackupPrivateKey: jest.fn(),
}),
});

0 comments on commit ddb8e0a

Please sign in to comment.