2020-02-11 11:59:49 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import TestRenderer from 'react-test-renderer';
|
|
|
|
import sdk from '../../../skinned-sdk';
|
|
|
|
import {MatrixClientPeg} from '../../../../src/MatrixClientPeg';
|
|
|
|
import { stubClient } from '../../../test-utils';
|
|
|
|
|
2020-09-10 12:56:07 +00:00
|
|
|
const AccessSecretStorageDialog = sdk.getComponent("dialogs.security.AccessSecretStorageDialog");
|
2020-02-11 11:59:49 +00:00
|
|
|
|
2020-02-11 12:06:40 +00:00
|
|
|
describe("AccessSecretStorageDialog", function() {
|
2020-02-11 11:59:49 +00:00
|
|
|
it("Closes the dialog if _onRecoveryKeyNext is called with a valid key", (done) => {
|
|
|
|
const testInstance = TestRenderer.create(
|
|
|
|
<AccessSecretStorageDialog
|
2021-04-27 15:23:27 +00:00
|
|
|
checkPrivateKey={(p) => p && p.recoveryKey && p.recoveryKey == "a"}
|
|
|
|
onFinished={(v) => {
|
|
|
|
if (v) { done(); }
|
2020-02-11 11:59:49 +00:00
|
|
|
}}
|
2020-02-11 12:06:40 +00:00
|
|
|
/>,
|
2020-02-11 11:59:49 +00:00
|
|
|
);
|
|
|
|
testInstance.getInstance().setState({
|
|
|
|
recoveryKeyValid: true,
|
|
|
|
recoveryKey: "a",
|
|
|
|
});
|
2020-02-11 12:06:40 +00:00
|
|
|
const e = { preventDefault: () => {} };
|
2021-03-26 05:47:41 +00:00
|
|
|
testInstance.getInstance().onRecoveryKeyNext(e);
|
2020-02-11 11:59:49 +00:00
|
|
|
});
|
|
|
|
|
2020-06-26 19:25:38 +00:00
|
|
|
it("Considers a valid key to be valid", async function() {
|
2020-02-11 11:59:49 +00:00
|
|
|
const testInstance = TestRenderer.create(
|
|
|
|
<AccessSecretStorageDialog
|
2021-04-27 15:23:27 +00:00
|
|
|
checkPrivateKey={() => true}
|
2020-02-11 12:06:40 +00:00
|
|
|
/>,
|
2020-02-11 11:59:49 +00:00
|
|
|
);
|
2020-06-26 19:25:38 +00:00
|
|
|
const v = "asdf";
|
2020-02-11 11:59:49 +00:00
|
|
|
const e = { target: { value: v } };
|
|
|
|
stubClient();
|
2020-06-26 19:25:38 +00:00
|
|
|
MatrixClientPeg.get().keyBackupKeyFromRecoveryKey = () => 'a raw key';
|
|
|
|
MatrixClientPeg.get().checkSecretStorageKey = () => true;
|
2021-03-26 05:47:41 +00:00
|
|
|
testInstance.getInstance().onRecoveryKeyChange(e);
|
2020-06-26 19:25:38 +00:00
|
|
|
// force a validation now because it debounces
|
2021-03-26 05:47:41 +00:00
|
|
|
await testInstance.getInstance().validateRecoveryKey();
|
2020-02-11 11:59:49 +00:00
|
|
|
const { recoveryKeyValid } = testInstance.getInstance().state;
|
|
|
|
expect(recoveryKeyValid).toBe(true);
|
|
|
|
});
|
|
|
|
|
2021-01-05 01:17:12 +00:00
|
|
|
it("Notifies the user if they input an invalid Security Key", async function(done) {
|
2020-02-11 11:59:49 +00:00
|
|
|
const testInstance = TestRenderer.create(
|
|
|
|
<AccessSecretStorageDialog
|
2021-04-27 15:23:27 +00:00
|
|
|
checkPrivateKey={async () => false}
|
2020-02-11 12:06:40 +00:00
|
|
|
/>,
|
2020-02-11 11:59:49 +00:00
|
|
|
);
|
|
|
|
const e = { target: { value: "a" } };
|
|
|
|
stubClient();
|
2020-06-26 19:25:38 +00:00
|
|
|
MatrixClientPeg.get().keyBackupKeyFromRecoveryKey = () => {
|
|
|
|
throw new Error("that's no key");
|
|
|
|
};
|
2021-03-26 05:47:41 +00:00
|
|
|
testInstance.getInstance().onRecoveryKeyChange(e);
|
2020-06-26 19:25:38 +00:00
|
|
|
// force a validation now because it debounces
|
2021-03-26 05:47:41 +00:00
|
|
|
await testInstance.getInstance().validateRecoveryKey();
|
2020-06-26 19:25:38 +00:00
|
|
|
|
|
|
|
const { recoveryKeyValid, recoveryKeyCorrect } = testInstance.getInstance().state;
|
|
|
|
expect(recoveryKeyValid).toBe(false);
|
|
|
|
expect(recoveryKeyCorrect).toBe(false);
|
2020-02-11 11:59:49 +00:00
|
|
|
const notification = testInstance.root.findByProps({
|
2020-06-26 19:31:22 +00:00
|
|
|
className: "mx_AccessSecretStorageDialog_recoveryKeyFeedback " +
|
|
|
|
"mx_AccessSecretStorageDialog_recoveryKeyFeedback_invalid",
|
2020-02-11 11:59:49 +00:00
|
|
|
});
|
2021-01-05 01:17:12 +00:00
|
|
|
expect(notification.props.children).toEqual("Invalid Security Key");
|
2020-02-11 12:06:40 +00:00
|
|
|
done();
|
2020-02-11 11:59:49 +00:00
|
|
|
});
|
|
|
|
|
2020-02-11 12:06:40 +00:00
|
|
|
it("Notifies the user if they input an invalid passphrase", async function(done) {
|
2020-02-11 11:59:49 +00:00
|
|
|
const testInstance = TestRenderer.create(
|
|
|
|
<AccessSecretStorageDialog
|
2021-04-27 15:23:27 +00:00
|
|
|
checkPrivateKey={() => false}
|
|
|
|
onFinished={() => {}}
|
|
|
|
keyInfo={{
|
|
|
|
passphrase: {
|
|
|
|
salt: 'nonempty',
|
|
|
|
iterations: 2,
|
|
|
|
},
|
|
|
|
}}
|
2020-02-11 12:06:40 +00:00
|
|
|
/>,
|
2020-02-11 11:59:49 +00:00
|
|
|
);
|
|
|
|
const e = { target: { value: "a" } };
|
|
|
|
stubClient();
|
|
|
|
MatrixClientPeg.get().isValidRecoveryKey = () => false;
|
2021-03-26 05:47:41 +00:00
|
|
|
testInstance.getInstance().onPassPhraseChange(e);
|
|
|
|
await testInstance.getInstance().onPassPhraseNext({ preventDefault: () => {} });
|
2020-02-11 11:59:49 +00:00
|
|
|
const notification = testInstance.root.findByProps({
|
|
|
|
className: "mx_AccessSecretStorageDialog_keyStatus",
|
|
|
|
});
|
|
|
|
expect(notification.props.children).toEqual(
|
|
|
|
["\uD83D\uDC4E ", "Unable to access secret storage. Please verify that you " +
|
2021-01-05 01:17:12 +00:00
|
|
|
"entered the correct Security Phrase."]);
|
2020-02-11 11:59:49 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|