Skip to content

Commit 0579c9f

Browse files
committed
Fix tests
1 parent 916f606 commit 0579c9f

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/components/views/dialogs/secretstorage/AccessSecretStorageDialog.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import * as sdk from '../../../../index';
2323
import {MatrixClientPeg} from '../../../../MatrixClientPeg';
2424
import Field from '../../elements/Field';
2525
import AccessibleButton from '../../elements/AccessibleButton';
26-
import { decodeRecoveryKey } from 'matrix-js-sdk/src/crypto/recoverykey';
2726

2827
import { _t } from '../../../../languageHandler';
2928

@@ -86,8 +85,9 @@ export default class AccessSecretStorageDialog extends React.PureComponent {
8685
}
8786

8887
try {
89-
const decodedKey = decodeRecoveryKey(this.state.recoveryKey);
90-
const correct = await MatrixClientPeg.get().checkSecretStorageKey(
88+
const cli = MatrixClientPeg.get();
89+
const decodedKey = cli.keyBackupKeyFromRecoveryKey(this.state.recoveryKey);
90+
const correct = await cli.checkSecretStorageKey(
9191
decodedKey, this.props.keyInfo,
9292
);
9393
this.setState({

test/components/views/dialogs/AccessSecretStorageDialog-test.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,20 @@ describe("AccessSecretStorageDialog", function() {
4040
testInstance.getInstance()._onRecoveryKeyNext(e);
4141
});
4242

43-
it("Considers a valid key to be valid", function() {
43+
it("Considers a valid key to be valid", async function() {
4444
const testInstance = TestRenderer.create(
4545
<AccessSecretStorageDialog
4646
checkPrivateKey={() => true}
4747
/>,
4848
);
49-
const v = "asfd";
49+
const v = "asdf";
5050
const e = { target: { value: v } };
5151
stubClient();
52-
MatrixClientPeg.get().isValidRecoveryKey = function(k) {
53-
return k == v;
54-
};
52+
MatrixClientPeg.get().keyBackupKeyFromRecoveryKey = () => 'a raw key';
53+
MatrixClientPeg.get().checkSecretStorageKey = () => true;
5554
testInstance.getInstance()._onRecoveryKeyChange(e);
55+
// force a validation now because it debounces
56+
await testInstance.getInstance()._validateRecoveryKey();
5657
const { recoveryKeyValid } = testInstance.getInstance().state;
5758
expect(recoveryKeyValid).toBe(true);
5859
});
@@ -65,17 +66,20 @@ describe("AccessSecretStorageDialog", function() {
6566
);
6667
const e = { target: { value: "a" } };
6768
stubClient();
68-
MatrixClientPeg.get().isValidRecoveryKey = () => true;
69+
MatrixClientPeg.get().keyBackupKeyFromRecoveryKey = () => {
70+
throw new Error("that's no key");
71+
};
6972
testInstance.getInstance()._onRecoveryKeyChange(e);
70-
await testInstance.getInstance()._onRecoveryKeyNext({ preventDefault: () => {} });
71-
const { keyMatches } = testInstance.getInstance().state;
72-
expect(keyMatches).toBe(false);
73+
// force a validation now because it debounces
74+
await testInstance.getInstance()._validateRecoveryKey();
75+
76+
const { recoveryKeyValid, recoveryKeyCorrect } = testInstance.getInstance().state;
77+
expect(recoveryKeyValid).toBe(false);
78+
expect(recoveryKeyCorrect).toBe(false);
7379
const notification = testInstance.root.findByProps({
74-
className: "mx_AccessSecretStorageDialog_keyStatus",
80+
className: "mx_AccessSecretStorageDialog_recoveryKeyFeedback mx_AccessSecretStorageDialog_recoveryKeyFeedback_invalid",
7581
});
76-
expect(notification.props.children).toEqual(
77-
["\uD83D\uDC4E ", "Unable to access secret storage. Please verify that you " +
78-
"entered the correct recovery key."]);
82+
expect(notification.props.children).toEqual("Invalid Recovery Key");
7983
done();
8084
});
8185

0 commit comments

Comments
 (0)