Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 3bc0439

Browse files
authored
Replace MatrixClient.checkSecretStorageKey by MatrixClient.SecretStorage.checkKey (#142)
1 parent 03186e4 commit 3bc0439

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

src/SecurityManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async function getSecretStorageKey({
121121
keyInfo,
122122
checkPrivateKey: async (input: KeyParams): Promise<boolean> => {
123123
const key = await inputToKey(input);
124-
return MatrixClientPeg.safeGet().checkSecretStorageKey(key, keyInfo);
124+
return MatrixClientPeg.safeGet().secretStorage.checkKey(key, keyInfo);
125125
},
126126
},
127127
/* className= */ undefined,

src/components/views/dialogs/security/AccessSecretStorageDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export default class AccessSecretStorageDialog extends React.PureComponent<IProp
102102
try {
103103
const cli = MatrixClientPeg.safeGet();
104104
const decodedKey = decodeRecoveryKey(this.state.recoveryKey);
105-
const correct = await cli.checkSecretStorageKey(decodedKey, this.props.keyInfo);
105+
const correct = await cli.secretStorage.checkKey(decodedKey, this.props.keyInfo);
106106
this.setState({
107107
recoveryKeyValid: true,
108108
recoveryKeyCorrect: correct,

test/components/views/dialogs/AccessSecretStorageDialog-test.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import React, { ComponentProps } from "react";
1010
import { SecretStorage, MatrixClient } from "matrix-js-sdk/src/matrix";
1111
import { act, fireEvent, render, screen } from "@testing-library/react";
1212
import userEvent from "@testing-library/user-event";
13-
import { Mocked } from "jest-mock";
1413

15-
import { getMockClientWithEventEmitter, mockPlatformPeg } from "../../../test-utils";
14+
import { mockPlatformPeg, stubClient } from "../../../test-utils";
1615
import AccessSecretStorageDialog from "../../../../src/components/views/dialogs/security/AccessSecretStorageDialog";
1716

1817
const securityKey = "EsTc WKmb ivvk jLS7 Y1NH 5CcQ mP1E JJwj B3Fd pFWm t4Dp dbyu";
1918

2019
describe("AccessSecretStorageDialog", () => {
21-
let mockClient: Mocked<MatrixClient>;
20+
let mockClient: MatrixClient;
2221

2322
const defaultProps: ComponentProps<typeof AccessSecretStorageDialog> = {
2423
keyInfo: {} as any,
@@ -57,13 +56,11 @@ describe("AccessSecretStorageDialog", () => {
5756
});
5857

5958
beforeEach(() => {
60-
mockClient = getMockClientWithEventEmitter({
61-
checkSecretStorageKey: jest.fn(),
62-
});
59+
mockClient = stubClient();
6360
});
6461

6562
it("Closes the dialog when the form is submitted with a valid key", async () => {
66-
mockClient.checkSecretStorageKey.mockResolvedValue(true);
63+
jest.spyOn(mockClient.secretStorage, "checkKey").mockResolvedValue(true);
6764

6865
const onFinished = jest.fn();
6966
const checkPrivateKey = jest.fn().mockResolvedValue(true);
@@ -85,7 +82,7 @@ describe("AccessSecretStorageDialog", () => {
8582
const checkPrivateKey = jest.fn().mockResolvedValue(true);
8683
renderComponent({ onFinished, checkPrivateKey });
8784

88-
mockClient.checkSecretStorageKey.mockImplementation(() => {
85+
jest.spyOn(mockClient.secretStorage, "checkKey").mockImplementation(() => {
8986
throw new Error("invalid key");
9087
});
9188

test/test-utils/test-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export function createTestClient(): MatrixClient {
109109
secretStorage: {
110110
get: jest.fn(),
111111
isStored: jest.fn().mockReturnValue(false),
112+
checkKey: jest.fn().mockResolvedValue(false),
112113
},
113114

114115
store: {

0 commit comments

Comments
 (0)