cozy-keys-lib 6.1.0 → 6.1.1
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 +17 -17
- package/src/components/UnlockForm.jsx +30 -142
- package/src/components/UnlockForm.spec.jsx +12 -9
- package/src/components/VaultUnlocker.jsx +1 -10
- package/src/locales/en.json +1 -15
- package/src/locales/fr.json +1 -15
- package/transpiled/components/UnlockForm.js +44 -128
- package/transpiled/components/UnlockForm.spec.js +10 -9
- package/transpiled/components/VaultUnlocker.js +1 -8
- package/transpiled/locales/en.json +1 -15
- package/transpiled/locales/fr.json +1 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-keys-lib",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "Interactions between cozy-keys and a bitwarden server",
|
|
5
5
|
"browser": "transpiled/index.js",
|
|
6
6
|
"main": "transpiled/index.node.js",
|
|
@@ -38,28 +38,28 @@
|
|
|
38
38
|
"@babel/plugin-transform-runtime": "7.17.0",
|
|
39
39
|
"@babel/preset-env": "7.16.11",
|
|
40
40
|
"@babel/runtime": "7.17.8",
|
|
41
|
-
"@material-ui/core": "3",
|
|
42
|
-
"@semantic-release/changelog": "
|
|
43
|
-
"@semantic-release/git": "
|
|
44
|
-
"@semantic-release/npm": "
|
|
45
|
-
"@testing-library/react": "
|
|
46
|
-
"@testing-library/react-hooks": "
|
|
41
|
+
"@material-ui/core": "3.9.4",
|
|
42
|
+
"@semantic-release/changelog": "3.0.6",
|
|
43
|
+
"@semantic-release/git": "7.0.18",
|
|
44
|
+
"@semantic-release/npm": "5.3.5",
|
|
45
|
+
"@testing-library/react": "11.2.7",
|
|
46
|
+
"@testing-library/react-hooks": "3.7.0",
|
|
47
47
|
"babel-loader": "8.2.4",
|
|
48
|
-
"babel-plugin-inline-react-svg": "
|
|
49
|
-
"babel-plugin-mock-imports": "
|
|
48
|
+
"babel-plugin-inline-react-svg": "1.1.2",
|
|
49
|
+
"babel-plugin-mock-imports": "1.2.0",
|
|
50
50
|
"babel-plugin-rewire": "1.2.0",
|
|
51
|
-
"babel-preset-cozy-app": "
|
|
51
|
+
"babel-preset-cozy-app": "1.12.0",
|
|
52
52
|
"cozy-client": "^40.5.0",
|
|
53
53
|
"cozy-flags": "2.8.6",
|
|
54
|
-
"cozy-intent": "
|
|
55
|
-
"cozy-ui": "
|
|
56
|
-
"enzyme": "
|
|
57
|
-
"enzyme-adapter-react-16": "
|
|
54
|
+
"cozy-intent": "2.13.1",
|
|
55
|
+
"cozy-ui": "93.1.1",
|
|
56
|
+
"enzyme": "3.11.0",
|
|
57
|
+
"enzyme-adapter-react-16": "1.15.7",
|
|
58
58
|
"enzyme-to-json": "3.4.0",
|
|
59
|
-
"eslint-config-cozy-app": "
|
|
59
|
+
"eslint-config-cozy-app": "1.6.0",
|
|
60
60
|
"jest": "26.2.2",
|
|
61
|
-
"react": "
|
|
62
|
-
"react-dom": "
|
|
61
|
+
"react": "16.14.0",
|
|
62
|
+
"react-dom": "16.14.0",
|
|
63
63
|
"semantic-release": "^15.13.24"
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
import React, { useState, useCallback
|
|
2
|
-
import cx from 'classnames'
|
|
1
|
+
import React, { useState, useCallback } from 'react'
|
|
3
2
|
import get from 'lodash/get'
|
|
4
3
|
import PropTypes from 'prop-types'
|
|
5
4
|
|
|
6
|
-
import { useClient } from 'cozy-client'
|
|
7
5
|
import flag from 'cozy-flags'
|
|
8
|
-
import
|
|
9
|
-
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
|
|
10
|
-
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
|
|
11
|
-
import Button from 'cozy-ui/transpiled/react/deprecated/Button'
|
|
12
|
-
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
13
|
-
import CozyTheme from 'cozy-ui/transpiled/react/providers/CozyTheme'
|
|
14
|
-
import { IllustrationDialog } from 'cozy-ui/transpiled/react/CozyDialogs'
|
|
15
|
-
import KeychainIcon from 'cozy-ui/transpiled/react/Icons/Keychain'
|
|
16
|
-
import { useWebviewIntent } from 'cozy-intent'
|
|
17
|
-
|
|
18
|
-
import CloudIcon from './IconCozySecurity'
|
|
19
|
-
import PasswordField from './PasswordField'
|
|
6
|
+
import { AuthentificationDialog } from 'cozy-ui/transpiled/react/CozyDialogs'
|
|
20
7
|
|
|
21
8
|
import { useVaultClient } from './VaultContext'
|
|
22
|
-
|
|
23
|
-
const getPassphraseResetUrl = client => {
|
|
24
|
-
const url = new URL('/auth/passphrase_reset', client.getStackClient().uri)
|
|
25
|
-
|
|
26
|
-
return url.href
|
|
27
|
-
}
|
|
9
|
+
import { useClient } from 'cozy-client'
|
|
28
10
|
|
|
29
11
|
const canClientAuthWithOIDC = client => {
|
|
30
12
|
return (
|
|
@@ -36,137 +18,43 @@ const canClientAuthWithOIDC = client => {
|
|
|
36
18
|
const UnlockForm = props => {
|
|
37
19
|
const client = useClient()
|
|
38
20
|
const vaultClient = useVaultClient()
|
|
39
|
-
const { isMobile } = useBreakpoints()
|
|
40
|
-
const { t } = useI18n()
|
|
41
21
|
|
|
42
22
|
const { onUnlock, onDismiss, closable } = props
|
|
43
23
|
|
|
44
|
-
const [
|
|
24
|
+
const [isUnlocking, setUnlocking] = useState(false)
|
|
45
25
|
const [error, setError] = useState(null)
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const handlePasswordChange = useCallback(ev => {
|
|
49
|
-
setPassword(ev.currentTarget.value)
|
|
50
|
-
})
|
|
26
|
+
const canAuthWithOIDC = canClientAuthWithOIDC(client)
|
|
51
27
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
onUnlock
|
|
28
|
+
const handleUnlock = useCallback(
|
|
29
|
+
async password => {
|
|
30
|
+
setUnlocking(true)
|
|
31
|
+
setError(null)
|
|
32
|
+
try {
|
|
33
|
+
await vaultClient.unlock(password)
|
|
34
|
+
if (onUnlock) {
|
|
35
|
+
onUnlock()
|
|
36
|
+
}
|
|
37
|
+
} catch (e) {
|
|
38
|
+
setError(
|
|
39
|
+
e.response.error === 'invalid password'
|
|
40
|
+
? 'invalid_password'
|
|
41
|
+
: 'server_error'
|
|
42
|
+
)
|
|
43
|
+
} finally {
|
|
44
|
+
setUnlocking(false)
|
|
59
45
|
}
|
|
60
|
-
} catch (error) {
|
|
61
|
-
setError(error)
|
|
62
|
-
} finally {
|
|
63
|
-
setUnlocking(false)
|
|
64
|
-
}
|
|
65
|
-
}, [vaultClient, onUnlock, password])
|
|
66
|
-
|
|
67
|
-
const handleVaultUnlock = useCallback(
|
|
68
|
-
ev => {
|
|
69
|
-
ev.preventDefault()
|
|
70
|
-
unlockVault()
|
|
71
46
|
},
|
|
72
|
-
[
|
|
47
|
+
[vaultClient, onUnlock]
|
|
73
48
|
)
|
|
74
49
|
|
|
75
|
-
const getPassphraseResetUrlCb = useMemo(() => getPassphraseResetUrl(client), [
|
|
76
|
-
client
|
|
77
|
-
])
|
|
78
|
-
|
|
79
|
-
const canAuthWithOIDC = canClientAuthWithOIDC(client)
|
|
80
|
-
|
|
81
|
-
const webviewIntent = useWebviewIntent()
|
|
82
|
-
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
webviewIntent &&
|
|
85
|
-
webviewIntent.call(
|
|
86
|
-
'setFlagshipUI',
|
|
87
|
-
{
|
|
88
|
-
bottomTheme: 'light',
|
|
89
|
-
topTheme: 'light'
|
|
90
|
-
},
|
|
91
|
-
'cozy-keys-lib/UnlockForm'
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
return () =>
|
|
95
|
-
webviewIntent &&
|
|
96
|
-
webviewIntent.call(
|
|
97
|
-
'setFlagshipUI',
|
|
98
|
-
{
|
|
99
|
-
bottomTheme: 'light',
|
|
100
|
-
topTheme: 'light'
|
|
101
|
-
},
|
|
102
|
-
'cozy-keys-lib/UnlockForm'
|
|
103
|
-
)
|
|
104
|
-
}, [webviewIntent])
|
|
105
|
-
|
|
106
50
|
return (
|
|
107
|
-
<
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
onSubmit={handleVaultUnlock}
|
|
115
|
-
className="u-stack-m u-flex u-flex-column u-flex-items-center"
|
|
116
|
-
>
|
|
117
|
-
{canAuthWithOIDC ? (
|
|
118
|
-
<Icon icon={KeychainIcon} size={64} className="u-mb-half" />
|
|
119
|
-
) : (
|
|
120
|
-
<CloudIcon className="u-mb-half" size={104} />
|
|
121
|
-
)}
|
|
122
|
-
<Typography variant="h3" gutterBottom>
|
|
123
|
-
{canAuthWithOIDC ? t('unlock.title-oidc') : t('unlock.title')}
|
|
124
|
-
</Typography>
|
|
125
|
-
{error ? (
|
|
126
|
-
<Typography variant="body1" className="u-error">
|
|
127
|
-
{t('unlock.error')}
|
|
128
|
-
</Typography>
|
|
129
|
-
) : (
|
|
130
|
-
<Typography variant="body1">{t('unlock.subtitle')}</Typography>
|
|
131
|
-
)}
|
|
132
|
-
|
|
133
|
-
<PasswordField
|
|
134
|
-
id="idField"
|
|
135
|
-
label={
|
|
136
|
-
canAuthWithOIDC ? t('unlock.label-oidc') : t('unlock.label')
|
|
137
|
-
}
|
|
138
|
-
value={password}
|
|
139
|
-
onChange={handlePasswordChange}
|
|
140
|
-
fullWidth
|
|
141
|
-
className="u-mt-2"
|
|
142
|
-
/>
|
|
143
|
-
|
|
144
|
-
<Typography
|
|
145
|
-
variant="body1"
|
|
146
|
-
component="a"
|
|
147
|
-
color="primary"
|
|
148
|
-
href={getPassphraseResetUrlCb}
|
|
149
|
-
className="u-link u-mt-1 u-flex-self-start"
|
|
150
|
-
>
|
|
151
|
-
{t('unlock.forgotten-password')}
|
|
152
|
-
</Typography>
|
|
153
|
-
</form>
|
|
154
|
-
}
|
|
155
|
-
actions={
|
|
156
|
-
<Button
|
|
157
|
-
onClick={handleVaultUnlock}
|
|
158
|
-
label={t('unlock.unlock')}
|
|
159
|
-
theme="primary"
|
|
160
|
-
className={cx({
|
|
161
|
-
'u-mt-1': !isMobile,
|
|
162
|
-
'u-mt-auto': isMobile
|
|
163
|
-
})}
|
|
164
|
-
busy={unlocking}
|
|
165
|
-
extension="full"
|
|
166
|
-
/>
|
|
167
|
-
}
|
|
168
|
-
/>
|
|
169
|
-
</CozyTheme>
|
|
51
|
+
<AuthentificationDialog
|
|
52
|
+
onClose={closable ? onDismiss : null}
|
|
53
|
+
onSubmit={handleUnlock}
|
|
54
|
+
isLoading={isUnlocking}
|
|
55
|
+
isOIDC={canAuthWithOIDC}
|
|
56
|
+
error={error}
|
|
57
|
+
/>
|
|
170
58
|
)
|
|
171
59
|
}
|
|
172
60
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import { render, fireEvent, act, waitFor, screen } from '@testing-library/react'
|
|
3
|
+
|
|
4
4
|
import CozyClient, { CozyProvider } from 'cozy-client'
|
|
5
|
-
import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints'
|
|
6
5
|
import I18n from 'cozy-ui/transpiled/react/providers/I18n'
|
|
6
|
+
import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints'
|
|
7
|
+
|
|
7
8
|
import { VaultProvider, useVaultClient } from './VaultContext'
|
|
8
|
-
import
|
|
9
|
+
import UnlockForm from './UnlockForm'
|
|
9
10
|
|
|
10
11
|
jest.mock('./VaultContext', () => {
|
|
11
12
|
const { VaultProvider } = jest.requireActual('./VaultContext')
|
|
@@ -27,20 +28,22 @@ describe('unlock form', () => {
|
|
|
27
28
|
const root = render(
|
|
28
29
|
<CozyProvider client={client}>
|
|
29
30
|
<BreakpointsProvider>
|
|
30
|
-
<
|
|
31
|
-
<
|
|
31
|
+
<VaultProvider instance="cozy.tools:8080">
|
|
32
|
+
<I18n dictRequire={() => ({})} lang="en">
|
|
32
33
|
<UnlockForm
|
|
33
34
|
closable={true}
|
|
34
35
|
onDismiss={jest.fn()}
|
|
35
36
|
onUnlock={onUnlock}
|
|
36
37
|
/>
|
|
37
|
-
</
|
|
38
|
-
</
|
|
38
|
+
</I18n>
|
|
39
|
+
</VaultProvider>
|
|
39
40
|
</BreakpointsProvider>
|
|
40
41
|
</CozyProvider>
|
|
41
42
|
)
|
|
42
43
|
|
|
43
|
-
const password = await waitFor(() =>
|
|
44
|
+
const password = await waitFor(() =>
|
|
45
|
+
screen.getByLabelText(/password/i, { selector: 'input' })
|
|
46
|
+
)
|
|
44
47
|
await act(async () => {
|
|
45
48
|
fireEvent.change(password, { target: { value: 'my-password' } })
|
|
46
49
|
})
|
|
@@ -3,20 +3,11 @@ import PropTypes from 'prop-types'
|
|
|
3
3
|
|
|
4
4
|
import Spinner from 'cozy-ui/transpiled/react/Spinner'
|
|
5
5
|
import Overlay from 'cozy-ui/transpiled/react/deprecated/Overlay'
|
|
6
|
-
import withLocales from 'cozy-ui/transpiled/react/providers/I18n/withLocales'
|
|
7
|
-
|
|
8
|
-
import localesEn from '../locales/en.json'
|
|
9
|
-
import localesFr from '../locales/fr.json'
|
|
10
6
|
|
|
11
7
|
import { VaultContext } from './VaultContext'
|
|
12
8
|
import UnlockForm from './UnlockForm'
|
|
13
9
|
import { checkShouldUnlock } from './defaults'
|
|
14
10
|
|
|
15
|
-
const locales = {
|
|
16
|
-
en: localesEn,
|
|
17
|
-
fr: localesFr
|
|
18
|
-
}
|
|
19
|
-
|
|
20
11
|
const VaultUnlocker = ({
|
|
21
12
|
children,
|
|
22
13
|
onDismiss,
|
|
@@ -84,4 +75,4 @@ VaultUnlocker.defaultProps = {
|
|
|
84
75
|
UnlockForm
|
|
85
76
|
}
|
|
86
77
|
|
|
87
|
-
export default
|
|
78
|
+
export default VaultUnlocker
|
package/src/locales/en.json
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"unlock": {
|
|
3
|
-
"title": "Login",
|
|
4
|
-
"title-oidc": "Cozy Pass",
|
|
5
|
-
"subtitle": "For security, please confirm your identity",
|
|
6
|
-
"error": "Incorrect password",
|
|
7
|
-
"label": "Cozy password",
|
|
8
|
-
"label-oidc": "Cozy Pass password",
|
|
9
|
-
"show": "show",
|
|
10
|
-
"hide": "hide",
|
|
11
|
-
"abort": "Leave",
|
|
12
|
-
"unlock": "Unlock",
|
|
13
|
-
"forgotten-password": "I forgot my password"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
{}
|
package/src/locales/fr.json
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"unlock": {
|
|
3
|
-
"title": "Authentification",
|
|
4
|
-
"title-oidc": "Cozy Pass",
|
|
5
|
-
"subtitle": "Par sécurité, merci de confirmer votre identité",
|
|
6
|
-
"error": "Mot de passe incorrect, essayer à nouveau",
|
|
7
|
-
"label": "Mot de passe Cozy",
|
|
8
|
-
"label-oidc": "Mot de passe Cozy Pass",
|
|
9
|
-
"show": "afficher",
|
|
10
|
-
"hide": "masquer",
|
|
11
|
-
"abort": "Quitter",
|
|
12
|
-
"unlock": "Déverrouiller",
|
|
13
|
-
"forgotten-password": "J'ai oublié mon mot de passe"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
{}
|
|
@@ -1,156 +1,72 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
-
import React, { useState, useCallback
|
|
5
|
-
import cx from 'classnames';
|
|
4
|
+
import React, { useState, useCallback } from 'react';
|
|
6
5
|
import get from 'lodash/get';
|
|
7
6
|
import PropTypes from 'prop-types';
|
|
8
|
-
import { useClient } from 'cozy-client';
|
|
9
7
|
import flag from 'cozy-flags';
|
|
10
|
-
import
|
|
11
|
-
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints';
|
|
12
|
-
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
13
|
-
import Button from 'cozy-ui/transpiled/react/deprecated/Button';
|
|
14
|
-
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
15
|
-
import CozyTheme from 'cozy-ui/transpiled/react/providers/CozyTheme';
|
|
16
|
-
import { IllustrationDialog } from 'cozy-ui/transpiled/react/CozyDialogs';
|
|
17
|
-
import KeychainIcon from 'cozy-ui/transpiled/react/Icons/Keychain';
|
|
18
|
-
import { useWebviewIntent } from 'cozy-intent';
|
|
19
|
-
import CloudIcon from './IconCozySecurity';
|
|
20
|
-
import PasswordField from './PasswordField';
|
|
8
|
+
import { AuthentificationDialog } from 'cozy-ui/transpiled/react/CozyDialogs';
|
|
21
9
|
import { useVaultClient } from './VaultContext';
|
|
22
|
-
|
|
23
|
-
var url = new URL('/auth/passphrase_reset', client.getStackClient().uri);
|
|
24
|
-
return url.href;
|
|
25
|
-
};
|
|
10
|
+
import { useClient } from 'cozy-client';
|
|
26
11
|
var canClientAuthWithOIDC = function canClientAuthWithOIDC(client) {
|
|
27
12
|
return get(client, 'capabilities.can_auth_with_oidc') || flag('vault.force-oidc-display');
|
|
28
13
|
};
|
|
29
14
|
var UnlockForm = function UnlockForm(props) {
|
|
30
15
|
var client = useClient();
|
|
31
16
|
var vaultClient = useVaultClient();
|
|
32
|
-
var _useBreakpoints = useBreakpoints(),
|
|
33
|
-
isMobile = _useBreakpoints.isMobile;
|
|
34
|
-
var _useI18n = useI18n(),
|
|
35
|
-
t = _useI18n.t;
|
|
36
17
|
var onUnlock = props.onUnlock,
|
|
37
18
|
onDismiss = props.onDismiss,
|
|
38
19
|
closable = props.closable;
|
|
39
20
|
var _useState = useState(false),
|
|
40
21
|
_useState2 = _slicedToArray(_useState, 2),
|
|
41
|
-
|
|
22
|
+
isUnlocking = _useState2[0],
|
|
42
23
|
setUnlocking = _useState2[1];
|
|
43
24
|
var _useState3 = useState(null),
|
|
44
25
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
45
26
|
error = _useState4[0],
|
|
46
27
|
setError = _useState4[1];
|
|
47
|
-
var _useState5 = useState(''),
|
|
48
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
49
|
-
password = _useState6[0],
|
|
50
|
-
setPassword = _useState6[1];
|
|
51
|
-
var handlePasswordChange = useCallback(function (ev) {
|
|
52
|
-
setPassword(ev.currentTarget.value);
|
|
53
|
-
});
|
|
54
|
-
var unlockVault = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
55
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
56
|
-
while (1) switch (_context.prev = _context.next) {
|
|
57
|
-
case 0:
|
|
58
|
-
setUnlocking(true);
|
|
59
|
-
setError(null);
|
|
60
|
-
_context.prev = 2;
|
|
61
|
-
_context.next = 5;
|
|
62
|
-
return vaultClient.unlock(password);
|
|
63
|
-
case 5:
|
|
64
|
-
if (onUnlock) {
|
|
65
|
-
onUnlock();
|
|
66
|
-
}
|
|
67
|
-
_context.next = 11;
|
|
68
|
-
break;
|
|
69
|
-
case 8:
|
|
70
|
-
_context.prev = 8;
|
|
71
|
-
_context.t0 = _context["catch"](2);
|
|
72
|
-
setError(_context.t0);
|
|
73
|
-
case 11:
|
|
74
|
-
_context.prev = 11;
|
|
75
|
-
setUnlocking(false);
|
|
76
|
-
return _context.finish(11);
|
|
77
|
-
case 14:
|
|
78
|
-
case "end":
|
|
79
|
-
return _context.stop();
|
|
80
|
-
}
|
|
81
|
-
}, _callee, null, [[2, 8, 11, 14]]);
|
|
82
|
-
})), [vaultClient, onUnlock, password]);
|
|
83
|
-
var handleVaultUnlock = useCallback(function (ev) {
|
|
84
|
-
ev.preventDefault();
|
|
85
|
-
unlockVault();
|
|
86
|
-
}, [unlockVault]);
|
|
87
|
-
var getPassphraseResetUrlCb = useMemo(function () {
|
|
88
|
-
return getPassphraseResetUrl(client);
|
|
89
|
-
}, [client]);
|
|
90
28
|
var canAuthWithOIDC = canClientAuthWithOIDC(client);
|
|
91
|
-
var
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
29
|
+
var handleUnlock = useCallback( /*#__PURE__*/function () {
|
|
30
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(password) {
|
|
31
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
32
|
+
while (1) switch (_context.prev = _context.next) {
|
|
33
|
+
case 0:
|
|
34
|
+
setUnlocking(true);
|
|
35
|
+
setError(null);
|
|
36
|
+
_context.prev = 2;
|
|
37
|
+
_context.next = 5;
|
|
38
|
+
return vaultClient.unlock(password);
|
|
39
|
+
case 5:
|
|
40
|
+
if (onUnlock) {
|
|
41
|
+
onUnlock();
|
|
42
|
+
}
|
|
43
|
+
_context.next = 11;
|
|
44
|
+
break;
|
|
45
|
+
case 8:
|
|
46
|
+
_context.prev = 8;
|
|
47
|
+
_context.t0 = _context["catch"](2);
|
|
48
|
+
setError(_context.t0.response.error === 'invalid password' ? 'invalid_password' : 'server_error');
|
|
49
|
+
case 11:
|
|
50
|
+
_context.prev = 11;
|
|
51
|
+
setUnlocking(false);
|
|
52
|
+
return _context.finish(11);
|
|
53
|
+
case 14:
|
|
54
|
+
case "end":
|
|
55
|
+
return _context.stop();
|
|
56
|
+
}
|
|
57
|
+
}, _callee, null, [[2, 8, 11, 14]]);
|
|
58
|
+
}));
|
|
59
|
+
return function (_x) {
|
|
60
|
+
return _ref.apply(this, arguments);
|
|
102
61
|
};
|
|
103
|
-
}, [
|
|
104
|
-
return /*#__PURE__*/React.createElement(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
onSubmit: handleVaultUnlock,
|
|
112
|
-
className: "u-stack-m u-flex u-flex-column u-flex-items-center"
|
|
113
|
-
}, canAuthWithOIDC ? /*#__PURE__*/React.createElement(Icon, {
|
|
114
|
-
icon: KeychainIcon,
|
|
115
|
-
size: 64,
|
|
116
|
-
className: "u-mb-half"
|
|
117
|
-
}) : /*#__PURE__*/React.createElement(CloudIcon, {
|
|
118
|
-
className: "u-mb-half",
|
|
119
|
-
size: 104
|
|
120
|
-
}), /*#__PURE__*/React.createElement(Typography, {
|
|
121
|
-
variant: "h3",
|
|
122
|
-
gutterBottom: true
|
|
123
|
-
}, canAuthWithOIDC ? t('unlock.title-oidc') : t('unlock.title')), error ? /*#__PURE__*/React.createElement(Typography, {
|
|
124
|
-
variant: "body1",
|
|
125
|
-
className: "u-error"
|
|
126
|
-
}, t('unlock.error')) : /*#__PURE__*/React.createElement(Typography, {
|
|
127
|
-
variant: "body1"
|
|
128
|
-
}, t('unlock.subtitle')), /*#__PURE__*/React.createElement(PasswordField, {
|
|
129
|
-
id: "idField",
|
|
130
|
-
label: canAuthWithOIDC ? t('unlock.label-oidc') : t('unlock.label'),
|
|
131
|
-
value: password,
|
|
132
|
-
onChange: handlePasswordChange,
|
|
133
|
-
fullWidth: true,
|
|
134
|
-
className: "u-mt-2"
|
|
135
|
-
}), /*#__PURE__*/React.createElement(Typography, {
|
|
136
|
-
variant: "body1",
|
|
137
|
-
component: "a",
|
|
138
|
-
color: "primary",
|
|
139
|
-
href: getPassphraseResetUrlCb,
|
|
140
|
-
className: "u-link u-mt-1 u-flex-self-start"
|
|
141
|
-
}, t('unlock.forgotten-password'))),
|
|
142
|
-
actions: /*#__PURE__*/React.createElement(Button, {
|
|
143
|
-
onClick: handleVaultUnlock,
|
|
144
|
-
label: t('unlock.unlock'),
|
|
145
|
-
theme: "primary",
|
|
146
|
-
className: cx({
|
|
147
|
-
'u-mt-1': !isMobile,
|
|
148
|
-
'u-mt-auto': isMobile
|
|
149
|
-
}),
|
|
150
|
-
busy: unlocking,
|
|
151
|
-
extension: "full"
|
|
152
|
-
})
|
|
153
|
-
}));
|
|
62
|
+
}(), [vaultClient, onUnlock]);
|
|
63
|
+
return /*#__PURE__*/React.createElement(AuthentificationDialog, {
|
|
64
|
+
onClose: closable ? onDismiss : null,
|
|
65
|
+
onSubmit: handleUnlock,
|
|
66
|
+
isLoading: isUnlocking,
|
|
67
|
+
isOIDC: canAuthWithOIDC,
|
|
68
|
+
error: error
|
|
69
|
+
});
|
|
154
70
|
};
|
|
155
71
|
UnlockForm.propTypes = {
|
|
156
72
|
onDismiss: PropTypes.func.isRequired,
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import
|
|
5
|
-
import { render, fireEvent, act, waitFor } from '@testing-library/react';
|
|
4
|
+
import { render, fireEvent, act, waitFor, screen } from '@testing-library/react';
|
|
6
5
|
import CozyClient, { CozyProvider } from 'cozy-client';
|
|
7
|
-
import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints';
|
|
8
6
|
import I18n from 'cozy-ui/transpiled/react/providers/I18n';
|
|
7
|
+
import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints';
|
|
9
8
|
import { VaultProvider, useVaultClient } from './VaultContext';
|
|
10
|
-
import
|
|
9
|
+
import UnlockForm from './UnlockForm';
|
|
11
10
|
jest.mock('./VaultContext', function () {
|
|
12
11
|
var _jest$requireActual = jest.requireActual('./VaultContext'),
|
|
13
12
|
VaultProvider = _jest$requireActual.VaultProvider;
|
|
@@ -38,13 +37,13 @@ describe('unlock form', function () {
|
|
|
38
37
|
onUnlock = jest.fn();
|
|
39
38
|
root = render( /*#__PURE__*/React.createElement(CozyProvider, {
|
|
40
39
|
client: client
|
|
41
|
-
}, /*#__PURE__*/React.createElement(BreakpointsProvider, null, /*#__PURE__*/React.createElement(
|
|
40
|
+
}, /*#__PURE__*/React.createElement(BreakpointsProvider, null, /*#__PURE__*/React.createElement(VaultProvider, {
|
|
41
|
+
instance: "cozy.tools:8080"
|
|
42
|
+
}, /*#__PURE__*/React.createElement(I18n, {
|
|
42
43
|
dictRequire: function dictRequire() {
|
|
43
|
-
return
|
|
44
|
+
return {};
|
|
44
45
|
},
|
|
45
46
|
lang: "en"
|
|
46
|
-
}, /*#__PURE__*/React.createElement(VaultProvider, {
|
|
47
|
-
instance: "cozy.tools:8080"
|
|
48
47
|
}, /*#__PURE__*/React.createElement(UnlockForm, {
|
|
49
48
|
closable: true,
|
|
50
49
|
onDismiss: jest.fn(),
|
|
@@ -52,7 +51,9 @@ describe('unlock form', function () {
|
|
|
52
51
|
}))))));
|
|
53
52
|
_context3.next = 7;
|
|
54
53
|
return waitFor(function () {
|
|
55
|
-
return
|
|
54
|
+
return screen.getByLabelText(/password/i, {
|
|
55
|
+
selector: 'input'
|
|
56
|
+
});
|
|
56
57
|
});
|
|
57
58
|
case 7:
|
|
58
59
|
password = _context3.sent;
|
|
@@ -5,16 +5,9 @@ import React, { useContext, useState, useEffect } from 'react';
|
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import Spinner from 'cozy-ui/transpiled/react/Spinner';
|
|
7
7
|
import Overlay from 'cozy-ui/transpiled/react/deprecated/Overlay';
|
|
8
|
-
import withLocales from 'cozy-ui/transpiled/react/providers/I18n/withLocales';
|
|
9
|
-
import localesEn from '../locales/en.json';
|
|
10
|
-
import localesFr from '../locales/fr.json';
|
|
11
8
|
import { VaultContext } from './VaultContext';
|
|
12
9
|
import UnlockForm from './UnlockForm';
|
|
13
10
|
import { checkShouldUnlock } from './defaults';
|
|
14
|
-
var locales = {
|
|
15
|
-
en: localesEn,
|
|
16
|
-
fr: localesFr
|
|
17
|
-
};
|
|
18
11
|
var VaultUnlocker = function VaultUnlocker(_ref) {
|
|
19
12
|
var children = _ref.children,
|
|
20
13
|
onDismiss = _ref.onDismiss,
|
|
@@ -98,4 +91,4 @@ VaultUnlocker.propTypes = {
|
|
|
98
91
|
VaultUnlocker.defaultProps = {
|
|
99
92
|
UnlockForm: UnlockForm
|
|
100
93
|
};
|
|
101
|
-
export default
|
|
94
|
+
export default VaultUnlocker;
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"unlock": {
|
|
3
|
-
"title": "Login",
|
|
4
|
-
"title-oidc": "Cozy Pass",
|
|
5
|
-
"subtitle": "For security, please confirm your identity",
|
|
6
|
-
"error": "Incorrect password",
|
|
7
|
-
"label": "Cozy password",
|
|
8
|
-
"label-oidc": "Cozy Pass password",
|
|
9
|
-
"show": "show",
|
|
10
|
-
"hide": "hide",
|
|
11
|
-
"abort": "Leave",
|
|
12
|
-
"unlock": "Unlock",
|
|
13
|
-
"forgotten-password": "I forgot my password"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
{}
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"unlock": {
|
|
3
|
-
"title": "Authentification",
|
|
4
|
-
"title-oidc": "Cozy Pass",
|
|
5
|
-
"subtitle": "Par sécurité, merci de confirmer votre identité",
|
|
6
|
-
"error": "Mot de passe incorrect, essayer à nouveau",
|
|
7
|
-
"label": "Mot de passe Cozy",
|
|
8
|
-
"label-oidc": "Mot de passe Cozy Pass",
|
|
9
|
-
"show": "afficher",
|
|
10
|
-
"hide": "masquer",
|
|
11
|
-
"abort": "Quitter",
|
|
12
|
-
"unlock": "Déverrouiller",
|
|
13
|
-
"forgotten-password": "J'ai oublié mon mot de passe"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
{}
|