Replace MatrixClient.checkSecretStorageKey
by MatrixClient.SecretStorage.checkKey
(#142)
This commit is contained in:
parent
03186e4a4d
commit
3bc0439fd2
4 changed files with 8 additions and 10 deletions
|
@ -121,7 +121,7 @@ async function getSecretStorageKey({
|
||||||
keyInfo,
|
keyInfo,
|
||||||
checkPrivateKey: async (input: KeyParams): Promise<boolean> => {
|
checkPrivateKey: async (input: KeyParams): Promise<boolean> => {
|
||||||
const key = await inputToKey(input);
|
const key = await inputToKey(input);
|
||||||
return MatrixClientPeg.safeGet().checkSecretStorageKey(key, keyInfo);
|
return MatrixClientPeg.safeGet().secretStorage.checkKey(key, keyInfo);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/* className= */ undefined,
|
/* className= */ undefined,
|
||||||
|
|
|
@ -102,7 +102,7 @@ export default class AccessSecretStorageDialog extends React.PureComponent<IProp
|
||||||
try {
|
try {
|
||||||
const cli = MatrixClientPeg.safeGet();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const decodedKey = decodeRecoveryKey(this.state.recoveryKey);
|
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({
|
this.setState({
|
||||||
recoveryKeyValid: true,
|
recoveryKeyValid: true,
|
||||||
recoveryKeyCorrect: correct,
|
recoveryKeyCorrect: correct,
|
||||||
|
|
|
@ -10,15 +10,14 @@ import React, { ComponentProps } from "react";
|
||||||
import { SecretStorage, MatrixClient } from "matrix-js-sdk/src/matrix";
|
import { SecretStorage, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
import { act, fireEvent, render, screen } from "@testing-library/react";
|
import { act, fireEvent, render, screen } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
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";
|
import AccessSecretStorageDialog from "../../../../src/components/views/dialogs/security/AccessSecretStorageDialog";
|
||||||
|
|
||||||
const securityKey = "EsTc WKmb ivvk jLS7 Y1NH 5CcQ mP1E JJwj B3Fd pFWm t4Dp dbyu";
|
const securityKey = "EsTc WKmb ivvk jLS7 Y1NH 5CcQ mP1E JJwj B3Fd pFWm t4Dp dbyu";
|
||||||
|
|
||||||
describe("AccessSecretStorageDialog", () => {
|
describe("AccessSecretStorageDialog", () => {
|
||||||
let mockClient: Mocked<MatrixClient>;
|
let mockClient: MatrixClient;
|
||||||
|
|
||||||
const defaultProps: ComponentProps<typeof AccessSecretStorageDialog> = {
|
const defaultProps: ComponentProps<typeof AccessSecretStorageDialog> = {
|
||||||
keyInfo: {} as any,
|
keyInfo: {} as any,
|
||||||
|
@ -57,13 +56,11 @@ describe("AccessSecretStorageDialog", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockClient = getMockClientWithEventEmitter({
|
mockClient = stubClient();
|
||||||
checkSecretStorageKey: jest.fn(),
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Closes the dialog when the form is submitted with a valid key", async () => {
|
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 onFinished = jest.fn();
|
||||||
const checkPrivateKey = jest.fn().mockResolvedValue(true);
|
const checkPrivateKey = jest.fn().mockResolvedValue(true);
|
||||||
|
@ -85,7 +82,7 @@ describe("AccessSecretStorageDialog", () => {
|
||||||
const checkPrivateKey = jest.fn().mockResolvedValue(true);
|
const checkPrivateKey = jest.fn().mockResolvedValue(true);
|
||||||
renderComponent({ onFinished, checkPrivateKey });
|
renderComponent({ onFinished, checkPrivateKey });
|
||||||
|
|
||||||
mockClient.checkSecretStorageKey.mockImplementation(() => {
|
jest.spyOn(mockClient.secretStorage, "checkKey").mockImplementation(() => {
|
||||||
throw new Error("invalid key");
|
throw new Error("invalid key");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,7 @@ export function createTestClient(): MatrixClient {
|
||||||
secretStorage: {
|
secretStorage: {
|
||||||
get: jest.fn(),
|
get: jest.fn(),
|
||||||
isStored: jest.fn().mockReturnValue(false),
|
isStored: jest.fn().mockReturnValue(false),
|
||||||
|
checkKey: jest.fn().mockResolvedValue(false),
|
||||||
},
|
},
|
||||||
|
|
||||||
store: {
|
store: {
|
||||||
|
|
Loading…
Reference in a new issue