cozy-keys-lib 6.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-keys-lib",
3
- "version": "6.0.0",
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": "^3.0.4",
43
- "@semantic-release/git": "^7.0.16",
44
- "@semantic-release/npm": "^5.1.15",
45
- "@testing-library/react": "^11.2.2",
46
- "@testing-library/react-hooks": "^3.2.1",
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": "^1.1.0",
49
- "babel-plugin-mock-imports": "^1.0.2",
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": "^1.6.0",
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": "^2.0.2",
55
- "cozy-ui": "^93.1.1",
56
- "enzyme": "^3.10.0",
57
- "enzyme-adapter-react-16": "^1.14.0",
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": "^1.2.2",
59
+ "eslint-config-cozy-app": "1.6.0",
60
60
  "jest": "26.2.2",
61
- "react": "^16.9.0",
62
- "react-dom": "^16.9.0",
61
+ "react": "16.14.0",
62
+ "react-dom": "16.14.0",
63
63
  "semantic-release": "^15.13.24"
64
64
  },
65
65
  "files": [
@@ -4,12 +4,79 @@ import React from 'react'
4
4
 
5
5
  function SvgIconCozySecurity(props) {
6
6
  return (
7
- <svg width={96} height={64} {...props}>
8
- <path
9
- fill="#FFF"
10
- fillRule="evenodd"
11
- d="M80 32c8.837 0 16 7.163 16 16s-7.163 16-16 16-16-7.163-16-16 7.163-16 16-16zm0 8c-2.206 0-4 1.794-4 4v2h-1c-.552 0-1 .456-1 .995v8.01c0 .55.456.995 1.002.995h9.996c.553 0 1.002-.456 1.002-.995v-8.01A.995.995 0 0085 46h-1v-2c0-2.206-1.795-4-4-4zm0 8.5c.826 0 1.5.672 1.5 1.5 0 .552-.305 1.032-.75 1.29v2.46a.751.751 0 01-1.5 0v-2.46A1.49 1.49 0 0178.5 50a1.5 1.5 0 011.5-1.5zM47.755 0c4.455 0 8.665 1.689 11.85 4.762 2.779 2.679 4.507 6.147 4.97 9.9 8.201.724 14.74 7.229 15.374 15.339L80 30c-9.941 0-18 8.059-18 18H32.946C23.6 48 16 40.507 16 31.297c0-4.393 1.716-8.542 4.833-11.681a16.942 16.942 0 0110.096-4.903c.452-3.772 2.185-7.26 4.975-9.95C39.09 1.689 43.298 0 47.754 0zM80 42c1.103 0 2 1.121 2 2.5V46h-4v-1.5c0-1.379.897-2.5 2-2.5zM55.386 28a1.132 1.132 0 00-1.113 1.154c.011.203.02.3.056.51.04.227.096.46.172.692-3.7 3.16-9.297 3.168-13.007.023.165-.49.233-.942.233-1.234a1.13 1.13 0 00-1.104-1.143 1.136 1.136 0 00-1.157 1.1c0 .11-.04.36-.135.618-.153.419-.41.771-.802 1.017a1.136 1.136 0 00-.333 1.597 1.127 1.127 0 001.538.323 4.21 4.21 0 00.505-.375C42.426 34.054 45.163 35 47.986 35c2.83 0 5.573-.95 7.764-2.73.16.141.332.27.517.387a1.134 1.134 0 001.307-1.848l-.101-.073-.077-.048a1.9 1.9 0 01-.546-.589 2.312 2.312 0 01-.316-1.003A1.128 1.128 0 0055.386 28z"
12
- />
7
+ <svg viewBox="0 0 104 104" fill="none" {...props}>
8
+ <g filter="url(#icon-connect_svg__filter0_ddd_8318_41471)">
9
+ <rect x={16} y={12} width={72} height={72} rx={36} fill="#fff" />
10
+ <path
11
+ d="M28 50.5c0 7.364 5.97 13.333 13.333 13.333h21.334C70.03 63.833 76 57.863 76 50.5c0-6.53-4.693-11.962-10.89-13.11C63.962 31.193 58.53 26.5 52 26.5c-6.53 0-11.962 4.693-13.11 10.89C32.693 38.538 28 43.97 28 50.5z"
12
+ fill="#B3D3FF"
13
+ />
14
+ <path
15
+ fillRule="evenodd"
16
+ clipRule="evenodd"
17
+ d="M54 50.584A5.001 5.001 0 0052 41a5 5 0 00-2 9.584V55a2 2 0 104 0v-4.416z"
18
+ fill="#297EF2"
19
+ />
20
+ </g>
21
+ <defs>
22
+ <filter
23
+ id="icon-connect_svg__filter0_ddd_8318_41471"
24
+ x={0}
25
+ y={0}
26
+ width={104}
27
+ height={104}
28
+ filterUnits="userSpaceOnUse"
29
+ colorInterpolationFilters="sRGB"
30
+ >
31
+ <feFlood floodOpacity={0} result="BackgroundImageFix" />
32
+ <feColorMatrix
33
+ in="SourceAlpha"
34
+ values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
35
+ result="hardAlpha"
36
+ />
37
+ <feOffset dy={4} />
38
+ <feGaussianBlur stdDeviation={8} />
39
+ <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.06 0" />
40
+ <feBlend
41
+ in2="BackgroundImageFix"
42
+ result="effect1_dropShadow_8318_41471"
43
+ />
44
+ <feColorMatrix
45
+ in="SourceAlpha"
46
+ values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
47
+ result="hardAlpha"
48
+ />
49
+ <feOffset dy={2} />
50
+ <feGaussianBlur stdDeviation={2} />
51
+ <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.08 0" />
52
+ <feBlend
53
+ in2="effect1_dropShadow_8318_41471"
54
+ result="effect2_dropShadow_8318_41471"
55
+ />
56
+ <feColorMatrix
57
+ in="SourceAlpha"
58
+ values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
59
+ result="hardAlpha"
60
+ />
61
+ <feMorphology
62
+ radius={0.5}
63
+ operator="dilate"
64
+ in="SourceAlpha"
65
+ result="effect3_dropShadow_8318_41471"
66
+ />
67
+ <feOffset />
68
+ <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.12 0" />
69
+ <feBlend
70
+ in2="effect2_dropShadow_8318_41471"
71
+ result="effect3_dropShadow_8318_41471"
72
+ />
73
+ <feBlend
74
+ in="SourceGraphic"
75
+ in2="effect3_dropShadow_8318_41471"
76
+ result="shape"
77
+ />
78
+ </filter>
79
+ </defs>
13
80
  </svg>
14
81
  )
15
82
  }
@@ -1,30 +1,12 @@
1
- import React, { useState, useCallback, useMemo, useEffect } from 'react'
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 Typography from 'cozy-ui/transpiled/react/Typography'
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 [unlocking, setUnlocking] = useState(false)
24
+ const [isUnlocking, setUnlocking] = useState(false)
45
25
  const [error, setError] = useState(null)
46
- const [password, setPassword] = useState('')
47
-
48
- const handlePasswordChange = useCallback(ev => {
49
- setPassword(ev.currentTarget.value)
50
- })
26
+ const canAuthWithOIDC = canClientAuthWithOIDC(client)
51
27
 
52
- const unlockVault = useCallback(async () => {
53
- setUnlocking(true)
54
- setError(null)
55
- try {
56
- await vaultClient.unlock(password)
57
- if (onUnlock) {
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
- [unlockVault]
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
- <CozyTheme variant="inverted">
108
- <IllustrationDialog
109
- size="small"
110
- open={true}
111
- onClose={closable && onDismiss}
112
- content={
113
- <form
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" />
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 UnlockForm from './UnlockForm'
3
- import { render, fireEvent, act, waitFor } from '@testing-library/react'
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 en from '../locales/en.json'
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
- <I18n dictRequire={() => en} lang="en">
31
- <VaultProvider instance="cozy.tools:8080">
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
- </VaultProvider>
38
- </I18n>
38
+ </I18n>
39
+ </VaultProvider>
39
40
  </BreakpointsProvider>
40
41
  </CozyProvider>
41
42
  )
42
43
 
43
- const password = await waitFor(() => root.getByTestId('password'))
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 withLocales(locales)(VaultUnlocker)
78
+ 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
+ {}
@@ -4,12 +4,80 @@ import _extends from "@babel/runtime/helpers/extends";
4
4
  import React from 'react';
5
5
  function SvgIconCozySecurity(props) {
6
6
  return /*#__PURE__*/React.createElement("svg", _extends({
7
- width: 96,
8
- height: 64
9
- }, props), /*#__PURE__*/React.createElement("path", {
10
- fill: "#FFF",
7
+ viewBox: "0 0 104 104",
8
+ fill: "none"
9
+ }, props), /*#__PURE__*/React.createElement("g", {
10
+ filter: "url(#icon-connect_svg__filter0_ddd_8318_41471)"
11
+ }, /*#__PURE__*/React.createElement("rect", {
12
+ x: 16,
13
+ y: 12,
14
+ width: 72,
15
+ height: 72,
16
+ rx: 36,
17
+ fill: "#fff"
18
+ }), /*#__PURE__*/React.createElement("path", {
19
+ d: "M28 50.5c0 7.364 5.97 13.333 13.333 13.333h21.334C70.03 63.833 76 57.863 76 50.5c0-6.53-4.693-11.962-10.89-13.11C63.962 31.193 58.53 26.5 52 26.5c-6.53 0-11.962 4.693-13.11 10.89C32.693 38.538 28 43.97 28 50.5z",
20
+ fill: "#B3D3FF"
21
+ }), /*#__PURE__*/React.createElement("path", {
11
22
  fillRule: "evenodd",
12
- d: "M80 32c8.837 0 16 7.163 16 16s-7.163 16-16 16-16-7.163-16-16 7.163-16 16-16zm0 8c-2.206 0-4 1.794-4 4v2h-1c-.552 0-1 .456-1 .995v8.01c0 .55.456.995 1.002.995h9.996c.553 0 1.002-.456 1.002-.995v-8.01A.995.995 0 0085 46h-1v-2c0-2.206-1.795-4-4-4zm0 8.5c.826 0 1.5.672 1.5 1.5 0 .552-.305 1.032-.75 1.29v2.46a.751.751 0 01-1.5 0v-2.46A1.49 1.49 0 0178.5 50a1.5 1.5 0 011.5-1.5zM47.755 0c4.455 0 8.665 1.689 11.85 4.762 2.779 2.679 4.507 6.147 4.97 9.9 8.201.724 14.74 7.229 15.374 15.339L80 30c-9.941 0-18 8.059-18 18H32.946C23.6 48 16 40.507 16 31.297c0-4.393 1.716-8.542 4.833-11.681a16.942 16.942 0 0110.096-4.903c.452-3.772 2.185-7.26 4.975-9.95C39.09 1.689 43.298 0 47.754 0zM80 42c1.103 0 2 1.121 2 2.5V46h-4v-1.5c0-1.379.897-2.5 2-2.5zM55.386 28a1.132 1.132 0 00-1.113 1.154c.011.203.02.3.056.51.04.227.096.46.172.692-3.7 3.16-9.297 3.168-13.007.023.165-.49.233-.942.233-1.234a1.13 1.13 0 00-1.104-1.143 1.136 1.136 0 00-1.157 1.1c0 .11-.04.36-.135.618-.153.419-.41.771-.802 1.017a1.136 1.136 0 00-.333 1.597 1.127 1.127 0 001.538.323 4.21 4.21 0 00.505-.375C42.426 34.054 45.163 35 47.986 35c2.83 0 5.573-.95 7.764-2.73.16.141.332.27.517.387a1.134 1.134 0 001.307-1.848l-.101-.073-.077-.048a1.9 1.9 0 01-.546-.589 2.312 2.312 0 01-.316-1.003A1.128 1.128 0 0055.386 28z"
13
- }));
23
+ clipRule: "evenodd",
24
+ d: "M54 50.584A5.001 5.001 0 0052 41a5 5 0 00-2 9.584V55a2 2 0 104 0v-4.416z",
25
+ fill: "#297EF2"
26
+ })), /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("filter", {
27
+ id: "icon-connect_svg__filter0_ddd_8318_41471",
28
+ x: 0,
29
+ y: 0,
30
+ width: 104,
31
+ height: 104,
32
+ filterUnits: "userSpaceOnUse",
33
+ colorInterpolationFilters: "sRGB"
34
+ }, /*#__PURE__*/React.createElement("feFlood", {
35
+ floodOpacity: 0,
36
+ result: "BackgroundImageFix"
37
+ }), /*#__PURE__*/React.createElement("feColorMatrix", {
38
+ in: "SourceAlpha",
39
+ values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0",
40
+ result: "hardAlpha"
41
+ }), /*#__PURE__*/React.createElement("feOffset", {
42
+ dy: 4
43
+ }), /*#__PURE__*/React.createElement("feGaussianBlur", {
44
+ stdDeviation: 8
45
+ }), /*#__PURE__*/React.createElement("feColorMatrix", {
46
+ values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.06 0"
47
+ }), /*#__PURE__*/React.createElement("feBlend", {
48
+ in2: "BackgroundImageFix",
49
+ result: "effect1_dropShadow_8318_41471"
50
+ }), /*#__PURE__*/React.createElement("feColorMatrix", {
51
+ in: "SourceAlpha",
52
+ values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0",
53
+ result: "hardAlpha"
54
+ }), /*#__PURE__*/React.createElement("feOffset", {
55
+ dy: 2
56
+ }), /*#__PURE__*/React.createElement("feGaussianBlur", {
57
+ stdDeviation: 2
58
+ }), /*#__PURE__*/React.createElement("feColorMatrix", {
59
+ values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.08 0"
60
+ }), /*#__PURE__*/React.createElement("feBlend", {
61
+ in2: "effect1_dropShadow_8318_41471",
62
+ result: "effect2_dropShadow_8318_41471"
63
+ }), /*#__PURE__*/React.createElement("feColorMatrix", {
64
+ in: "SourceAlpha",
65
+ values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0",
66
+ result: "hardAlpha"
67
+ }), /*#__PURE__*/React.createElement("feMorphology", {
68
+ radius: 0.5,
69
+ operator: "dilate",
70
+ in: "SourceAlpha",
71
+ result: "effect3_dropShadow_8318_41471"
72
+ }), /*#__PURE__*/React.createElement("feOffset", null), /*#__PURE__*/React.createElement("feColorMatrix", {
73
+ values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.12 0"
74
+ }), /*#__PURE__*/React.createElement("feBlend", {
75
+ in2: "effect2_dropShadow_8318_41471",
76
+ result: "effect3_dropShadow_8318_41471"
77
+ }), /*#__PURE__*/React.createElement("feBlend", {
78
+ in: "SourceGraphic",
79
+ in2: "effect3_dropShadow_8318_41471",
80
+ result: "shape"
81
+ }))));
14
82
  }
15
83
  export default SvgIconCozySecurity;
@@ -1,155 +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, useMemo, useEffect } from 'react';
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 Typography from 'cozy-ui/transpiled/react/Typography';
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
- var getPassphraseResetUrl = function getPassphraseResetUrl(client) {
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
- unlocking = _useState2[0],
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 webviewIntent = useWebviewIntent();
92
- useEffect(function () {
93
- webviewIntent && webviewIntent.call('setFlagshipUI', {
94
- bottomTheme: 'light',
95
- topTheme: 'light'
96
- }, 'cozy-keys-lib/UnlockForm');
97
- return function () {
98
- return webviewIntent && webviewIntent.call('setFlagshipUI', {
99
- bottomTheme: 'light',
100
- topTheme: 'light'
101
- }, 'cozy-keys-lib/UnlockForm');
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
- }, [webviewIntent]);
104
- return /*#__PURE__*/React.createElement(CozyTheme, {
105
- variant: "inverted"
106
- }, /*#__PURE__*/React.createElement(IllustrationDialog, {
107
- size: "small",
108
- open: true,
109
- onClose: closable && onDismiss,
110
- content: /*#__PURE__*/React.createElement("form", {
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
- }), /*#__PURE__*/React.createElement(Typography, {
120
- variant: "h3",
121
- gutterBottom: true
122
- }, canAuthWithOIDC ? t('unlock.title-oidc') : t('unlock.title')), error ? /*#__PURE__*/React.createElement(Typography, {
123
- variant: "body1",
124
- className: "u-error"
125
- }, t('unlock.error')) : /*#__PURE__*/React.createElement(Typography, {
126
- variant: "body1"
127
- }, t('unlock.subtitle')), /*#__PURE__*/React.createElement(PasswordField, {
128
- id: "idField",
129
- label: canAuthWithOIDC ? t('unlock.label-oidc') : t('unlock.label'),
130
- value: password,
131
- onChange: handlePasswordChange,
132
- fullWidth: true,
133
- className: "u-mt-2"
134
- }), /*#__PURE__*/React.createElement(Typography, {
135
- variant: "body1",
136
- component: "a",
137
- color: "primary",
138
- href: getPassphraseResetUrlCb,
139
- className: "u-link u-mt-1 u-flex-self-start"
140
- }, t('unlock.forgotten-password'))),
141
- actions: /*#__PURE__*/React.createElement(Button, {
142
- onClick: handleVaultUnlock,
143
- label: t('unlock.unlock'),
144
- theme: "primary",
145
- className: cx({
146
- 'u-mt-1': !isMobile,
147
- 'u-mt-auto': isMobile
148
- }),
149
- busy: unlocking,
150
- extension: "full"
151
- })
152
- }));
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
+ });
153
70
  };
154
71
  UnlockForm.propTypes = {
155
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 UnlockForm from './UnlockForm';
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 en from '../locales/en.json';
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(I18n, {
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 en;
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 root.getByTestId('password');
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 withLocales(locales)(VaultUnlocker);
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
+ {}