passbolt-styleguide 4.6.2 → 4.7.0-alpha-4
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/build/css/help.min.css +1 -1
- package/build/css/public.min.css +1 -1
- package/build/css/themes/default/api_authentication.min.css +1 -1
- package/build/css/themes/default/api_cloud.min.css +1 -1
- package/build/css/themes/default/api_main.min.css +1 -1
- package/build/css/themes/default/api_reports.min.css +1 -1
- package/build/css/themes/default/api_webinstaller.min.css +1 -1
- package/build/css/themes/default/ext_app.min.css +1 -1
- package/build/css/themes/default/ext_authentication.min.css +1 -1
- package/build/css/themes/default/ext_external.min.css +1 -1
- package/build/css/themes/default/ext_in_form_cta.min.css +1 -1
- package/build/css/themes/default/ext_in_form_menu.min.css +1 -1
- package/build/css/themes/default/ext_quickaccess.min.css +1 -1
- package/build/css/themes/midgar/api_authentication.min.css +1 -1
- package/build/css/themes/midgar/api_main.min.css +1 -1
- package/build/css/themes/midgar/api_reports.min.css +1 -1
- package/build/css/themes/midgar/ext_app.min.css +1 -1
- package/build/css/themes/midgar/ext_authentication.min.css +1 -1
- package/build/css/themes/midgar/ext_in_form_cta.min.css +1 -1
- package/build/css/themes/midgar/ext_in_form_menu.min.css +1 -1
- package/build/css/themes/midgar/ext_quickaccess.min.css +1 -1
- package/build/js/dist/api-account-recovery.js +1 -1
- package/build/js/dist/api-app.js +1 -1
- package/build/js/dist/api-recover.js +1 -1
- package/build/js/dist/api-setup.js +1 -1
- package/build/js/dist/api-triage.js +1 -1
- package/package.json +1 -1
- package/src/react-extension/components/Administration/DisplayUserDirectoryAdministration/DisplayUserDirectoryAdministration.test.data.js +1 -1
- package/src/react-extension/components/Administration/DisplayUserDirectoryAdministration/DisplayUserDirectoryAdministration.test.js +22 -31
- package/src/react-extension/components/Administration/DisplayUserDirectoryAdministration/DisplayUserDirectoryAdministration.test.page.js +5 -9
- package/src/react-extension/contexts/Administration/AdministrationUserDirectory/AdministrationUserDirectoryContext.test.js +1 -1
- package/src/react-extension/contexts/ApiAccountRecoveryContext.js +3 -3
- package/src/react-extension/contexts/ApiAppContext.js +3 -3
- package/src/react-extension/contexts/ApiRecoverContext.js +3 -3
- package/src/react-extension/contexts/ApiSetupContext.js +3 -3
- package/src/shared/lib/apiClient/apiClient.js +11 -4
- package/src/shared/lib/apiClient/apiClient.test.js +20 -1
- package/src/shared/models/entity/abstract/collectionValidationError.js +57 -0
- package/src/shared/models/entity/abstract/entity.test.data.js +98 -0
- package/src/shared/models/entity/abstract/entityCollection.js +28 -3
- package/src/shared/models/entity/abstract/entityCollection.test.js +41 -60
- package/src/shared/models/entity/abstract/entityCollectionError.js +4 -0
- package/src/shared/models/entity/abstract/entityV2Collection.js +108 -0
- package/src/shared/models/entity/abstract/entityV2Collection.test.data.js +48 -0
- package/src/shared/models/entity/abstract/entityV2Collection.test.js +281 -0
- package/src/shared/models/entity/accountRecovery/accountRecoveryPrivateKeyEntity.test.data.js +76 -0
- package/src/shared/models/entity/accountRecovery/accountRecoveryRequestEntity.test.data.js +102 -0
- package/src/shared/models/entity/accountRecovery/accountRecoveryResponseEntity.test.data.js +93 -0
- package/src/shared/models/entity/accountRecovery/accountRecoveryUserSettingEntity.test.data.js +45 -0
- package/src/shared/models/entity/accountRecovery/pendingAccountRecoveryRequestEntity.test.data.js +25 -0
- package/src/shared/models/entity/avatar/avatarEntity.test.data.js +1 -1
- package/src/shared/models/entity/gpgkey/gpgkeyEntity.test.data.js +31 -0
- package/src/shared/models/entity/profile/ProfileEntity.test.data.js +3 -1
- package/src/shared/models/entity/user/groupUserEntity.test.data.js +0 -3
- package/src/shared/models/entity/user/userEntity.test.data.js +47 -16
- package/src/shared/services/api/auth/AuthLogoutService.js +66 -0
- package/src/shared/services/api/auth/{authService.test.js → AuthLogoutService.test.js} +9 -9
- package/src/shared/services/api/auth/AuthService.js +2 -106
- package/test/assert/assertEntityProperty.js +179 -0
- package/test/fixture/pgpKeys/keys.js +419 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passbolt-styleguide",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0-alpha-4",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"copyright": "Copyright 2023 Passbolt SA",
|
|
6
6
|
"description": "Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.",
|
|
@@ -6,7 +6,7 @@ import {TEST_ROLE_ADMIN_ID, TEST_ROLE_USER_ID} from "../../../../shared/models/e
|
|
|
6
6
|
* @param {Object} data The props to override
|
|
7
7
|
* @returns {object}
|
|
8
8
|
*/
|
|
9
|
-
export function defaultProps(data) {
|
|
9
|
+
export function defaultProps(data = {}) {
|
|
10
10
|
const defaultProps = {
|
|
11
11
|
context: defaultAppContext({
|
|
12
12
|
loggedInUser: {
|
|
@@ -18,12 +18,9 @@
|
|
|
18
18
|
import {defaultProps, mockResult, mockUsers} from "./DisplayUserDirectoryAdministration.test.data";
|
|
19
19
|
import DisplayUserDirectoryAdministrationPage from "./DisplayUserDirectoryAdministration.test.page";
|
|
20
20
|
import {waitFor} from "@testing-library/react";
|
|
21
|
-
import {ActionFeedbackContext} from "../../../contexts/ActionFeedbackContext";
|
|
22
|
-
import {defaultAppContext} from "../../../contexts/ApiAppContext.test.data";
|
|
23
21
|
import DisplayTestUserDirectoryAdministration from "../DisplayTestUserDirectoryAdministration/DisplayTestUserDirectoryAdministration";
|
|
24
22
|
import {enableFetchMocks} from 'jest-fetch-mock';
|
|
25
23
|
import {mockApiResponse} from '../../../../../test/mocks/mockApiResponse';
|
|
26
|
-
import {DialogContext} from '../../../contexts/DialogContext';
|
|
27
24
|
import DisplaySynchronizeUserDirectoryAdministration from "../DisplaySynchronizeUserDirectoryAdministration/DisplaySynchronizeUserDirectoryAdministration";
|
|
28
25
|
import DisplaySimulateSynchronizeUserDirectoryAdministration from "../DisplaySimulateSynchronizeUserDirectoryAdministration/DisplaySimulateSynchronizeUserDirectoryAdministration";
|
|
29
26
|
|
|
@@ -39,16 +36,16 @@ const mockApiCalls = (result = mockResult) => {
|
|
|
39
36
|
|
|
40
37
|
describe("As AD I should see the user directory settings", () => {
|
|
41
38
|
let page; // The page to test against
|
|
42
|
-
const context = defaultAppContext(); // The applicative context
|
|
43
39
|
const props = defaultProps(); // The props to pass
|
|
44
40
|
|
|
45
41
|
describe('As AD I should see the user directory activation state on the administration settings page', () => {
|
|
46
42
|
/**
|
|
47
43
|
* I should see the User Directory activation state on the administration settings page
|
|
48
44
|
*/
|
|
49
|
-
beforeEach(() => {
|
|
45
|
+
beforeEach(async() => {
|
|
50
46
|
mockApiCalls();
|
|
51
|
-
page = new DisplayUserDirectoryAdministrationPage(
|
|
47
|
+
page = new DisplayUserDirectoryAdministrationPage(props);
|
|
48
|
+
await waitFor(() => {});
|
|
52
49
|
});
|
|
53
50
|
|
|
54
51
|
it('As AD I should see if the User Directory is enabled on my Passbolt instance', async() => {
|
|
@@ -112,13 +109,13 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
112
109
|
|
|
113
110
|
//Call to save the settings
|
|
114
111
|
fetch.doMockOnceIf(/directorysync\/settings\/test*/, () => mockApiResponse(mockResult));
|
|
115
|
-
jest.spyOn(
|
|
112
|
+
jest.spyOn(props.dialogContext, 'open').mockImplementationOnce(jest.fn);
|
|
116
113
|
|
|
117
114
|
// Click on test button
|
|
118
115
|
await page.testSettings();
|
|
119
116
|
|
|
120
|
-
expect(
|
|
121
|
-
expect(context.setContext).toHaveBeenCalledWith({displayTestUserDirectoryDialogProps: {userDirectoryTestResult: mockResult}});
|
|
117
|
+
expect(props.dialogContext.open).toHaveBeenCalledWith(DisplayTestUserDirectoryAdministration);
|
|
118
|
+
expect(props.context.setContext).toHaveBeenCalledWith({displayTestUserDirectoryDialogProps: {userDirectoryTestResult: mockResult}});
|
|
122
119
|
});
|
|
123
120
|
|
|
124
121
|
|
|
@@ -139,10 +136,10 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
139
136
|
//button should be enable with the changes
|
|
140
137
|
expect(page.isSaveButtonEnabled()).toBeTruthy();
|
|
141
138
|
|
|
142
|
-
jest.spyOn(
|
|
139
|
+
jest.spyOn(props.actionFeedbackContext, 'displaySuccess').mockImplementation(() => {});
|
|
143
140
|
await page.saveSettings();
|
|
144
141
|
|
|
145
|
-
expect(
|
|
142
|
+
expect(props.actionFeedbackContext.displaySuccess).toHaveBeenCalledWith("The user directory settings for the organization were updated.");
|
|
146
143
|
expect(page.isSaveButtonEnabled()).toBeFalsy();
|
|
147
144
|
//Simulate buttons and synchronize buttons should be enable
|
|
148
145
|
expect(page.isSynchronizeButtonEnabled()).toBeTruthy();
|
|
@@ -163,7 +160,7 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
163
160
|
|
|
164
161
|
await page.click(page.userDirectory);
|
|
165
162
|
|
|
166
|
-
jest.spyOn(
|
|
163
|
+
jest.spyOn(props.actionFeedbackContext, 'displaySuccess').mockImplementation(() => {});
|
|
167
164
|
await page.saveSettings();
|
|
168
165
|
|
|
169
166
|
expect(page.userDirectory.checked).toBeFalsy();
|
|
@@ -175,7 +172,7 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
175
172
|
expect(page.password).toBeNull();
|
|
176
173
|
expect(page.domainName).toBeNull();
|
|
177
174
|
expect(page.baseDn).toBeNull();
|
|
178
|
-
expect(
|
|
175
|
+
expect(props.actionFeedbackContext.displaySuccess).toHaveBeenCalledWith("The user directory settings for the organization were updated.");
|
|
179
176
|
//Simulate buttons and synchronize buttons should not be enable
|
|
180
177
|
expect(page.isSynchronizeButtonEnabled()).toBeFalsy();
|
|
181
178
|
expect(page.isSimulateButtonEnabled()).toBeFalsy();
|
|
@@ -246,12 +243,12 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
246
243
|
|
|
247
244
|
fetch.doMockOnceIf(/directorysync*/, () => Promise.reject(error));
|
|
248
245
|
|
|
249
|
-
jest.spyOn(
|
|
246
|
+
jest.spyOn(props.actionFeedbackContext, 'displayError').mockImplementation(() => {});
|
|
250
247
|
await page.saveSettings();
|
|
251
248
|
|
|
252
249
|
await waitFor(() => {});
|
|
253
250
|
// Throw general error message
|
|
254
|
-
expect(
|
|
251
|
+
expect(props.actionFeedbackContext.displayError).toHaveBeenCalledWith(error.message);
|
|
255
252
|
});
|
|
256
253
|
|
|
257
254
|
it('As AD I should be able to simulate the synchronization', async() => {
|
|
@@ -264,12 +261,12 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
264
261
|
//Call to save the settings
|
|
265
262
|
fetch.doMockOnceIf(/directorysync*/, () => mockApiResponse(mockResult));
|
|
266
263
|
fetch.doMockOnceIf(/users*/, () => mockApiResponse(mockUsers));
|
|
267
|
-
jest.spyOn(
|
|
264
|
+
jest.spyOn(props.dialogContext, 'open').mockImplementationOnce(jest.fn);
|
|
268
265
|
|
|
269
266
|
// Click on simulate button
|
|
270
267
|
await page.simulateSettings();
|
|
271
268
|
|
|
272
|
-
expect(
|
|
269
|
+
expect(props.dialogContext.open).toHaveBeenCalledWith(DisplaySimulateSynchronizeUserDirectoryAdministration);
|
|
273
270
|
});
|
|
274
271
|
|
|
275
272
|
it('As AD I should be able to synchronize the users', async() => {
|
|
@@ -283,12 +280,12 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
283
280
|
fetch.doMockOnceIf(/directorysync\/synchronize*/, () => mockApiResponse(mockResult));
|
|
284
281
|
fetch.doMockOnceIf(/users*/, () => mockApiResponse(mockUsers));
|
|
285
282
|
|
|
286
|
-
jest.spyOn(
|
|
283
|
+
jest.spyOn(props.dialogContext, 'open').mockImplementationOnce(jest.fn);
|
|
287
284
|
|
|
288
285
|
// Click on synchronize button
|
|
289
286
|
await page.synchronizeSettings();
|
|
290
287
|
|
|
291
|
-
expect(
|
|
288
|
+
expect(props.dialogContext.open).toHaveBeenCalledWith(DisplaySynchronizeUserDirectoryAdministration);
|
|
292
289
|
});
|
|
293
290
|
|
|
294
291
|
it('As AD I should see the synchronize popup when requested by simulate', async() => {
|
|
@@ -303,14 +300,12 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
303
300
|
fetch.doMockOnceIf(/directorysync\/synchronize*/, () => mockApiResponse(mockResult));
|
|
304
301
|
fetch.doMockOnceIf(/users*/, () => mockApiResponse(mockUsers));
|
|
305
302
|
|
|
306
|
-
jest.spyOn(
|
|
303
|
+
jest.spyOn(props.dialogContext, 'open').mockImplementationOnce(jest.fn);
|
|
307
304
|
|
|
308
305
|
// Click on synchronize button
|
|
309
306
|
await page.simulateSettings();
|
|
310
307
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
expect(DialogContext._currentValue.open).toHaveBeenCalledWith(DisplaySynchronizeUserDirectoryAdministration);
|
|
308
|
+
expect(props.dialogContext.open).toHaveBeenCalledWith(DisplaySynchronizeUserDirectoryAdministration);
|
|
314
309
|
});
|
|
315
310
|
});
|
|
316
311
|
|
|
@@ -324,12 +319,11 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
324
319
|
expect.assertions(1);
|
|
325
320
|
await waitFor(() => {});
|
|
326
321
|
|
|
327
|
-
const context = defaultAppContext(); // The applicative context
|
|
328
322
|
const props = defaultProps(); // The props to pass
|
|
329
323
|
mockResult.source = "db";
|
|
330
324
|
mockApiCalls(mockResult);
|
|
331
325
|
|
|
332
|
-
const page = new DisplayUserDirectoryAdministrationPage(
|
|
326
|
+
const page = new DisplayUserDirectoryAdministrationPage(props);
|
|
333
327
|
await waitFor(() => {});
|
|
334
328
|
|
|
335
329
|
expect(page.settingsSource.textContent).toStrictEqual("This current configuration source is: database.");
|
|
@@ -338,12 +332,11 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
338
332
|
it('::when the source is file', async() => {
|
|
339
333
|
expect.assertions(1);
|
|
340
334
|
|
|
341
|
-
const context = defaultAppContext(); // The applicative context
|
|
342
335
|
const props = defaultProps(); // The props to pass
|
|
343
336
|
mockResult.source = "file";
|
|
344
337
|
mockApiCalls(mockResult);
|
|
345
338
|
|
|
346
|
-
const page = new DisplayUserDirectoryAdministrationPage(
|
|
339
|
+
const page = new DisplayUserDirectoryAdministrationPage(props);
|
|
347
340
|
await waitFor(() => {});
|
|
348
341
|
|
|
349
342
|
expect(page.settingsSource.textContent).toStrictEqual("This current configuration source is: file.");
|
|
@@ -352,12 +345,11 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
352
345
|
it('::when the source is env', async() => {
|
|
353
346
|
expect.assertions(1);
|
|
354
347
|
|
|
355
|
-
const context = defaultAppContext(); // The applicative context
|
|
356
348
|
const props = defaultProps(); // The props to pass
|
|
357
349
|
mockResult.source = "env";
|
|
358
350
|
mockApiCalls(mockResult);
|
|
359
351
|
|
|
360
|
-
const page = new DisplayUserDirectoryAdministrationPage(
|
|
352
|
+
const page = new DisplayUserDirectoryAdministrationPage(props);
|
|
361
353
|
await waitFor(() => {});
|
|
362
354
|
|
|
363
355
|
expect(page.settingsSource.textContent).toStrictEqual("This current configuration source is: environment variables.");
|
|
@@ -366,12 +358,11 @@ describe("As AD I should see the user directory settings", () => {
|
|
|
366
358
|
it('::when the source is env', async() => {
|
|
367
359
|
expect.assertions(1);
|
|
368
360
|
|
|
369
|
-
const context = defaultAppContext(); // The applicative context
|
|
370
361
|
const props = defaultProps(); // The props to pass
|
|
371
362
|
mockResult.source = "something-unsupported";
|
|
372
363
|
mockApiCalls(mockResult);
|
|
373
364
|
|
|
374
|
-
const page = new DisplayUserDirectoryAdministrationPage(
|
|
365
|
+
const page = new DisplayUserDirectoryAdministrationPage(props);
|
|
375
366
|
await waitFor(() => {});
|
|
376
367
|
|
|
377
368
|
expect(page.settingsSource.textContent).toStrictEqual("This current configuration source is: unknown.");
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
* @since 2.11.0
|
|
13
13
|
*/
|
|
14
14
|
import {fireEvent, render, waitFor} from "@testing-library/react";
|
|
15
|
-
import AppContext from "../../../../shared/context/AppContext/AppContext";
|
|
16
15
|
import React from "react";
|
|
17
16
|
import DisplayUserDirectoryAdministration from "./DisplayUserDirectoryAdministration";
|
|
18
17
|
import MockTranslationProvider from "../../../test/mock/components/Internationalisation/MockTranslationProvider";
|
|
@@ -25,18 +24,15 @@ import {AdminUserDirectoryContextProvider} from "../../../contexts/Administratio
|
|
|
25
24
|
export default class DisplayUserDirectoryAdministrationPage {
|
|
26
25
|
/**
|
|
27
26
|
* Default constructor
|
|
28
|
-
* @param appContext An app context
|
|
29
27
|
* @param props Props to attach
|
|
30
28
|
*/
|
|
31
|
-
constructor(
|
|
29
|
+
constructor(props) {
|
|
32
30
|
this._page = render(
|
|
33
31
|
<MockTranslationProvider>
|
|
34
|
-
<
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
</AdminUserDirectoryContextProvider>
|
|
39
|
-
</AppContext.Provider>
|
|
32
|
+
<AdminUserDirectoryContextProvider context={props.context}>
|
|
33
|
+
<DisplayAdministrationUserDirectoryActions {...props}/>
|
|
34
|
+
<DisplayUserDirectoryAdministration {...props}/>
|
|
35
|
+
</AdminUserDirectoryContextProvider>
|
|
40
36
|
</MockTranslationProvider>
|
|
41
37
|
);
|
|
42
38
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @since 3.8.0
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {defaultProps} from "
|
|
15
|
+
import {defaultProps} from "../../../components/Administration/DisplayUserDirectoryAdministration/DisplayUserDirectoryAdministration.test.data";
|
|
16
16
|
import {enableFetchMocks} from 'jest-fetch-mock';
|
|
17
17
|
import {AdminUserDirectoryContextProvider} from "./AdministrationUserDirectoryContext";
|
|
18
18
|
import {mockApiResponse, mockApiResponseError} from '../../../../../test/mocks/mockApiResponse';
|
|
@@ -18,7 +18,7 @@ import {withAppContext} from "../../shared/context/AppContext/AppContext";
|
|
|
18
18
|
import {ApiClient} from "../../shared/lib/apiClient/apiClient";
|
|
19
19
|
import PassboltApiFetchError from "../../shared/lib/Error/PassboltApiFetchError";
|
|
20
20
|
import PassboltServiceUnavailableError from "../../shared/lib/Error/PassboltServiceUnavailableError";
|
|
21
|
-
import
|
|
21
|
+
import AuthLogoutService from "../../shared/services/api/auth/AuthLogoutService";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* The ApiAccountRecovery context.
|
|
@@ -48,7 +48,7 @@ export class ApiAccountRecoveryContextProvider extends React.Component {
|
|
|
48
48
|
constructor(props) {
|
|
49
49
|
super(props);
|
|
50
50
|
this.state = Object.assign(this.defaultState, props.value);
|
|
51
|
-
this.
|
|
51
|
+
this.authLogoutService = new AuthLogoutService(props.context.getApiClientOptions());
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -119,7 +119,7 @@ export class ApiAccountRecoveryContextProvider extends React.Component {
|
|
|
119
119
|
*/
|
|
120
120
|
async logoutUserAndRefresh() {
|
|
121
121
|
try {
|
|
122
|
-
await this.
|
|
122
|
+
await this.authLogoutService.logout();
|
|
123
123
|
} catch (e) {
|
|
124
124
|
const error = new PassboltServiceUnavailableError(e.message);
|
|
125
125
|
return this.setState({unexpectedError: error, state: ApiAccountRecoveryContextState.UNEXPECTED_ERROR_STATE});
|
|
@@ -21,7 +21,7 @@ import PassboltApiFetchError from "../../shared/lib/Error/PassboltApiFetchError"
|
|
|
21
21
|
import PassboltSubscriptionError from "../lib/Error/PassboltSubscriptionError";
|
|
22
22
|
import RbacMeService from "../../shared/services/api/rbac/rbacMeService";
|
|
23
23
|
import RbacsCollection from "../../shared/models/entity/rbac/rbacsCollection";
|
|
24
|
-
import
|
|
24
|
+
import AuthLogoutService from "../../shared/services/api/auth/AuthLogoutService";
|
|
25
25
|
|
|
26
26
|
const IS_AUTHENTICATED_CHECK_PERIOD = 60000;
|
|
27
27
|
|
|
@@ -32,7 +32,7 @@ class ApiAppContextProvider extends React.Component {
|
|
|
32
32
|
constructor(props) {
|
|
33
33
|
super(props);
|
|
34
34
|
this.state = this.defaultState;
|
|
35
|
-
this.
|
|
35
|
+
this.authLogoutService = new AuthLogoutService(this.getApiClientOptions());
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -214,7 +214,7 @@ class ApiAppContextProvider extends React.Component {
|
|
|
214
214
|
* Listen when the user wants to logout.
|
|
215
215
|
*/
|
|
216
216
|
async onLogoutRequested() {
|
|
217
|
-
await this.
|
|
217
|
+
await this.authLogoutService.logout();
|
|
218
218
|
window.location.href = this.state.trustedDomain;
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -18,7 +18,7 @@ import {ApiClient} from "../../shared/lib/apiClient/apiClient";
|
|
|
18
18
|
import {BROWSER_NAMES, detectBrowserName} from "../../shared/lib/Browser/detectBrowserName";
|
|
19
19
|
import PassboltApiFetchError from "../../shared/lib/Error/PassboltApiFetchError";
|
|
20
20
|
import PassboltServiceUnavailableError from "../../shared/lib/Error/PassboltServiceUnavailableError";
|
|
21
|
-
import
|
|
21
|
+
import AuthLogoutService from "../../shared/services/api/auth/AuthLogoutService";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* The Api recover context.
|
|
@@ -48,7 +48,7 @@ class ApiRecoverContextProvider extends React.Component {
|
|
|
48
48
|
constructor(props) {
|
|
49
49
|
super(props);
|
|
50
50
|
this.state = Object.assign(this.defaultState, props.value);
|
|
51
|
-
this.
|
|
51
|
+
this.authLogoutService = new AuthLogoutService(props.context.getApiClientOptions());
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -120,7 +120,7 @@ class ApiRecoverContextProvider extends React.Component {
|
|
|
120
120
|
*/
|
|
121
121
|
async logoutUserAndRefresh() {
|
|
122
122
|
try {
|
|
123
|
-
await this.
|
|
123
|
+
await this.authLogoutService.logout();
|
|
124
124
|
} catch (e) {
|
|
125
125
|
const error = new PassboltServiceUnavailableError(e.message);
|
|
126
126
|
return this.setState({unexpectedError: error, state: ApiRecoverContextState.UNEXPECTED_ERROR_STATE});
|
|
@@ -18,7 +18,7 @@ import {ApiClient} from "../../shared/lib/apiClient/apiClient";
|
|
|
18
18
|
import {BROWSER_NAMES, detectBrowserName} from "../../shared/lib/Browser/detectBrowserName";
|
|
19
19
|
import PassboltApiFetchError from "../../shared/lib/Error/PassboltApiFetchError";
|
|
20
20
|
import PassboltServiceUnavailableError from "../../shared/lib/Error/PassboltServiceUnavailableError";
|
|
21
|
-
import
|
|
21
|
+
import AuthLogoutService from "../../shared/services/api/auth/AuthLogoutService";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* The Api setup context.
|
|
@@ -48,7 +48,7 @@ class ApiSetupContextProvider extends React.Component {
|
|
|
48
48
|
constructor(props) {
|
|
49
49
|
super(props);
|
|
50
50
|
this.state = Object.assign(this.defaultState, props.value);
|
|
51
|
-
this.
|
|
51
|
+
this.authLogoutService = new AuthLogoutService(props.context.getApiClientOptions());
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -96,7 +96,7 @@ class ApiSetupContextProvider extends React.Component {
|
|
|
96
96
|
*/
|
|
97
97
|
async logoutUserAndRefresh() {
|
|
98
98
|
try {
|
|
99
|
-
await this.
|
|
99
|
+
await this.authLogoutService.logout();
|
|
100
100
|
} catch (e) {
|
|
101
101
|
const error = new PassboltServiceUnavailableError(e.message);
|
|
102
102
|
return this.setState({unexpectedError: error, state: ApiSetupContextState.UNEXPECTED_ERROR_STATE});
|
|
@@ -141,7 +141,7 @@ export class ApiClient {
|
|
|
141
141
|
*/
|
|
142
142
|
async findAll(urlOptions) {
|
|
143
143
|
const url = this.buildUrl(this.baseUrl.toString(), urlOptions || {});
|
|
144
|
-
return
|
|
144
|
+
return this.fetchAndHandleResponse('GET', url);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/**
|
|
@@ -382,20 +382,27 @@ export class ApiClient {
|
|
|
382
382
|
* @public
|
|
383
383
|
*/
|
|
384
384
|
async fetchAndHandleResponse(method, url, body, options) {
|
|
385
|
-
let responseJson;
|
|
386
385
|
const response = await this.sendRequest(method, url, body, options);
|
|
386
|
+
return this.parseResponseJson(response);
|
|
387
|
+
}
|
|
387
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Parse the response into json
|
|
391
|
+
* @param {Response} response Fetch response
|
|
392
|
+
* @return {Promise<object>}
|
|
393
|
+
*/
|
|
394
|
+
async parseResponseJson(response) {
|
|
395
|
+
let responseJson;
|
|
388
396
|
try {
|
|
389
397
|
responseJson = await response.json();
|
|
390
398
|
} catch (error) {
|
|
391
|
-
console.debug(url.toString(), error);
|
|
399
|
+
console.debug(response.url.toString(), error);
|
|
392
400
|
/*
|
|
393
401
|
* If the response cannot be parsed, it's not a Passbolt API response.
|
|
394
402
|
* It can be a for example a proxy timeout error (504).
|
|
395
403
|
*/
|
|
396
404
|
throw new PassboltBadResponseError(error, response);
|
|
397
405
|
}
|
|
398
|
-
|
|
399
406
|
if (!response.ok) {
|
|
400
407
|
const message = responseJson.header.message;
|
|
401
408
|
throw new PassboltApiFetchError(message, {
|
|
@@ -80,6 +80,25 @@ describe("Unit testing apiClient with mocked fetch", () => {
|
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
+
it("Should call the endpoint with form data body and return the response as-is with sendRequest", async() => {
|
|
84
|
+
expect.assertions(4);
|
|
85
|
+
const testClient = new ApiClient(options);
|
|
86
|
+
|
|
87
|
+
const currentUrl = new URL(url);
|
|
88
|
+
const spyOnAssertUrl = jest.spyOn(testClient, "assertUrl");
|
|
89
|
+
const spyOnAssertMethod = jest.spyOn(testClient, "assertMethod");
|
|
90
|
+
const spyOnAssertBody = jest.spyOn(testClient, "assertBody");
|
|
91
|
+
const body = new FormData();
|
|
92
|
+
body.append('data[test]', "test");
|
|
93
|
+
|
|
94
|
+
fetch.mockResponseOnce(async() => responseJson);
|
|
95
|
+
const result = await testClient.sendRequest("POST", currentUrl, body);
|
|
96
|
+
expect(result.text()).resolves.toStrictEqual(responseJson);
|
|
97
|
+
expect(spyOnAssertUrl).toHaveBeenLastCalledWith(currentUrl);
|
|
98
|
+
expect(spyOnAssertMethod).toHaveBeenLastCalledWith("POST");
|
|
99
|
+
expect(spyOnAssertBody).toHaveBeenCalledWith(body);
|
|
100
|
+
});
|
|
101
|
+
|
|
83
102
|
each([
|
|
84
103
|
{responseBody: responseJson, method: "GET"},
|
|
85
104
|
{responseBody: responseJson, method: "POST"},
|
|
@@ -365,7 +384,7 @@ describe("Unit testing apiClient with mocked fetch", () => {
|
|
|
365
384
|
each([
|
|
366
385
|
{body: JSON.stringify({string: 'string', object: {}, array: []})},
|
|
367
386
|
{body: uuid()},
|
|
368
|
-
]).describe("should send the given body if it is a string", scenario => {
|
|
387
|
+
]).describe("should send the given body if it is a string or a form data", scenario => {
|
|
369
388
|
it(`scenario: ${JSON.stringify(scenario)}`, async() => {
|
|
370
389
|
expect.assertions(5);
|
|
371
390
|
const testClient = new ApiClient(options);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passbolt ~ Open source password manager for teams
|
|
3
|
+
* Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
4
|
+
*
|
|
5
|
+
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
|
6
|
+
* For full copyright and license information, please see the LICENSE.txt
|
|
7
|
+
* Redistributions of files must retain the above copyright notice.
|
|
8
|
+
*
|
|
9
|
+
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
10
|
+
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
|
11
|
+
* @link https://www.passbolt.com Passbolt(tm)
|
|
12
|
+
* @since 4.7.0
|
|
13
|
+
*/
|
|
14
|
+
import EntityValidationError from "./entityValidationError";
|
|
15
|
+
|
|
16
|
+
class CollectionValidationError extends Error {
|
|
17
|
+
/**
|
|
18
|
+
* CollectionValidationError constructor
|
|
19
|
+
*
|
|
20
|
+
* @param {string} message
|
|
21
|
+
*/
|
|
22
|
+
constructor(message = 'Collection validation error.') {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'CollectionValidationError';
|
|
25
|
+
this.items = [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Add a given an error for a given property and rule
|
|
30
|
+
*
|
|
31
|
+
* @param {number} position The index of the collection the error occurred.
|
|
32
|
+
* @param {EntityValidationError|CollectionValidationError} validationError The entity or collection validation error.
|
|
33
|
+
*/
|
|
34
|
+
addEntityValidationError(position, validationError) {
|
|
35
|
+
if (!Number.isInteger(position)) {
|
|
36
|
+
throw new TypeError('CollectionValidationError addEntityValidationError expects "position" to be an integer.');
|
|
37
|
+
}
|
|
38
|
+
if (!(validationError instanceof EntityValidationError) && !(validationError instanceof CollectionValidationError)) {
|
|
39
|
+
throw new TypeError('CollectionValidationError addEntityValidationError expects "entityValidationError" to be an instance of EntityValidationError or CollectionValidationError.');
|
|
40
|
+
}
|
|
41
|
+
this.items[position] = validationError;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Return the error in the details expected format.
|
|
46
|
+
* @return {array}
|
|
47
|
+
*/
|
|
48
|
+
get details() {
|
|
49
|
+
const details = [];
|
|
50
|
+
for (const itemPosition in this.items) {
|
|
51
|
+
details[itemPosition] = this.items[itemPosition].details;
|
|
52
|
+
}
|
|
53
|
+
return details;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default CollectionValidationError;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passbolt ~ Open source password manager for teams
|
|
3
|
+
* Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
4
|
+
*
|
|
5
|
+
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
|
6
|
+
* For full copyright and license information, please see the LICENSE.txt
|
|
7
|
+
* Redistributions of files must retain the above copyright notice.
|
|
8
|
+
*
|
|
9
|
+
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
10
|
+
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
|
11
|
+
* @link https://www.passbolt.com Passbolt(tm)
|
|
12
|
+
* @since 4.7.0
|
|
13
|
+
*/
|
|
14
|
+
import {v4 as uuid} from "uuid";
|
|
15
|
+
import Entity from "./entity";
|
|
16
|
+
import EntitySchema from "./entitySchema";
|
|
17
|
+
|
|
18
|
+
export class TestEntity extends Entity {
|
|
19
|
+
constructor(dto, options = {}) {
|
|
20
|
+
super(EntitySchema.validate(TestEntity.name, dto, TestEntity.getSchema()), options);
|
|
21
|
+
// Association manual process
|
|
22
|
+
if (this._props.associated_entity) {
|
|
23
|
+
this._groups_users = new TestAssociatedEntity(this._props.associated_entity, {...options, clone: false});
|
|
24
|
+
delete this._props.associated_entity;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static getSchema() {
|
|
29
|
+
return {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"required": [],
|
|
32
|
+
"properties": {
|
|
33
|
+
"id": {
|
|
34
|
+
"anyOf": [{
|
|
35
|
+
"type": "string",
|
|
36
|
+
"format": "uuid"
|
|
37
|
+
}, {
|
|
38
|
+
"type": "null"
|
|
39
|
+
}],
|
|
40
|
+
},
|
|
41
|
+
"name": {
|
|
42
|
+
"anyOf": [{
|
|
43
|
+
"type": "string"
|
|
44
|
+
}, {
|
|
45
|
+
"type": "null"
|
|
46
|
+
}],
|
|
47
|
+
},
|
|
48
|
+
"associated_entity": TestAssociatedEntity.getSchema()
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get id() {
|
|
54
|
+
return this._props.id;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get name() {
|
|
58
|
+
return this._props.name;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class TestAssociatedEntity extends Entity {
|
|
63
|
+
constructor(dto, options = {}) {
|
|
64
|
+
super(EntitySchema.validate(TestAssociatedEntity.name, dto, TestAssociatedEntity.getSchema()), options);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static getSchema() {
|
|
68
|
+
return {
|
|
69
|
+
"type": "object",
|
|
70
|
+
"required": [],
|
|
71
|
+
"properties": {
|
|
72
|
+
"id": {
|
|
73
|
+
"anyOf": [{
|
|
74
|
+
"type": "string",
|
|
75
|
+
"format": "uuid"
|
|
76
|
+
}, {
|
|
77
|
+
"type": "null"
|
|
78
|
+
}],
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get id() {
|
|
85
|
+
return this._props.id;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const defaultTestEntityDto = data => ({
|
|
90
|
+
id: uuid(),
|
|
91
|
+
name: "test name",
|
|
92
|
+
...data
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export const defaultAssociatedTestEntityDto = data => ({
|
|
96
|
+
id: uuid(),
|
|
97
|
+
...data
|
|
98
|
+
});
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* @since 2.13.0
|
|
13
13
|
*/
|
|
14
14
|
import EntityCollectionError from "./entityCollectionError";
|
|
15
|
+
import EntityValidationError from "./entityValidationError";
|
|
15
16
|
|
|
16
17
|
class EntityCollection {
|
|
17
18
|
/**
|
|
@@ -241,14 +242,38 @@ class EntityCollection {
|
|
|
241
242
|
assertUniqueByProperty(propName, message) {
|
|
242
243
|
const ruleId = `unique_${propName}`;
|
|
243
244
|
const propValues = this.extract(propName);
|
|
245
|
+
// Set is the preferred approach for performance reasons, it does a deduplicate in 0n.
|
|
246
|
+
const uniqueElements = new Set();
|
|
244
247
|
message = message || `The collection should only contain items with unique values for the property: ${propName}.`;
|
|
245
|
-
propValues.forEach((
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
+
propValues.forEach((propValue, index) => {
|
|
249
|
+
uniqueElements.add(propValue);
|
|
250
|
+
if (index !== uniqueElements.size - 1) {
|
|
248
251
|
throw new EntityCollectionError(index, ruleId, message);
|
|
249
252
|
}
|
|
250
253
|
});
|
|
251
254
|
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Assert that no item in the collection already has the given value for the given property.
|
|
258
|
+
* @param {string} propName The property name for checking value uniqueness.
|
|
259
|
+
* @param {string|boolean|number} propValue The property value for checking value uniqueness.
|
|
260
|
+
* @param {string} [message] The error message. If none given, it will fallback on a default one.
|
|
261
|
+
* @throw {EntityValidationError} If another item already has the given value for the given property.
|
|
262
|
+
*/
|
|
263
|
+
assertNotExist(propName, propValue, message) {
|
|
264
|
+
const propValues = this.extract(propName);
|
|
265
|
+
// Set is the preferred approach for performance reasons, it does a deduplicate in 0n.
|
|
266
|
+
const uniqueElements = new Set(propValues);
|
|
267
|
+
const sizeBefore = uniqueElements.size;
|
|
268
|
+
uniqueElements.add(propValue);
|
|
269
|
+
|
|
270
|
+
if (sizeBefore === uniqueElements.size) {
|
|
271
|
+
const error = new EntityValidationError();
|
|
272
|
+
message = message || `The collection already includes an element that has a property (${propName}) with an identical value.`;
|
|
273
|
+
error.addError(propName, 'unique', message);
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
252
277
|
}
|
|
253
278
|
|
|
254
279
|
export default EntityCollection;
|