Fix tests

pull/21833/head
David Baker 2020-06-26 20:25:38 +01:00
parent 916f606872
commit 0579c9f748
2 changed files with 20 additions and 16 deletions

View File

@ -23,7 +23,6 @@ import * as sdk from '../../../../index';
import {MatrixClientPeg} from '../../../../MatrixClientPeg';
import Field from '../../elements/Field';
import AccessibleButton from '../../elements/AccessibleButton';
import { decodeRecoveryKey } from 'matrix-js-sdk/src/crypto/recoverykey';
import { _t } from '../../../../languageHandler';
@ -86,8 +85,9 @@ export default class AccessSecretStorageDialog extends React.PureComponent {
}
try {
const decodedKey = decodeRecoveryKey(this.state.recoveryKey);
const correct = await MatrixClientPeg.get().checkSecretStorageKey(
const cli = MatrixClientPeg.get();
const decodedKey = cli.keyBackupKeyFromRecoveryKey(this.state.recoveryKey);
const correct = await cli.checkSecretStorageKey(
decodedKey, this.props.keyInfo,
);
this.setState({

View File

@ -40,19 +40,20 @@ describe("AccessSecretStorageDialog", function() {
testInstance.getInstance()._onRecoveryKeyNext(e);
});
it("Considers a valid key to be valid", function() {
it("Considers a valid key to be valid", async function() {
const testInstance = TestRenderer.create(
<AccessSecretStorageDialog
checkPrivateKey={() => true}
/>,
);
const v = "asfd";
const v = "asdf";
const e = { target: { value: v } };
stubClient();
MatrixClientPeg.get().isValidRecoveryKey = function(k) {
return k == v;
};
MatrixClientPeg.get().keyBackupKeyFromRecoveryKey = () => 'a raw key';
MatrixClientPeg.get().checkSecretStorageKey = () => true;
testInstance.getInstance()._onRecoveryKeyChange(e);
// force a validation now because it debounces
await testInstance.getInstance()._validateRecoveryKey();
const { recoveryKeyValid } = testInstance.getInstance().state;
expect(recoveryKeyValid).toBe(true);
});
@ -65,17 +66,20 @@ describe("AccessSecretStorageDialog", function() {
);
const e = { target: { value: "a" } };
stubClient();
MatrixClientPeg.get().isValidRecoveryKey = () => true;
MatrixClientPeg.get().keyBackupKeyFromRecoveryKey = () => {
throw new Error("that's no key");
};
testInstance.getInstance()._onRecoveryKeyChange(e);
await testInstance.getInstance()._onRecoveryKeyNext({ preventDefault: () => {} });
const { keyMatches } = testInstance.getInstance().state;
expect(keyMatches).toBe(false);
// force a validation now because it debounces
await testInstance.getInstance()._validateRecoveryKey();
const { recoveryKeyValid, recoveryKeyCorrect } = testInstance.getInstance().state;
expect(recoveryKeyValid).toBe(false);
expect(recoveryKeyCorrect).toBe(false);
const notification = testInstance.root.findByProps({
className: "mx_AccessSecretStorageDialog_keyStatus",
className: "mx_AccessSecretStorageDialog_recoveryKeyFeedback mx_AccessSecretStorageDialog_recoveryKeyFeedback_invalid",
});
expect(notification.props.children).toEqual(
["\uD83D\uDC4E ", "Unable to access secret storage. Please verify that you " +
"entered the correct recovery key."]);
expect(notification.props.children).toEqual("Invalid Recovery Key");
done();
});