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

Commit

Permalink
Replace MatrixClient.checkSecretStorageKey by `MatrixClient.SecretS…
Browse files Browse the repository at this point in the history
…torage.checkKey`
  • Loading branch information
florianduros committed Oct 10, 2024
1 parent c71dc6b commit f005dcb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/SecurityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 5 additions & 8 deletions test/components/views/dialogs/AccessSecretStorageDialog-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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");
});

Expand Down
1 change: 1 addition & 0 deletions test/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export function createTestClient(): MatrixClient {
secretStorage: {
get: jest.fn(),
isStored: jest.fn().mockReturnValue(false),
checkKey: jest.fn().mockResolvedValue(false),
},

store: {
Expand Down

0 comments on commit f005dcb

Please sign in to comment.