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

Commit

Permalink
Replace MatrixClient.isValidRecoveryKey by local check with `decode…
Browse files Browse the repository at this point in the history
…RecoveryKey`
  • Loading branch information
florianduros committed Sep 18, 2024
1 parent e7032e4 commit af75479
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/components/views/dialogs/security/RestoreKeyBackupDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,24 @@ export default class RestoreKeyBackupDialog extends React.PureComponent<IProps,
accessSecretStorage(async (): Promise<void> => {}, /* forceReset = */ true);
};

/**
* Check if the recovery key is valid
* @param recoveryKey
* @private
*/
private isValidRecoveryKey(recoveryKey: string): boolean {
try {
decodeRecoveryKey(recoveryKey);
return true;
} catch (e) {
return false;
}
}

private onRecoveryKeyChange = (e: ChangeEvent<HTMLInputElement>): void => {
this.setState({
recoveryKey: e.target.value,
recoveryKeyValid: MatrixClientPeg.safeGet().isValidRecoveryKey(e.target.value),
recoveryKeyValid: this.isValidRecoveryKey(e.target.value),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ describe("AccessSecretStorageDialog", () => {
beforeEach(() => {
mockClient = getMockClientWithEventEmitter({
checkSecretStorageKey: jest.fn(),
isValidRecoveryKey: jest.fn(),
});
});

it("Closes the dialog when the form is submitted with a valid key", async () => {
mockClient.checkSecretStorageKey.mockResolvedValue(true);
mockClient.isValidRecoveryKey.mockReturnValue(true);

const onFinished = jest.fn();
const checkPrivateKey = jest.fn().mockResolvedValue(true);
Expand Down Expand Up @@ -114,7 +112,6 @@ describe("AccessSecretStorageDialog", () => {
};
const checkPrivateKey = jest.fn().mockResolvedValue(false);
renderComponent({ checkPrivateKey, keyInfo });
mockClient.isValidRecoveryKey.mockReturnValue(false);

await enterSecurityKey("Security Phrase");
expect(screen.getByPlaceholderText("Security Phrase")).toHaveValue(securityKey);
Expand Down

0 comments on commit af75479

Please sign in to comment.