2020-02-11 14:59:49 +03: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';
|
|
|
|
|
|
|
|
const AccessSecretStorageDialog = sdk.getComponent("dialogs.secretstorage.AccessSecretStorageDialog");
|
|
|
|
|
2020-02-11 15:06:40 +03:00
|
|
|
describe("AccessSecretStorageDialog", function() {
|
2020-02-11 14:59:49 +03:00
|
|
|
it("Closes the dialog if _onRecoveryKeyNext is called with a valid key", (done) => {
|
|
|
|
const testInstance = TestRenderer.create(
|
|
|
|
<AccessSecretStorageDialog
|
|
|
|
checkPrivateKey={(p) => p && p.recoveryKey && p.recoveryKey == "a"}
|
|
|
|
onFinished={(v) => {
|
2020-02-11 15:06:40 +03:00
|
|
|
if (v) { done(); }
|
2020-02-11 14:59:49 +03:00
|
|
|
}}
|
2020-02-11 15:06:40 +03:00
|
|
|
/>,
|
2020-02-11 14:59:49 +03:00
|
|
|
);
|
|
|
|
testInstance.getInstance().setState({
|
|
|
|
recoveryKeyValid: true,
|
|
|
|
recoveryKey: "a",
|
|
|
|
});
|
2020-02-11 15:06:40 +03:00
|
|
|
const e = { preventDefault: () => {} };
|
2020-02-11 14:59:49 +03:00
|
|
|
testInstance.getInstance()._onRecoveryKeyNext(e);
|
|
|
|
});
|
|
|
|
|
2020-02-11 15:06:40 +03:00
|
|
|
it("Considers a valid key to be valid", function() {
|
2020-02-11 14:59:49 +03:00
|
|
|
const testInstance = TestRenderer.create(
|
|
|
|
<AccessSecretStorageDialog
|
|
|
|
checkPrivateKey={() => true}
|
2020-02-11 15:06:40 +03:00
|
|
|
/>,
|
2020-02-11 14:59:49 +03:00
|
|
|
);
|
|
|
|
const v = "asfd";
|
|
|
|
const e = { target: { value: v } };
|
|
|
|
stubClient();
|
2020-02-11 15:06:40 +03:00
|
|
|
MatrixClientPeg.get().isValidRecoveryKey = function(k) {
|
2020-02-11 14:59:49 +03:00
|
|
|
return k == v;
|
2020-02-11 15:06:40 +03:00
|
|
|
};
|
2020-02-11 14:59:49 +03:00
|
|
|
testInstance.getInstance()._onRecoveryKeyChange(e);
|
|
|
|
const { recoveryKeyValid } = testInstance.getInstance().state;
|
|
|
|
expect(recoveryKeyValid).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-02-11 15:06:40 +03:00
|
|
|
it("Notifies the user if they input an invalid recovery key", async function(done) {
|
2020-02-11 14:59:49 +03:00
|
|
|
const testInstance = TestRenderer.create(
|
|
|
|
<AccessSecretStorageDialog
|
|
|
|
checkPrivateKey={async () => false}
|
2020-02-11 15:06:40 +03:00
|
|
|
/>,
|
2020-02-11 14:59:49 +03:00
|
|
|
);
|
|
|
|
const e = { target: { value: "a" } };
|
|
|
|
stubClient();
|
|
|
|
MatrixClientPeg.get().isValidRecoveryKey = () => true;
|
|
|
|
testInstance.getInstance()._onRecoveryKeyChange(e);
|
|
|
|
await testInstance.getInstance()._onRecoveryKeyNext({ preventDefault: () => {} });
|
|
|
|
const { keyMatches } = testInstance.getInstance().state;
|
|
|
|
expect(keyMatches).toBe(false);
|
|
|
|
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 " +
|
|
|
|
"entered the correct recovery key."]);
|
2020-02-11 15:06:40 +03:00
|
|
|
done();
|
2020-02-11 14:59:49 +03:00
|
|
|
});
|
|
|
|
|
2020-02-11 15:06:40 +03:00
|
|
|
it("Notifies the user if they input an invalid passphrase", async function(done) {
|
2020-02-11 14:59:49 +03:00
|
|
|
const testInstance = TestRenderer.create(
|
|
|
|
<AccessSecretStorageDialog
|
|
|
|
checkPrivateKey={() => false}
|
|
|
|
onFinished={() => {}}
|
|
|
|
keyInfo={ { passphrase: {
|
|
|
|
salt: 'nonempty',
|
|
|
|
iterations: 2,
|
|
|
|
} } }
|
2020-02-11 15:06:40 +03:00
|
|
|
/>,
|
2020-02-11 14:59:49 +03:00
|
|
|
);
|
|
|
|
const e = { target: { value: "a" } };
|
|
|
|
stubClient();
|
|
|
|
MatrixClientPeg.get().isValidRecoveryKey = () => false;
|
|
|
|
testInstance.getInstance()._onPassPhraseChange(e);
|
2020-02-11 15:06:40 +03:00
|
|
|
await testInstance.getInstance()._onPassPhraseNext({ preventDefault: () => {} });
|
2020-02-11 14:59:49 +03: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 " +
|
2020-04-16 16:09:41 +03:00
|
|
|
"entered the correct recovery passphrase."]);
|
2020-02-11 14:59:49 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|