Replace `MatrixClient.checkSecretStorageKey` by `MatrixClient.SecretStorage.checkKey` (#142)

pull/28192/head
Florian Duros 2024-10-14 17:08:42 +02:00 committed by GitHub
parent 03186e4a4d
commit 3bc0439fd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 10 deletions

View File

@ -121,7 +121,7 @@ async function getSecretStorageKey({
keyInfo,
checkPrivateKey: async (input: KeyParams): Promise<boolean> => {
const key = await inputToKey(input);
return MatrixClientPeg.safeGet().checkSecretStorageKey(key, keyInfo);
return MatrixClientPeg.safeGet().secretStorage.checkKey(key, keyInfo);
},
},
/* className= */ undefined,

View File

@ -102,7 +102,7 @@ export default class AccessSecretStorageDialog extends React.PureComponent<IProp
try {
const cli = MatrixClientPeg.safeGet();
const decodedKey = decodeRecoveryKey(this.state.recoveryKey);
const correct = await cli.checkSecretStorageKey(decodedKey, this.props.keyInfo);
const correct = await cli.secretStorage.checkKey(decodedKey, this.props.keyInfo);
this.setState({
recoveryKeyValid: true,
recoveryKeyCorrect: correct,

View File

@ -10,15 +10,14 @@ import React, { ComponentProps } from "react";
import { SecretStorage, MatrixClient } from "matrix-js-sdk/src/matrix";
import { act, fireEvent, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { Mocked } from "jest-mock";
import { getMockClientWithEventEmitter, mockPlatformPeg } from "../../../test-utils";
import { mockPlatformPeg, stubClient } from "../../../test-utils";
import AccessSecretStorageDialog from "../../../../src/components/views/dialogs/security/AccessSecretStorageDialog";
const securityKey = "EsTc WKmb ivvk jLS7 Y1NH 5CcQ mP1E JJwj B3Fd pFWm t4Dp dbyu";
describe("AccessSecretStorageDialog", () => {
let mockClient: Mocked<MatrixClient>;
let mockClient: MatrixClient;
const defaultProps: ComponentProps<typeof AccessSecretStorageDialog> = {
keyInfo: {} as any,
@ -57,13 +56,11 @@ describe("AccessSecretStorageDialog", () => {
});
beforeEach(() => {
mockClient = getMockClientWithEventEmitter({
checkSecretStorageKey: jest.fn(),
});
mockClient = stubClient();
});
it("Closes the dialog when the form is submitted with a valid key", async () => {
mockClient.checkSecretStorageKey.mockResolvedValue(true);
jest.spyOn(mockClient.secretStorage, "checkKey").mockResolvedValue(true);
const onFinished = jest.fn();
const checkPrivateKey = jest.fn().mockResolvedValue(true);
@ -85,7 +82,7 @@ describe("AccessSecretStorageDialog", () => {
const checkPrivateKey = jest.fn().mockResolvedValue(true);
renderComponent({ onFinished, checkPrivateKey });
mockClient.checkSecretStorageKey.mockImplementation(() => {
jest.spyOn(mockClient.secretStorage, "checkKey").mockImplementation(() => {
throw new Error("invalid key");
});

View File

@ -109,6 +109,7 @@ export function createTestClient(): MatrixClient {
secretStorage: {
get: jest.fn(),
isStored: jest.fn().mockReturnValue(false),
checkKey: jest.fn().mockResolvedValue(false),
},
store: {