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

Commit

Permalink
Remove deprecated calls to hasSecretStorageKey
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed Jan 8, 2024
1 parent 9abb2d9 commit 8464448
Show file tree
Hide file tree
Showing 6 changed files with 9 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 @@ -350,7 +350,7 @@ export async function accessSecretStorage(func = async (): Promise<void> => {},
async function doAccessSecretStorage(func: () => Promise<void>, forceReset: boolean): Promise<void> {
try {
const cli = MatrixClientPeg.safeGet();
if (!(await cli.hasSecretStorageKey()) || forceReset) {
if (!(await cli.secretStorage.hasKey()) || forceReset) {
// This dialog calls bootstrap itself after guiding the user through
// passphrase creation.
const { finished } = Modal.createDialogAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class CreateKeyBackupDialog extends React.PureComponent<IProps, I
const cli = MatrixClientPeg.safeGet();
try {
// Check if 4S already set up
const secretStorageAlreadySetup = await cli.hasSecretStorageKey();
const secretStorageAlreadySetup = await cli.secretStorage.hasKey();

if (!secretStorageAlreadySetup) {
// bootstrap secret storage, that will also create a backup version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export default class RestoreKeyBackupDialog extends React.PureComponent<IProps,
try {
const cli = MatrixClientPeg.safeGet();
const backupInfo = await cli.getKeyBackupVersion();
const has4S = await cli.hasSecretStorageKey();
const has4S = await cli.secretStorage.hasKey();
const backupKeyStored = has4S ? await cli.isKeyBackupKeyStored() : null;
this.setState({
backupInfo,
Expand Down
4 changes: 2 additions & 2 deletions test/SecurityManager-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("SecurityManager", () => {
bootstrapSecretStorage: () => {},
} as unknown as CryptoApi;
const client = stubClient();
mocked(client.hasSecretStorageKey).mockResolvedValue(true);
mocked(client.secretStorage.hasKey).mockResolvedValue(true);
mocked(client.getCrypto).mockReturnValue(crypto);

// When I run accessSecretStorage
Expand All @@ -48,7 +48,7 @@ describe("SecurityManager", () => {
it("throws if crypto is unavailable", async () => {
// Given a client with no crypto
const client = stubClient();
mocked(client.hasSecretStorageKey).mockResolvedValue(true);
mocked(client.secretStorage.hasKey).mockResolvedValue(true);
mocked(client.getCrypto).mockReturnValue(undefined);

// When I run accessSecretStorage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("CreateKeyBackupDialog", () => {

it("should display an error message when backup creation failed", async () => {
const matrixClient = createTestClient();
mocked(matrixClient.hasSecretStorageKey).mockResolvedValue(true);
mocked(matrixClient.secretStorage.hasKey).mockResolvedValue(true);
mocked(matrixClient.getCrypto()!.resetKeyBackup).mockImplementation(() => {
throw new Error("failed");
});
Expand All @@ -57,7 +57,7 @@ describe("CreateKeyBackupDialog", () => {

it("should display an error message when there is no Crypto available", async () => {
const matrixClient = createTestClient();
mocked(matrixClient.hasSecretStorageKey).mockResolvedValue(true);
mocked(matrixClient.secretStorage.hasKey).mockResolvedValue(true);
mocked(matrixClient.getCrypto).mockReturnValue(undefined);
MatrixClientPeg.safeGet = MatrixClientPeg.get = () => matrixClient;

Expand Down
5 changes: 2 additions & 3 deletions test/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import { MapperOpts } from "matrix-js-sdk/src/event-mapper";
import { MatrixRTCSessionManager } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSessionManager";
// eslint-disable-next-line no-restricted-imports
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
import { ServerSideSecretStorage } from "matrix-js-sdk/src/secret-storage";

import type { GroupCall } from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg as peg } from "../../src/MatrixClientPeg";
Expand Down Expand Up @@ -115,11 +114,11 @@ export function createTestClient(): MatrixClient {
getSessionId: jest.fn().mockReturnValue("iaszphgvfku"),
credentials: { userId: "@userId:matrix.org" },
bootstrapCrossSigning: jest.fn(),
hasSecretStorageKey: jest.fn(),

secretStorage: {
get: jest.fn(),
} as unknown as ServerSideSecretStorage,
hasKey: jest.fn(),
},

store: {
getPendingEvents: jest.fn().mockResolvedValue([]),
Expand Down

0 comments on commit 8464448

Please sign in to comment.