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

View File

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