cozy-keys-lib 3.9.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/WebVaultClient.js +75 -10
- package/src/WebVaultClient.spec.js +23 -0
- package/src/components/VaultContext.jsx +48 -29
- package/src/components/VaultContext.spec.jsx +14 -8
- package/src/components/VaultUnlocker.jsx +9 -8
- package/src/components/defaults.js +12 -6
- package/src/components/defaults.spec.js +34 -0
- package/src/components/vaultUnlockContext.jsx +6 -16
- package/src/components/vaultUnlockContext.spec.jsx +0 -17
- package/src/index.js +1 -0
- package/transpiled/WebVaultClient.js +480 -283
- package/transpiled/WebVaultClient.spec.js +36 -0
- package/transpiled/components/VaultContext.js +55 -28
- package/transpiled/components/VaultContext.spec.js +9 -9
- package/transpiled/components/VaultUnlocker.js +6 -8
- package/transpiled/components/defaults.js +23 -11
- package/transpiled/components/defaults.spec.js +94 -0
- package/transpiled/components/vaultUnlockContext.js +3 -8
- package/transpiled/components/vaultUnlockContext.spec.js +8 -48
- package/transpiled/index.js +2 -1
|
@@ -6,6 +6,7 @@ import { Utils } from './@bitwarden/jslib/misc/utils';
|
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import range from 'lodash/range';
|
|
9
|
+
import { SymmetricCryptoKey } from './@bitwarden/jslib/models/domain/symmetricCryptoKey';
|
|
9
10
|
jest.spyOn(Utils, 'init').mockImplementation(function () {});
|
|
10
11
|
describe('WebVaultClient', function () {
|
|
11
12
|
describe('global instance', function () {
|
|
@@ -373,4 +374,39 @@ describe('WebVaultClient', function () {
|
|
|
373
374
|
}, _callee5);
|
|
374
375
|
})));
|
|
375
376
|
});
|
|
377
|
+
describe('decryptEncryptionKey', function () {
|
|
378
|
+
var client = new WebVaultClient('https://me.cozy.wtf');
|
|
379
|
+
jest.spyOn(client.cryptoService, 'decryptToBytes').mockResolvedValue(new ArrayBuffer(64));
|
|
380
|
+
jest.spyOn(client, 'getEncryptionKey').mockResolvedValue(new SymmetricCryptoKey(new ArrayBuffer(64)));
|
|
381
|
+
afterEach(function () {
|
|
382
|
+
jest.clearAllMocks();
|
|
383
|
+
});
|
|
384
|
+
it('should decrypt the given key with correct length',
|
|
385
|
+
/*#__PURE__*/
|
|
386
|
+
_asyncToGenerator(
|
|
387
|
+
/*#__PURE__*/
|
|
388
|
+
_regeneratorRuntime.mark(function _callee6() {
|
|
389
|
+
var encryptedKey, key;
|
|
390
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
391
|
+
while (1) {
|
|
392
|
+
switch (_context6.prev = _context6.next) {
|
|
393
|
+
case 0:
|
|
394
|
+
encryptedKey = 'xyz';
|
|
395
|
+
_context6.next = 3;
|
|
396
|
+
return client.decryptEncryptionKey(encryptedKey);
|
|
397
|
+
|
|
398
|
+
case 3:
|
|
399
|
+
key = _context6.sent;
|
|
400
|
+
expect(key.key.byteLength).toBe(64);
|
|
401
|
+
expect(key.encType).toBe(2);
|
|
402
|
+
expect(key.encKey.byteLength).toBe(32);
|
|
403
|
+
|
|
404
|
+
case 7:
|
|
405
|
+
case "end":
|
|
406
|
+
return _context6.stop();
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}, _callee6);
|
|
410
|
+
})));
|
|
411
|
+
});
|
|
376
412
|
});
|
|
@@ -29,8 +29,16 @@ function (_React$Component) {
|
|
|
29
29
|
_classCallCheck(this, VaultProvider);
|
|
30
30
|
|
|
31
31
|
_this = _possibleConstructorReturn(this, _getPrototypeOf(VaultProvider).call(this, props));
|
|
32
|
+
var vaultClient = _this.props.vaultClient;
|
|
33
|
+
|
|
34
|
+
if (_this.props.client) {
|
|
35
|
+
vaultClient = _this.props.client; // eslint-disable-next-line no-console
|
|
36
|
+
|
|
37
|
+
console.warn('Passing client in props is deprecated, please use vaultClient instead.');
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
_this.state = {
|
|
33
|
-
|
|
41
|
+
vaultClient: vaultClient,
|
|
34
42
|
locked: true
|
|
35
43
|
};
|
|
36
44
|
_this.updateLockedState = _this.updateLockedState.bind(_assertThisInitialized(_this));
|
|
@@ -41,22 +49,38 @@ function (_React$Component) {
|
|
|
41
49
|
_createClass(VaultProvider, [{
|
|
42
50
|
key: "componentDidMount",
|
|
43
51
|
value: function componentDidMount() {
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
var _this2 = this;
|
|
53
|
+
|
|
54
|
+
var _this$props = this.props,
|
|
55
|
+
cozyClient = _this$props.cozyClient,
|
|
56
|
+
instance = _this$props.instance;
|
|
57
|
+
|
|
58
|
+
if (cozyClient) {
|
|
59
|
+
var uri = cozyClient.getStackClient().uri;
|
|
60
|
+
|
|
61
|
+
if (!uri) {
|
|
62
|
+
cozyClient.on('login', function () {
|
|
63
|
+
_this2.setupClient(cozyClient.getStackClient().uri);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (instance) {
|
|
69
|
+
this.setupClient(this.props.instance);
|
|
46
70
|
}
|
|
47
71
|
}
|
|
48
72
|
}, {
|
|
49
73
|
key: "componentWillUnmount",
|
|
50
74
|
value: function componentWillUnmount() {
|
|
51
|
-
var
|
|
75
|
+
var vaultClient = this.state.vaultClient;
|
|
52
76
|
|
|
53
|
-
if (!
|
|
77
|
+
if (!vaultClient) {
|
|
54
78
|
return;
|
|
55
79
|
}
|
|
56
80
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
81
|
+
vaultClient.removeListener('unlock', this.updateLockedState);
|
|
82
|
+
vaultClient.removeListener('lock', this.updateLockedState);
|
|
83
|
+
vaultClient.removeListener('login', this.updateLockedState);
|
|
60
84
|
}
|
|
61
85
|
}, {
|
|
62
86
|
key: "updateLockedState",
|
|
@@ -64,14 +88,14 @@ function (_React$Component) {
|
|
|
64
88
|
var _updateLockedState = _asyncToGenerator(
|
|
65
89
|
/*#__PURE__*/
|
|
66
90
|
_regeneratorRuntime.mark(function _callee() {
|
|
67
|
-
var
|
|
91
|
+
var vaultClient, locked;
|
|
68
92
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
69
93
|
while (1) {
|
|
70
94
|
switch (_context.prev = _context.next) {
|
|
71
95
|
case 0:
|
|
72
|
-
|
|
96
|
+
vaultClient = this.state.vaultClient;
|
|
73
97
|
_context.next = 3;
|
|
74
|
-
return
|
|
98
|
+
return vaultClient.isLocked();
|
|
75
99
|
|
|
76
100
|
case 3:
|
|
77
101
|
locked = _context.sent;
|
|
@@ -98,33 +122,32 @@ function (_React$Component) {
|
|
|
98
122
|
}()
|
|
99
123
|
}, {
|
|
100
124
|
key: "setupClient",
|
|
101
|
-
value: function setupClient() {
|
|
102
|
-
var
|
|
125
|
+
value: function setupClient(instance) {
|
|
126
|
+
var _this3 = this;
|
|
103
127
|
|
|
104
128
|
var unsafeStorage = this.props.unsafeStorage;
|
|
105
|
-
var
|
|
129
|
+
var vaultClient = this.props.vaultClient || this.props.client || getVaultClient(instance, unsafeStorage, this.props.vaultData);
|
|
106
130
|
this.setState({
|
|
107
|
-
|
|
131
|
+
vaultClient: vaultClient,
|
|
108
132
|
locked: true
|
|
109
133
|
}, function () {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
134
|
+
vaultClient.on('unlock', _this3.updateLockedState);
|
|
135
|
+
vaultClient.on('lock', _this3.updateLockedState);
|
|
136
|
+
vaultClient.on('login', _this3.updateLockedState);
|
|
113
137
|
|
|
114
|
-
|
|
138
|
+
_this3.updateLockedState();
|
|
115
139
|
});
|
|
116
140
|
|
|
117
141
|
if (this.props.setClient) {
|
|
118
|
-
this.props.setClient(
|
|
142
|
+
this.props.setClient(vaultClient);
|
|
119
143
|
}
|
|
120
144
|
}
|
|
121
145
|
}, {
|
|
122
146
|
key: "render",
|
|
123
147
|
value: function render() {
|
|
124
|
-
|
|
125
|
-
return client ? React.createElement(VaultContext.Provider, {
|
|
148
|
+
return React.createElement(VaultContext.Provider, {
|
|
126
149
|
value: this.state
|
|
127
|
-
}, this.props.children)
|
|
150
|
+
}, this.props.children);
|
|
128
151
|
}
|
|
129
152
|
}]);
|
|
130
153
|
|
|
@@ -132,17 +155,21 @@ function (_React$Component) {
|
|
|
132
155
|
}(React.Component);
|
|
133
156
|
|
|
134
157
|
VaultProvider.propTypes = {
|
|
135
|
-
instance: PropTypes.string
|
|
158
|
+
instance: PropTypes.string,
|
|
159
|
+
vaultClient: PropTypes.object,
|
|
160
|
+
client: PropTypes.object,
|
|
161
|
+
// deprecated
|
|
136
162
|
unsafeStorage: PropTypes.bool,
|
|
137
|
-
setClient: PropTypes.func
|
|
163
|
+
setClient: PropTypes.func,
|
|
164
|
+
cozyClient: PropTypes.object
|
|
138
165
|
};
|
|
139
166
|
|
|
140
167
|
var withVaultClient = function withVaultClient(BaseComponent) {
|
|
141
168
|
var Component = function Component(props) {
|
|
142
169
|
return React.createElement(VaultContext.Consumer, null, function (_ref) {
|
|
143
|
-
var
|
|
170
|
+
var vaultClient = _ref.vaultClient;
|
|
144
171
|
return React.createElement(BaseComponent, _extends({
|
|
145
|
-
vaultClient:
|
|
172
|
+
vaultClient: vaultClient
|
|
146
173
|
}, props));
|
|
147
174
|
});
|
|
148
175
|
};
|
|
@@ -153,7 +180,7 @@ var withVaultClient = function withVaultClient(BaseComponent) {
|
|
|
153
180
|
|
|
154
181
|
var useVaultClient = function useVaultClient() {
|
|
155
182
|
var ctx = useContext(VaultContext);
|
|
156
|
-
return ctx.
|
|
183
|
+
return ctx.vaultClient;
|
|
157
184
|
};
|
|
158
185
|
|
|
159
186
|
export { VaultContext, VaultProvider, withVaultClient, useVaultClient };
|
|
@@ -12,7 +12,7 @@ describe('VaultProvider', function () {
|
|
|
12
12
|
_asyncToGenerator(
|
|
13
13
|
/*#__PURE__*/
|
|
14
14
|
_regeneratorRuntime.mark(function _callee() {
|
|
15
|
-
var ChildComponent, component,
|
|
15
|
+
var ChildComponent, component, vaultClient;
|
|
16
16
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
17
17
|
while (1) {
|
|
18
18
|
switch (_context.prev = _context.next) {
|
|
@@ -21,18 +21,18 @@ describe('VaultProvider', function () {
|
|
|
21
21
|
component = mount(React.createElement(VaultProvider, {
|
|
22
22
|
instance: 'test@example.com'
|
|
23
23
|
}, React.createElement(VaultContext.Consumer, null, ChildComponent)));
|
|
24
|
-
|
|
24
|
+
vaultClient = component.state('vaultClient');
|
|
25
25
|
expect(ChildComponent).toHaveBeenCalledWith({
|
|
26
|
-
|
|
26
|
+
vaultClient: vaultClient,
|
|
27
27
|
locked: true
|
|
28
28
|
});
|
|
29
|
-
|
|
29
|
+
vaultClient.unlock();
|
|
30
30
|
_context.next = 7;
|
|
31
31
|
return new Promise(function (resolve) {
|
|
32
32
|
return setTimeout(function () {
|
|
33
|
-
expect(ChildComponent).toHaveBeenCalledTimes(
|
|
33
|
+
expect(ChildComponent).toHaveBeenCalledTimes(3);
|
|
34
34
|
expect(ChildComponent).toHaveBeenCalledWith({
|
|
35
|
-
|
|
35
|
+
vaultClient: vaultClient,
|
|
36
36
|
locked: false
|
|
37
37
|
});
|
|
38
38
|
resolve();
|
|
@@ -40,13 +40,13 @@ describe('VaultProvider', function () {
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
case 7:
|
|
43
|
-
|
|
43
|
+
vaultClient.lock();
|
|
44
44
|
_context.next = 10;
|
|
45
45
|
return new Promise(function (resolve) {
|
|
46
46
|
return setTimeout(function () {
|
|
47
|
-
expect(ChildComponent).toHaveBeenCalledTimes(
|
|
47
|
+
expect(ChildComponent).toHaveBeenCalledTimes(4);
|
|
48
48
|
expect(ChildComponent).toHaveBeenCalledWith({
|
|
49
|
-
|
|
49
|
+
vaultClient: vaultClient,
|
|
50
50
|
locked: true
|
|
51
51
|
});
|
|
52
52
|
resolve();
|
|
@@ -6,7 +6,6 @@ import PropTypes from 'prop-types';
|
|
|
6
6
|
import Spinner from 'cozy-ui/transpiled/react/Spinner';
|
|
7
7
|
import Overlay from 'cozy-ui/transpiled/react/Overlay';
|
|
8
8
|
import withLocales from 'cozy-ui/transpiled/react/I18n/withLocales';
|
|
9
|
-
import { useClient } from 'cozy-client';
|
|
10
9
|
import localesEn from '../locales/en.json';
|
|
11
10
|
import localesFr from '../locales/fr.json';
|
|
12
11
|
import { VaultContext } from './VaultContext';
|
|
@@ -23,12 +22,11 @@ var VaultUnlocker = function VaultUnlocker(_ref) {
|
|
|
23
22
|
closable = _ref.closable,
|
|
24
23
|
onUnlock = _ref.onUnlock,
|
|
25
24
|
UnlockForm = _ref.UnlockForm,
|
|
26
|
-
|
|
27
|
-
var cozyClient = useClient();
|
|
25
|
+
addCheckShouldUnlock = _ref.addCheckShouldUnlock;
|
|
28
26
|
|
|
29
27
|
var _useContext = useContext(VaultContext),
|
|
30
28
|
locked = _useContext.locked,
|
|
31
|
-
vaultClient = _useContext.
|
|
29
|
+
vaultClient = _useContext.vaultClient;
|
|
32
30
|
|
|
33
31
|
var _useState = useState(false),
|
|
34
32
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -67,7 +65,7 @@ var VaultUnlocker = function VaultUnlocker(_ref) {
|
|
|
67
65
|
switch (_context.prev = _context.next) {
|
|
68
66
|
case 0:
|
|
69
67
|
_context.next = 2;
|
|
70
|
-
return checkShouldUnlock(vaultClient,
|
|
68
|
+
return checkShouldUnlock(vaultClient, addCheckShouldUnlock);
|
|
71
69
|
|
|
72
70
|
case 2:
|
|
73
71
|
shouldUnlock = _context.sent;
|
|
@@ -113,10 +111,10 @@ var VaultUnlocker = function VaultUnlocker(_ref) {
|
|
|
113
111
|
VaultUnlocker.propTypes = {
|
|
114
112
|
onDismiss: PropTypes.func.isRequired,
|
|
115
113
|
closable: PropTypes.bool,
|
|
116
|
-
onUnlock: PropTypes.func.isRequired
|
|
114
|
+
onUnlock: PropTypes.func.isRequired,
|
|
115
|
+
addCheckShouldUnlock: PropTypes.func
|
|
117
116
|
};
|
|
118
117
|
VaultUnlocker.defaultProps = {
|
|
119
|
-
UnlockForm: UnlockForm
|
|
120
|
-
checkShouldUnlock: checkShouldUnlock
|
|
118
|
+
UnlockForm: UnlockForm
|
|
121
119
|
};
|
|
122
120
|
export default withLocales(locales)(VaultUnlocker);
|
|
@@ -1,37 +1,49 @@
|
|
|
1
1
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Check whether or not the vault should be unlocked
|
|
6
|
+
*
|
|
7
|
+
* @param {object} vaultClient - The vault client
|
|
8
|
+
* @param {function} addCheckShouldUnlock - An additional check method to unlock
|
|
9
|
+
* @returns {boolean} True if the vault should be unlocked
|
|
10
|
+
*/
|
|
4
11
|
export var checkShouldUnlock =
|
|
5
12
|
/*#__PURE__*/
|
|
6
13
|
function () {
|
|
7
14
|
var _ref = _asyncToGenerator(
|
|
8
15
|
/*#__PURE__*/
|
|
9
|
-
_regeneratorRuntime.mark(function _callee(vaultClient
|
|
16
|
+
_regeneratorRuntime.mark(function _callee(vaultClient) {
|
|
17
|
+
var addCheckShouldUnlock,
|
|
18
|
+
_args = arguments;
|
|
10
19
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
11
20
|
while (1) {
|
|
12
21
|
switch (_context.prev = _context.next) {
|
|
13
22
|
case 0:
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
addCheckShouldUnlock = _args.length > 1 && _args[1] !== undefined ? _args[1] : function () {
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
_context.next = 3;
|
|
27
|
+
return addCheckShouldUnlock();
|
|
16
28
|
|
|
17
|
-
case
|
|
29
|
+
case 3:
|
|
18
30
|
_context.t0 = _context.sent;
|
|
19
31
|
|
|
20
32
|
if (!_context.t0) {
|
|
21
|
-
_context.next =
|
|
33
|
+
_context.next = 8;
|
|
22
34
|
break;
|
|
23
35
|
}
|
|
24
36
|
|
|
25
|
-
_context.next =
|
|
37
|
+
_context.next = 7;
|
|
26
38
|
return vaultClient.isLocked();
|
|
27
39
|
|
|
28
|
-
case
|
|
40
|
+
case 7:
|
|
29
41
|
_context.t0 = _context.sent;
|
|
30
42
|
|
|
31
|
-
case
|
|
43
|
+
case 8:
|
|
32
44
|
return _context.abrupt("return", _context.t0);
|
|
33
45
|
|
|
34
|
-
case
|
|
46
|
+
case 9:
|
|
35
47
|
case "end":
|
|
36
48
|
return _context.stop();
|
|
37
49
|
}
|
|
@@ -39,7 +51,7 @@ function () {
|
|
|
39
51
|
}, _callee);
|
|
40
52
|
}));
|
|
41
53
|
|
|
42
|
-
return function checkShouldUnlock(_x
|
|
54
|
+
return function checkShouldUnlock(_x) {
|
|
43
55
|
return _ref.apply(this, arguments);
|
|
44
56
|
};
|
|
45
57
|
}();
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import { checkShouldUnlock } from './defaults';
|
|
4
|
+
import WebVaultClient from '../WebVaultClient';
|
|
5
|
+
jest.mock('../CozyUtils', function () {
|
|
6
|
+
return {
|
|
7
|
+
checkHasInstalledExtension: jest.fn(),
|
|
8
|
+
getEmail: jest.fn().mockReturnValue('me@test.fr'),
|
|
9
|
+
isInstance: jest.fn().mockReturnValue(true)
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
describe('checkShouldUnlock', function () {
|
|
13
|
+
var vaultClient = new WebVaultClient('https://me.cozy.wtf');
|
|
14
|
+
it('should return true when the vault is locked',
|
|
15
|
+
/*#__PURE__*/
|
|
16
|
+
_asyncToGenerator(
|
|
17
|
+
/*#__PURE__*/
|
|
18
|
+
_regeneratorRuntime.mark(function _callee() {
|
|
19
|
+
var shouldUnlock;
|
|
20
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
21
|
+
while (1) {
|
|
22
|
+
switch (_context.prev = _context.next) {
|
|
23
|
+
case 0:
|
|
24
|
+
jest.spyOn(vaultClient, 'isLocked').mockResolvedValue(true);
|
|
25
|
+
_context.next = 3;
|
|
26
|
+
return checkShouldUnlock(vaultClient);
|
|
27
|
+
|
|
28
|
+
case 3:
|
|
29
|
+
shouldUnlock = _context.sent;
|
|
30
|
+
expect(shouldUnlock).toBe(true);
|
|
31
|
+
|
|
32
|
+
case 5:
|
|
33
|
+
case "end":
|
|
34
|
+
return _context.stop();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, _callee);
|
|
38
|
+
})));
|
|
39
|
+
it('should return false when the vault is already unlocked',
|
|
40
|
+
/*#__PURE__*/
|
|
41
|
+
_asyncToGenerator(
|
|
42
|
+
/*#__PURE__*/
|
|
43
|
+
_regeneratorRuntime.mark(function _callee2() {
|
|
44
|
+
var shouldUnlock;
|
|
45
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
46
|
+
while (1) {
|
|
47
|
+
switch (_context2.prev = _context2.next) {
|
|
48
|
+
case 0:
|
|
49
|
+
jest.spyOn(vaultClient, 'isLocked').mockResolvedValue(false);
|
|
50
|
+
_context2.next = 3;
|
|
51
|
+
return checkShouldUnlock(vaultClient);
|
|
52
|
+
|
|
53
|
+
case 3:
|
|
54
|
+
shouldUnlock = _context2.sent;
|
|
55
|
+
expect(shouldUnlock).toBe(false);
|
|
56
|
+
|
|
57
|
+
case 5:
|
|
58
|
+
case "end":
|
|
59
|
+
return _context2.stop();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}, _callee2);
|
|
63
|
+
})));
|
|
64
|
+
it('should return false when additional check function return false',
|
|
65
|
+
/*#__PURE__*/
|
|
66
|
+
_asyncToGenerator(
|
|
67
|
+
/*#__PURE__*/
|
|
68
|
+
_regeneratorRuntime.mark(function _callee3() {
|
|
69
|
+
var additionalUnlockCheck, shouldUnlock;
|
|
70
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
71
|
+
while (1) {
|
|
72
|
+
switch (_context3.prev = _context3.next) {
|
|
73
|
+
case 0:
|
|
74
|
+
jest.spyOn(vaultClient, 'isLocked').mockResolvedValue(true);
|
|
75
|
+
|
|
76
|
+
additionalUnlockCheck = function additionalUnlockCheck() {
|
|
77
|
+
return false;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
_context3.next = 4;
|
|
81
|
+
return checkShouldUnlock(vaultClient, additionalUnlockCheck);
|
|
82
|
+
|
|
83
|
+
case 4:
|
|
84
|
+
shouldUnlock = _context3.sent;
|
|
85
|
+
expect(shouldUnlock).toBe(false);
|
|
86
|
+
|
|
87
|
+
case 6:
|
|
88
|
+
case "end":
|
|
89
|
+
return _context3.stop();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, _callee3);
|
|
93
|
+
})));
|
|
94
|
+
});
|
|
@@ -4,7 +4,6 @@ import _objectSpread from "@babel/runtime/helpers/objectSpread";
|
|
|
4
4
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
5
5
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
6
6
|
import React, { useMemo, useState, useContext } from 'react';
|
|
7
|
-
import { useClient } from 'cozy-client';
|
|
8
7
|
import { useVaultClient } from './VaultContext';
|
|
9
8
|
import { checkShouldUnlock } from './defaults';
|
|
10
9
|
var vaultUnlockContext = React.createContext();
|
|
@@ -46,8 +45,7 @@ export var useVaultUnlockContext = function useVaultUnlockContext() {
|
|
|
46
45
|
|
|
47
46
|
export var VaultUnlockProvider = function VaultUnlockProvider(_ref) {
|
|
48
47
|
var children = _ref.children,
|
|
49
|
-
|
|
50
|
-
var client = useClient();
|
|
48
|
+
addCheckShouldUnlock = _ref.addCheckShouldUnlock;
|
|
51
49
|
var vaultClient = useVaultClient();
|
|
52
50
|
|
|
53
51
|
var _useState = useState(false),
|
|
@@ -91,7 +89,7 @@ export var VaultUnlockProvider = function VaultUnlockProvider(_ref) {
|
|
|
91
89
|
};
|
|
92
90
|
|
|
93
91
|
_context.next = 6;
|
|
94
|
-
return checkShouldUnlock(vaultClient,
|
|
92
|
+
return checkShouldUnlock(vaultClient, addCheckShouldUnlock);
|
|
95
93
|
|
|
96
94
|
case 6:
|
|
97
95
|
shouldUnlock = _context.sent;
|
|
@@ -125,14 +123,11 @@ export var VaultUnlockProvider = function VaultUnlockProvider(_ref) {
|
|
|
125
123
|
unlockFormProps: unlockFormProps,
|
|
126
124
|
vaultClient: vaultClient
|
|
127
125
|
};
|
|
128
|
-
}, [showingUnlockForm, unlockFormProps, vaultClient,
|
|
126
|
+
}, [showingUnlockForm, unlockFormProps, vaultClient, addCheckShouldUnlock]);
|
|
129
127
|
return React.createElement(vaultUnlockContext.Provider, {
|
|
130
128
|
value: value
|
|
131
129
|
}, children);
|
|
132
130
|
};
|
|
133
|
-
VaultUnlockProvider.defaultProps = {
|
|
134
|
-
checkShouldUnlock: checkShouldUnlock
|
|
135
|
-
};
|
|
136
131
|
export var withVaultUnlockContext = function withVaultUnlockContext(Component) {
|
|
137
132
|
var Wrapper = function Wrapper(props) {
|
|
138
133
|
var vaultUnlockContextValue = useVaultUnlockContext();
|
|
@@ -3,18 +3,12 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { render, act, fireEvent } from '@testing-library/react';
|
|
5
5
|
import { VaultUnlockProvider, useVaultUnlockContext } from './vaultUnlockContext';
|
|
6
|
-
import { checkHasInstalledExtension } from '../CozyUtils';
|
|
7
6
|
import { useVaultClient } from './VaultContext';
|
|
8
7
|
jest.mock('./VaultContext', function () {
|
|
9
8
|
return {
|
|
10
9
|
useVaultClient: jest.fn()
|
|
11
10
|
};
|
|
12
11
|
});
|
|
13
|
-
jest.mock('../CozyUtils', function () {
|
|
14
|
-
return {
|
|
15
|
-
checkHasInstalledExtension: jest.fn()
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
12
|
describe('vault unlock context', function () {
|
|
19
13
|
var Component = function Component(_ref) {
|
|
20
14
|
var onUnlock = _ref.onUnlock;
|
|
@@ -105,25 +99,24 @@ describe('vault unlock context', function () {
|
|
|
105
99
|
useVaultClient.mockReturnValue({
|
|
106
100
|
isLocked: jest.fn().mockResolvedValue(true)
|
|
107
101
|
});
|
|
108
|
-
|
|
109
|
-
_context3.next = 4;
|
|
102
|
+
_context3.next = 3;
|
|
110
103
|
return setup();
|
|
111
104
|
|
|
112
|
-
case
|
|
105
|
+
case 3:
|
|
113
106
|
_ref5 = _context3.sent;
|
|
114
107
|
root = _ref5.root;
|
|
115
108
|
onUnlock = _ref5.onUnlock;
|
|
116
109
|
root.getByText('showingUnlockForm: true');
|
|
117
110
|
expect(onUnlock).not.toHaveBeenCalled();
|
|
118
111
|
|
|
119
|
-
case
|
|
112
|
+
case 8:
|
|
120
113
|
case "end":
|
|
121
114
|
return _context3.stop();
|
|
122
115
|
}
|
|
123
116
|
}
|
|
124
117
|
}, _callee3);
|
|
125
118
|
})));
|
|
126
|
-
it('should not show unlock form and call onUnlock if
|
|
119
|
+
it('should not show unlock form and call onUnlock if vault is unlocked',
|
|
127
120
|
/*#__PURE__*/
|
|
128
121
|
_asyncToGenerator(
|
|
129
122
|
/*#__PURE__*/
|
|
@@ -135,56 +128,23 @@ describe('vault unlock context', function () {
|
|
|
135
128
|
switch (_context4.prev = _context4.next) {
|
|
136
129
|
case 0:
|
|
137
130
|
useVaultClient.mockReturnValue({
|
|
138
|
-
isLocked: jest.fn().mockResolvedValue(
|
|
131
|
+
isLocked: jest.fn().mockResolvedValue(false)
|
|
139
132
|
});
|
|
140
|
-
|
|
141
|
-
_context4.next = 4;
|
|
133
|
+
_context4.next = 3;
|
|
142
134
|
return setup();
|
|
143
135
|
|
|
144
|
-
case
|
|
136
|
+
case 3:
|
|
145
137
|
_ref7 = _context4.sent;
|
|
146
138
|
root = _ref7.root;
|
|
147
139
|
onUnlock = _ref7.onUnlock;
|
|
148
140
|
expect(root.getByText('showingUnlockForm: false')).toBeTruthy();
|
|
149
141
|
expect(onUnlock).toHaveBeenCalled();
|
|
150
142
|
|
|
151
|
-
case
|
|
143
|
+
case 8:
|
|
152
144
|
case "end":
|
|
153
145
|
return _context4.stop();
|
|
154
146
|
}
|
|
155
147
|
}
|
|
156
148
|
}, _callee4);
|
|
157
149
|
})));
|
|
158
|
-
it('should not show unlock form and call onUnlock if vault is unlocked',
|
|
159
|
-
/*#__PURE__*/
|
|
160
|
-
_asyncToGenerator(
|
|
161
|
-
/*#__PURE__*/
|
|
162
|
-
_regeneratorRuntime.mark(function _callee5() {
|
|
163
|
-
var _ref9, root, onUnlock;
|
|
164
|
-
|
|
165
|
-
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
166
|
-
while (1) {
|
|
167
|
-
switch (_context5.prev = _context5.next) {
|
|
168
|
-
case 0:
|
|
169
|
-
useVaultClient.mockReturnValue({
|
|
170
|
-
isLocked: jest.fn().mockResolvedValue(false)
|
|
171
|
-
});
|
|
172
|
-
checkHasInstalledExtension.mockResolvedValue(true);
|
|
173
|
-
_context5.next = 4;
|
|
174
|
-
return setup();
|
|
175
|
-
|
|
176
|
-
case 4:
|
|
177
|
-
_ref9 = _context5.sent;
|
|
178
|
-
root = _ref9.root;
|
|
179
|
-
onUnlock = _ref9.onUnlock;
|
|
180
|
-
expect(root.getByText('showingUnlockForm: false')).toBeTruthy();
|
|
181
|
-
expect(onUnlock).toHaveBeenCalled();
|
|
182
|
-
|
|
183
|
-
case 9:
|
|
184
|
-
case "end":
|
|
185
|
-
return _context5.stop();
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}, _callee5);
|
|
189
|
-
})));
|
|
190
150
|
});
|
package/transpiled/index.js
CHANGED
|
@@ -9,4 +9,5 @@ import _VaultUnlocker from './components/VaultUnlocker';
|
|
|
9
9
|
export { _VaultUnlocker as VaultUnlocker };
|
|
10
10
|
import _VaultUnlockPlaceholder from './components/VaultUnlockPlaceholder';
|
|
11
11
|
export { _VaultUnlockPlaceholder as VaultUnlockPlaceholder };
|
|
12
|
-
export { useVaultUnlockContext, VaultUnlockProvider, withVaultUnlockContext } from './components/vaultUnlockContext';
|
|
12
|
+
export { useVaultUnlockContext, VaultUnlockProvider, withVaultUnlockContext } from './components/vaultUnlockContext';
|
|
13
|
+
export { UnlockForm } from './components/UnlockForm';
|