passbolt-browser-extension 5.12.1 → 5.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/.devcontainer/safe-chain-config.json +2 -1
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +30 -22
  3. package/.github/ISSUE_TEMPLATE/config.yml +11 -0
  4. package/.jpmignore +0 -1
  5. package/CHANGELOG.md +82 -1
  6. package/CONTRIBUTING.md +1 -12
  7. package/README.md +5 -16
  8. package/RELEASE_NOTES.md +2 -3
  9. package/SECURITY.md +7 -0
  10. package/i18next.config.js +28 -0
  11. package/jest.config.json +1 -0
  12. package/package.json +20 -40
  13. package/src/all/background_page/controller/accountRecovery/reviewRequestController.test.js +1 -1
  14. package/src/all/background_page/{event → controller/actionLog}/findAllForActionLogController.js +1 -1
  15. package/src/all/background_page/{event → controller/actionLog}/findAllForActionLogController.test.js +4 -4
  16. package/src/all/background_page/controller/export/exportResourcesFileController.test.js +7 -2
  17. package/src/all/background_page/controller/folder/folderCreateController.js +3 -1
  18. package/src/all/background_page/controller/group/findMyGroupsController.test.js +2 -2
  19. package/src/all/background_page/controller/group/getOrFindGroupsController.js +61 -0
  20. package/src/all/background_page/controller/group/getOrFindGroupsController.test.js +69 -0
  21. package/src/all/background_page/controller/group/getOrFindGroupsUsersController.js +62 -0
  22. package/src/all/background_page/controller/group/getOrFindGroupsUsersController.test.js +69 -0
  23. package/src/all/background_page/controller/group/groupCreateController.js +1 -1
  24. package/src/all/background_page/controller/group/groupCreateController.test.js +1 -1
  25. package/src/all/background_page/controller/group/groupUpdateController.js +1 -1
  26. package/src/all/background_page/controller/group/updateAllGroupsLocalStorageController.test.js +1 -1
  27. package/src/all/background_page/controller/keyring/synchroniseKeyringController.js +51 -0
  28. package/src/all/background_page/controller/keyring/synchroniseKeyringController.test.js +49 -0
  29. package/src/all/background_page/controller/metadata/shareMetadataKeyPrivateController.test.js +1 -1
  30. package/src/all/background_page/controller/move/moveFolderController.js +0 -2
  31. package/src/all/background_page/controller/permission/FindAcoPermissionsForDisplayController.js +1 -1
  32. package/src/all/background_page/controller/permission/FindAcoPermissionsForDisplayController.test.js +2 -2
  33. package/src/all/background_page/controller/resource/findAllByIdsForDisplayPermissionsController.test.js +8 -3
  34. package/src/all/background_page/controller/resource/findAllIdsByIsSharedWithGroupController.test.js +9 -4
  35. package/src/all/background_page/controller/resource/resourceUpdateController.test.js +1 -2
  36. package/src/all/background_page/controller/resourceLocalStorage/resourceUpdateLocalStorageController.test.js +5 -2
  37. package/src/all/background_page/controller/share/findFoldersForShareController.js +66 -0
  38. package/src/all/background_page/controller/share/findFoldersForShareController.test.js +70 -0
  39. package/src/all/background_page/controller/share/searchUsersAndGroupsController.js +4 -4
  40. package/src/all/background_page/controller/share/searchUsersAndGroupsController.test.js +8 -23
  41. package/src/all/background_page/controller/share/shareResourcesController.test.js +2 -2
  42. package/src/all/background_page/controller/subscription/createSubscriptionKeyController.js +63 -0
  43. package/src/all/background_page/controller/subscription/createSubscriptionKeyController.test.js +56 -0
  44. package/src/all/background_page/controller/subscription/deleteSubscriptionKeyController.js +55 -0
  45. package/src/all/background_page/controller/subscription/deleteSubscriptionKeyController.test.js +50 -0
  46. package/src/all/background_page/controller/user/deleteUserController.test.js +1 -1
  47. package/src/all/background_page/controller/user/getOrFindUsersController.js +61 -0
  48. package/src/all/background_page/controller/user/getOrFindUsersController.test.js +69 -0
  49. package/src/all/background_page/error/deleteDryRunError.js +1 -1
  50. package/src/all/background_page/event/actionLogEvents.js +1 -1
  51. package/src/all/background_page/event/appEvents.js +25 -0
  52. package/src/all/background_page/event/groupEvents.js +26 -0
  53. package/src/all/background_page/event/keyringEvents.js +12 -0
  54. package/src/all/background_page/event/shareEvents.js +3 -9
  55. package/src/all/background_page/event/userEvents.js +13 -0
  56. package/src/all/background_page/model/config.js +12 -2
  57. package/src/all/background_page/model/entity/folder/folderEntity.js +2 -2
  58. package/src/all/background_page/model/entity/folder/folderEntity.test.js +2 -2
  59. package/src/all/background_page/model/entity/folder/foldersCollection.test.js +1 -1
  60. package/src/all/background_page/model/entity/group/update/groupUpdateEntity.js +1 -1
  61. package/src/all/background_page/model/entity/group/update/groupUpdateEntity.test.js +1 -1
  62. package/src/all/background_page/model/entity/permission/actionLog/updatedPermissionEntity.js +2 -2
  63. package/src/all/background_page/model/entity/permission/actionLog/updatedPermissionEntity.test.data.js +1 -1
  64. package/src/all/background_page/model/entity/permission/change/permissionChangeEntity.js +1 -1
  65. package/src/all/background_page/model/entity/permission/change/permissionChangesCollection.js +2 -2
  66. package/src/all/background_page/model/entity/permission/change/permissionChangesCollection.test.js +2 -2
  67. package/src/all/background_page/model/entity/resource/resourceEntity.js +2 -2
  68. package/src/all/background_page/model/entity/resource/resourceEntity.test.js +1 -1
  69. package/src/all/background_page/model/entity/user/userEntity.js +16 -377
  70. package/src/all/background_page/model/entity/user/userEntity.test.js +22 -297
  71. package/src/all/background_page/model/entity/userAndGroupSearchResultEntity/userAndGroupSearchResultEntity.js +1 -1
  72. package/src/all/background_page/model/folder/folderModel.js +5 -154
  73. package/src/all/background_page/model/group/groupModel.js +1 -1
  74. package/src/all/background_page/model/keyring.js +52 -17
  75. package/src/all/background_page/model/keyring.test.js +110 -0
  76. package/src/all/background_page/model/resource/resourceModel.js +2 -55
  77. package/src/all/background_page/model/setup/setupModel.js +2 -2
  78. package/src/all/background_page/model/user/userModel.js +18 -15
  79. package/src/all/background_page/model/user/userModel.test.js +1 -3
  80. package/src/all/background_page/service/api/abstract/abstractService.js +3 -17
  81. package/src/all/background_page/service/api/edition/passboltEditionApiService.js +64 -0
  82. package/src/all/background_page/service/api/edition/passboltEditionApiService.test.js +99 -0
  83. package/src/all/background_page/service/api/group/groupApiService.js +22 -23
  84. package/src/all/background_page/service/api/group/groupApiService.test.js +70 -0
  85. package/src/all/background_page/service/api/resource/resourceService.js +18 -12
  86. package/src/all/background_page/service/api/share/{shareService.js → shareApiService.js} +10 -7
  87. package/src/all/background_page/service/api/share/{shareService.test.js → shareApiService.test.js} +5 -5
  88. package/src/all/background_page/service/group/createGroupService.js +1 -1
  89. package/src/all/background_page/service/group/createGroupService.test.js +1 -1
  90. package/src/all/background_page/service/group/findAndUpdateGroupsLocalStorageService.js +56 -1
  91. package/src/all/background_page/service/group/findAndUpdateGroupsLocalStorageService.test.js +84 -2
  92. package/src/all/background_page/service/group/findGroupsService.js +5 -9
  93. package/src/all/background_page/service/group/findGroupsService.test.data.js +1 -1
  94. package/src/all/background_page/service/group/findGroupsService.test.js +10 -15
  95. package/src/all/background_page/service/group/getOrFindGroupsService.js +65 -0
  96. package/src/all/background_page/service/group/getOrFindGroupsService.test.js +168 -0
  97. package/src/all/background_page/service/group/getOrFindGroupsUsersService.js +51 -0
  98. package/src/all/background_page/service/group/getOrFindGroupsUsersService.test.js +94 -0
  99. package/src/all/background_page/service/group/groupUpdateService.js +5 -3
  100. package/src/all/background_page/service/group/groupUpdateService.test.js +10 -2
  101. package/src/all/background_page/service/local_storage/groupLocalStorage.js +2 -2
  102. package/src/all/background_page/service/local_storage/groupLocalStorage.test.js +3 -3
  103. package/src/all/background_page/service/local_storage/userLocalStorage.js +57 -36
  104. package/src/all/background_page/service/local_storage/userLocalStorage.test.js +282 -0
  105. package/src/all/background_page/service/metadata/createMetadataKeyService.test.js +1 -1
  106. package/src/all/background_page/service/metadata/saveMetadataSettingsService.test.js +1 -1
  107. package/src/all/background_page/service/metadata/shareMetadataKeyPrivateService.test.js +1 -1
  108. package/src/all/background_page/service/migrateMetadata/migrateMetadataResourcesService.js +1 -1
  109. package/src/all/background_page/service/move/calculatePermissionsChangesForMoveService.js +113 -0
  110. package/src/all/background_page/service/move/calculatePermissionsChangesForMoveService.test.data.js +38 -0
  111. package/src/all/background_page/service/move/calculatePermissionsChangesForMoveService.test.js +158 -0
  112. package/src/all/background_page/service/move/moveOneFolderService.js +6 -7
  113. package/src/all/background_page/service/move/moveOneFolderService.test.js +90 -90
  114. package/src/all/background_page/service/move/moveResourcesService.js +2 -5
  115. package/src/all/background_page/service/permission/findPermissionsService.js +1 -1
  116. package/src/all/background_page/service/resource/create/resourceCreateService.js +13 -31
  117. package/src/all/background_page/service/resource/create/resourceCreateService.test.js +25 -18
  118. package/src/all/background_page/service/resource/export/exportResourcesService.test.js +13 -4
  119. package/src/all/background_page/service/resource/findAndUpdateResourcesLocalStorageService.test.js +35 -28
  120. package/src/all/background_page/service/resource/findResourcesService.js +78 -2
  121. package/src/all/background_page/service/resource/findResourcesService.test.data.js +1 -1
  122. package/src/all/background_page/service/resource/findResourcesService.test.js +90 -31
  123. package/src/all/background_page/service/resource/getOrFindResourcesService.test.js +18 -8
  124. package/src/all/background_page/service/session_storage/keepSessionAliveService.js +3 -3
  125. package/src/all/background_page/service/session_storage/keepSessionAliveService.test.js +5 -3
  126. package/src/all/background_page/service/share/searchUsersAndGroupsService.js +41 -0
  127. package/src/all/background_page/service/share/searchUsersAndGroupsService.test.js +64 -0
  128. package/src/all/background_page/service/share/shareFoldersService.js +3 -3
  129. package/src/all/background_page/service/share/shareFoldersService.test.js +3 -3
  130. package/src/all/background_page/service/share/shareResourceService.js +4 -4
  131. package/src/all/background_page/service/share/shareResourceService.test.js +8 -8
  132. package/src/all/background_page/service/subscription/createSubscriptionKeyService.js +57 -0
  133. package/src/all/background_page/service/subscription/createSubscriptionKeyService.test.js +111 -0
  134. package/src/all/background_page/service/subscription/deleteSubscriptionKeyService.js +35 -0
  135. package/src/all/background_page/service/subscription/deleteSubscriptionKeyService.test.js +55 -0
  136. package/src/all/background_page/service/user/deleteUserService.js +4 -4
  137. package/src/all/background_page/service/user/deleteUserService.test.js +10 -10
  138. package/src/all/background_page/service/user/findAndUpdateUsersLocalStorageService.js +81 -0
  139. package/src/all/background_page/service/user/findAndUpdateUsersLocalStorageService.test.js +132 -0
  140. package/src/all/background_page/service/user/findUsersService.js +6 -6
  141. package/src/all/background_page/service/user/findUsersService.test.js +39 -38
  142. package/src/all/background_page/service/user/getOrFindUsersService.js +60 -0
  143. package/src/all/background_page/service/user/getOrFindUsersService.test.js +110 -0
  144. package/src/all/background_page/utils/assertions.js +1 -0
  145. package/src/all/locales/ko-KR/common.json +1 -1
  146. package/src/chrome/manifest.json +1 -1
  147. package/src/chrome-mv3/manifest.json +1 -1
  148. package/src/firefox/manifest.json +3 -3
  149. package/src/safari/manifest.json +2 -2
  150. package/test/jest.env-setup.js +31 -0
  151. package/webpack/applyOutputClean.js +69 -0
  152. package/webpack/base.config.js +33 -0
  153. package/webpack/common-blocks.js +91 -0
  154. package/webpack/expectedBuildArtifacts.js +51 -0
  155. package/webpack/i18nextExtractionPlugin.js +43 -0
  156. package/webpack/passboltEnvPlugin.js +41 -0
  157. package/webpack/webExtPlugin/index.js +75 -0
  158. package/webpack.chromium-mv2.config.js +40 -0
  159. package/webpack.chromium-mv3.config.js +40 -0
  160. package/webpack.common.config.js +186 -0
  161. package/webpack.config.js +38 -0
  162. package/webpack.firefox.config.js +40 -0
  163. package/webpack.mv2.config.js +65 -0
  164. package/webpack.mv3.config.js +99 -0
  165. package/webpack.safari-background-page.config.js +66 -57
  166. package/webpack.safari.config.js +44 -0
  167. package/Gruntfile.js +0 -471
  168. package/am_i_compromised.py +0 -1036
  169. package/am_i_compromised.sh +0 -688
  170. package/i18next-parser.config.js +0 -22
  171. package/src/all/background_page/config/config.json +0 -7
  172. package/src/all/background_page/config/config.json.debug +0 -7
  173. package/src/all/background_page/config/config.json.default +0 -7
  174. package/src/all/background_page/model/entity/group/groupEntity.js +0 -241
  175. package/src/all/background_page/model/entity/group/groupEntity.test.js +0 -136
  176. package/src/all/background_page/model/entity/group/groupsCollection.js +0 -166
  177. package/src/all/background_page/model/entity/group/groupsCollection.test.data.js +0 -34
  178. package/src/all/background_page/model/entity/group/groupsCollection.test.js +0 -227
  179. package/src/all/background_page/model/entity/permission/permissionEntity.js +0 -485
  180. package/src/all/background_page/model/entity/permission/permissionEntity.test.js +0 -263
  181. package/src/all/background_page/model/entity/permission/permissionsCollection.js +0 -486
  182. package/src/all/background_page/model/entity/permission/permissionsCollection.test.js +0 -700
  183. package/src/all/background_page/model/entity/user/usersCollection.js +0 -147
  184. package/src/all/background_page/model/entity/user/usersCollection.test.js +0 -223
  185. package/src/all/background_page/model/share/shareModel.js +0 -183
  186. package/src/all/background_page/model/share/shareModel.test.js +0 -61
  187. package/src/all/background_page/service/api/user/userService.js +0 -260
  188. package/src/all/background_page/service/resource/create/resourceCreateService.test.data.js +0 -55
  189. package/webpack-content-scripts.browser-integration.config.js +0 -57
  190. package/webpack-content-scripts.config.js +0 -61
  191. package/webpack-content-scripts.public-website-sign-in.config.js +0 -57
  192. package/webpack-data.config.js +0 -102
  193. package/webpack-data.download.config.js +0 -59
  194. package/webpack-data.in-form-call-to-action.config.js +0 -97
  195. package/webpack-data.in-form-menu.config.js +0 -97
  196. package/webpack-offscreens.config.js +0 -55
  197. package/webpack.background-page.config.js +0 -62
  198. package/webpack.service-worker.config.js +0 -65
@@ -0,0 +1,69 @@
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 5.13.0
13
+ */
14
+
15
+ import AccountEntity from "../../model/entity/account/accountEntity";
16
+ import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
17
+ import { defaultApiClientOptions } from "passbolt-styleguide/src/shared/lib/apiClient/apiClientOptions.test.data";
18
+ import GetOrFindGroupsController from "./getOrFindGroupsController";
19
+ import GroupsCollection from "passbolt-styleguide/src/shared/models/entity/group/groupsCollection";
20
+ import { defaultGroupsDtos } from "passbolt-styleguide/src/shared/models/entity/group/groupsCollection.test.data";
21
+
22
+ beforeEach(() => {
23
+ jest.clearAllMocks();
24
+ });
25
+
26
+ describe("GetOrFindGroupsController", () => {
27
+ describe("::exec", () => {
28
+ it("Should retrieve the groups matching the given ids.", async () => {
29
+ expect.assertions(3);
30
+
31
+ const account = new AccountEntity(defaultAccountDto());
32
+ const groupsDto = defaultGroupsDtos();
33
+ const groupsCollection = new GroupsCollection(groupsDto);
34
+ const requestedIds = [groupsDto[1].id, groupsDto[3].id];
35
+ const controller = new GetOrFindGroupsController(null, null, defaultApiClientOptions(), account);
36
+ jest.spyOn(controller.getOrFindGroupsService, "getOrFindByIds").mockImplementation(() => groupsCollection);
37
+
38
+ const result = await controller.exec(requestedIds);
39
+
40
+ expect(result).toBeInstanceOf(GroupsCollection);
41
+ expect(result).toStrictEqual(groupsCollection);
42
+ expect(controller.getOrFindGroupsService.getOrFindByIds).toHaveBeenCalledWith(requestedIds);
43
+ });
44
+
45
+ it("Should let error been thrown from the service if any.", async () => {
46
+ expect.assertions(1);
47
+
48
+ const account = new AccountEntity(defaultAccountDto());
49
+ const controller = new GetOrFindGroupsController(null, null, defaultApiClientOptions(), account);
50
+ const requestedIds = [defaultGroupsDtos()[0].id];
51
+ jest.spyOn(controller.getOrFindGroupsService, "getOrFindByIds").mockImplementation(() => {
52
+ throw new Error("Something went wrong!");
53
+ });
54
+
55
+ await expect(() => controller.exec(requestedIds)).rejects.toThrow();
56
+ });
57
+
58
+ it("Should assert its parameter.", async () => {
59
+ expect.assertions(1);
60
+
61
+ const account = new AccountEntity(defaultAccountDto());
62
+ const controller = new GetOrFindGroupsController(null, null, defaultApiClientOptions(), account);
63
+
64
+ await expect(() => controller.exec(["not-a-uuid"])).rejects.toThrow(
65
+ "The given parameter is not a valid array of uuid",
66
+ );
67
+ });
68
+ });
69
+ });
@@ -0,0 +1,62 @@
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 5.13.0
13
+ */
14
+ import GetOrFindGroupsUsersService from "../../service/group/getOrFindGroupsUsersService";
15
+ import { assertUuid } from "../../utils/assertions";
16
+
17
+ /**
18
+ * Controller for the `passbolt.groups_users.get-by-group-id` event. Returns the members of the group
19
+ * matching the given id, served from the local storage cache when available and otherwise fetched
20
+ * from the API.
21
+ */
22
+ class GetOrFindGroupsUsersController {
23
+ /**
24
+ * Constructor.
25
+ * @param {Worker} worker The associated worker.
26
+ * @param {string} requestId The associated request id.
27
+ * @param {ApiClientOptions} apiClientOptions The api client options.
28
+ * @param {AccountEntity} account The user account.
29
+ */
30
+ constructor(worker, requestId, apiClientOptions, account) {
31
+ this.worker = worker;
32
+ this.requestId = requestId;
33
+ this.getOrFindGroupsUsersService = new GetOrFindGroupsUsersService(account, apiClientOptions);
34
+ }
35
+
36
+ /**
37
+ * Controller executor.
38
+ * @param {string} groupId The id of the group whose members are requested.
39
+ * @returns {Promise<void>}
40
+ */
41
+ async _exec(groupId) {
42
+ try {
43
+ const result = await this.exec(groupId);
44
+ this.worker.port.emit(this.requestId, "SUCCESS", result);
45
+ } catch (error) {
46
+ console.error(error);
47
+ this.worker.port.emit(this.requestId, "ERROR", error);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Find all the members of the group matching the given id.
53
+ * @param {string} groupId The id of the group whose members are requested.
54
+ * @returns {Promise<GroupsUsersCollection>}
55
+ */
56
+ async exec(groupId) {
57
+ assertUuid(groupId);
58
+ return this.getOrFindGroupsUsersService.getOrFindByGroupId(groupId);
59
+ }
60
+ }
61
+
62
+ export default GetOrFindGroupsUsersController;
@@ -0,0 +1,69 @@
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 5.13.0
13
+ */
14
+
15
+ import AccountEntity from "../../model/entity/account/accountEntity";
16
+ import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
17
+ import { defaultApiClientOptions } from "passbolt-styleguide/src/shared/lib/apiClient/apiClientOptions.test.data";
18
+ import GetOrFindGroupsUsersController from "./getOrFindGroupsUsersController";
19
+ import GroupsUsersCollection from "passbolt-styleguide/src/shared/models/entity/groupUser/groupsUsersCollection";
20
+ import { defaultGroupsDtos } from "passbolt-styleguide/src/shared/models/entity/group/groupsCollection.test.data";
21
+
22
+ beforeEach(() => {
23
+ jest.clearAllMocks();
24
+ });
25
+
26
+ describe("GetOrFindGroupsUsersController", () => {
27
+ describe("::exec", () => {
28
+ it("Should retrieve the members of the requested group.", async () => {
29
+ expect.assertions(3);
30
+
31
+ const account = new AccountEntity(defaultAccountDto());
32
+ const groupsDto = defaultGroupsDtos(1, { withGroupsUsers: 3 });
33
+ const targetGroup = groupsDto[0];
34
+ const groupsUsersCollection = new GroupsUsersCollection(targetGroup.groups_users);
35
+ const controller = new GetOrFindGroupsUsersController(null, null, defaultApiClientOptions(), account);
36
+ jest
37
+ .spyOn(controller.getOrFindGroupsUsersService, "getOrFindByGroupId")
38
+ .mockImplementation(() => groupsUsersCollection);
39
+
40
+ const result = await controller.exec(targetGroup.id);
41
+
42
+ expect(result).toBeInstanceOf(GroupsUsersCollection);
43
+ expect(result).toStrictEqual(groupsUsersCollection);
44
+ expect(controller.getOrFindGroupsUsersService.getOrFindByGroupId).toHaveBeenCalledWith(targetGroup.id);
45
+ });
46
+
47
+ it("Should let error been thrown from the service if any.", async () => {
48
+ expect.assertions(1);
49
+
50
+ const account = new AccountEntity(defaultAccountDto());
51
+ const controller = new GetOrFindGroupsUsersController(null, null, defaultApiClientOptions(), account);
52
+ const groupId = defaultGroupsDtos()[0].id;
53
+ jest.spyOn(controller.getOrFindGroupsUsersService, "getOrFindByGroupId").mockImplementation(() => {
54
+ throw new Error("Something went wrong!");
55
+ });
56
+
57
+ await expect(() => controller.exec(groupId)).rejects.toThrow();
58
+ });
59
+
60
+ it("Should assert its parameter.", async () => {
61
+ expect.assertions(1);
62
+
63
+ const account = new AccountEntity(defaultAccountDto());
64
+ const controller = new GetOrFindGroupsUsersController(null, null, defaultApiClientOptions(), account);
65
+
66
+ await expect(() => controller.exec("not-a-uuid")).rejects.toThrow("The given parameter is not a valid UUID");
67
+ });
68
+ });
69
+ });
@@ -12,7 +12,7 @@
12
12
  * @since 5.11.0
13
13
  */
14
14
  import CreateGroupService from "../../service/group/createGroupService";
15
- import GroupEntity from "../../model/entity/group/groupEntity";
15
+ import GroupEntity from "passbolt-styleguide/src/shared/models/entity/group/groupEntity";
16
16
 
17
17
  class GroupCreateController {
18
18
  /**
@@ -16,7 +16,7 @@ import { defaultAccountDto } from "../../model/entity/account/accountEntity.test
16
16
  import { defaultApiClientOptions } from "passbolt-styleguide/src/shared/lib/apiClient/apiClientOptions.test.data";
17
17
  import GroupCreateController from "./groupCreateController";
18
18
  import { defaultGroupDto } from "passbolt-styleguide/src/shared/models/entity/group/groupEntity.test.data";
19
- import GroupEntity from "../../model/entity/group/groupEntity";
19
+ import GroupEntity from "passbolt-styleguide/src/shared/models/entity/group/groupEntity";
20
20
 
21
21
  describe("GroupCreateController", () => {
22
22
  let controller, account, apiClientOptions;
@@ -15,7 +15,7 @@ import GetPassphraseService from "../../service/passphrase/getPassphraseService"
15
15
  import i18n from "../../sdk/i18n";
16
16
  import ProgressService from "../../service/progress/progressService";
17
17
  import GroupUpdateService from "../../service/group/groupUpdateService";
18
- import GroupEntity from "../../model/entity/group/groupEntity";
18
+ import GroupEntity from "passbolt-styleguide/src/shared/models/entity/group/groupEntity";
19
19
 
20
20
  class GroupsUpdateController {
21
21
  /**
@@ -13,7 +13,7 @@
13
13
  */
14
14
 
15
15
  import { defaultApiClientOptions } from "passbolt-styleguide/src/shared/lib/apiClient/apiClientOptions.test.data";
16
- import GroupsCollection from "../../model/entity/group/groupsCollection";
16
+ import GroupsCollection from "passbolt-styleguide/src/shared/models/entity/group/groupsCollection";
17
17
  import AccountEntity from "../../model/entity/account/accountEntity";
18
18
  import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
19
19
  import UpdateAllGroupsLocalStorageController from "./updateAllGroupsLocalStorageController";
@@ -0,0 +1,51 @@
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 5.13.0
13
+ */
14
+ import Keyring from "../../model/keyring";
15
+
16
+ class SynchroniseKeyringController {
17
+ /**
18
+ * SynchroniseKeyringController constructor.
19
+ * @param {Worker} worker
20
+ * @param {string} requestId uuid
21
+ */
22
+ constructor(worker, requestId) {
23
+ this.worker = worker;
24
+ this.requestId = requestId;
25
+ this.keyring = new Keyring();
26
+ }
27
+
28
+ /**
29
+ * Wrapper of exec function to run it with worker.
30
+ * @returns {Promise<void>}
31
+ */
32
+ async _exec() {
33
+ try {
34
+ await this.exec();
35
+ this.worker.port.emit(this.requestId, "SUCCESS");
36
+ } catch (error) {
37
+ console.error(error);
38
+ this.worker.port.emit(this.requestId, "ERROR", error);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Synchronises the keyring with the API.
44
+ * @returns {Promise<void>}
45
+ */
46
+ async exec() {
47
+ await this.keyring.sync();
48
+ }
49
+ }
50
+
51
+ export default SynchroniseKeyringController;
@@ -0,0 +1,49 @@
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 5.13.0
13
+ */
14
+
15
+ import SynchroniseKeyringController from "../keyring/synchroniseKeyringController";
16
+ import Keyring from "../../model/keyring";
17
+
18
+ const mockSync = jest.spyOn(Keyring.prototype, "sync");
19
+
20
+ beforeEach(() => {
21
+ jest.clearAllMocks();
22
+ });
23
+
24
+ describe("SynchroniseKeyringController", () => {
25
+ it("Should synchronise the keyring", async () => {
26
+ expect.assertions(1);
27
+ mockSync.mockImplementation(() => Promise.resolve());
28
+ const controller = new SynchroniseKeyringController();
29
+ const promise = controller.exec();
30
+ return expect(promise).resolves.not.toThrow();
31
+ });
32
+
33
+ it("Should call keyring.sync() once", async () => {
34
+ expect.assertions(1);
35
+ mockSync.mockImplementation(() => Promise.resolve());
36
+ const controller = new SynchroniseKeyringController();
37
+ await controller.exec();
38
+ expect(mockSync).toHaveBeenCalledTimes(1);
39
+ });
40
+
41
+ it("Should propagate errors thrown by keyring.sync()", async () => {
42
+ expect.assertions(1);
43
+ const error = new Error("Could not synchronize the keyring.");
44
+ mockSync.mockImplementation(() => Promise.reject(error));
45
+ const controller = new SynchroniseKeyringController();
46
+ const promise = controller.exec();
47
+ return expect(promise).rejects.toThrow("Could not synchronize the keyring.");
48
+ });
49
+ });
@@ -18,7 +18,7 @@ import ShareMetadataKeyPrivateController from "./shareMetadataKeyPrivateControll
18
18
  import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
19
19
  import { pgpKeys } from "passbolt-styleguide/test/fixture/pgpKeys/keys";
20
20
  import GetOrFindMetadataKeysService from "../../service/metadata/getOrFindMetadataKeysService";
21
- import UsersCollection from "../../model/entity/user/usersCollection";
21
+ import UsersCollection from "passbolt-styleguide/src/shared/models/entity/user/usersCollection";
22
22
  import {
23
23
  metadataKeysSignedByCurrentDto,
24
24
  usersWithMissingMetadataKeysDto,
@@ -16,7 +16,6 @@ import i18n from "../../sdk/i18n";
16
16
  import ProgressService from "../../service/progress/progressService";
17
17
  import MoveOneFolderService, { PROGRESS_STEPS_MOVE_FOLDER_MOVE_ONE } from "../../service/move/moveOneFolderService";
18
18
  import ConfirmMoveStrategyService from "../../service/move/confirmMoveStrategyService";
19
- import FolderModel from "../../model/folder/folderModel";
20
19
  import { assertUuid } from "../../utils/assertions";
21
20
  import VerifyOrTrustMetadataKeyService from "../../service/metadata/verifyOrTrustMetadataKeyService";
22
21
 
@@ -36,7 +35,6 @@ class MoveFolderController {
36
35
  this.getPassphraseService = new GetPassphraseService(account);
37
36
  this.moveOneFolderService = new MoveOneFolderService(apiClientOptions, account, this.progressService);
38
37
  this.confirmMoveStrategyService = new ConfirmMoveStrategyService(worker);
39
- this.folderModel = new FolderModel(apiClientOptions, account);
40
38
  this.verifyOrTrustMetadataKeyService = new VerifyOrTrustMetadataKeyService(worker, account, apiClientOptions);
41
39
  }
42
40
 
@@ -12,7 +12,7 @@
12
12
  * @since 4.9.4
13
13
  */
14
14
  import FindPermissionsService from "../../service/permission/findPermissionsService";
15
- import PermissionEntity from "../../model/entity/permission/permissionEntity";
15
+ import PermissionEntity from "passbolt-styleguide/src/shared/models/entity/permission/permissionEntity";
16
16
  import FindFoldersService from "../../service/folder/findFoldersService";
17
17
  import { assertString, assertUuid } from "../../utils/assertions";
18
18
 
@@ -17,10 +17,10 @@ import FindAcoPermissionsForDisplayController from "./FindAcoPermissionsForDispl
17
17
  import { defaultApiClientOptions } from "passbolt-styleguide/src/shared/lib/apiClient/apiClientOptions.test.data";
18
18
  import AccountEntity from "../../model/entity/account/accountEntity";
19
19
  import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
20
- import PermissionEntity from "../../model/entity/permission/permissionEntity";
20
+ import PermissionEntity from "passbolt-styleguide/src/shared/models/entity/permission/permissionEntity";
21
21
  import { defaultFolderDto } from "passbolt-styleguide/src/shared/models/entity/folder/folderEntity.test.data";
22
22
  import { defaultPermissionsDtos } from "passbolt-styleguide/src/shared/models/entity/permission/permissionCollection.test.data";
23
- import PermissionsCollection from "../../model/entity/permission/permissionsCollection";
23
+ import PermissionsCollection from "passbolt-styleguide/src/shared/models/entity/permission/permissionsCollection";
24
24
  import FolderService from "../../service/api/folder/folderService";
25
25
 
26
26
  describe("FindAcoPermissionsForDisplayController", () => {
@@ -19,12 +19,12 @@ import { multipleResourceDtos } from "../../service/resource/findResourcesServic
19
19
  import FindAllByIdsForDisplayPermissionsController from "./findAllByIdsForDisplayPermissionsController";
20
20
  import ResourcesCollection from "../../model/entity/resource/resourcesCollection";
21
21
  import { pgpKeys } from "passbolt-styleguide/test/fixture/pgpKeys/keys";
22
- import ResourceService from "../../service/api/resource/resourceService";
23
22
  import { v4 as uuidv4 } from "uuid";
24
23
  import { TEST_RESOURCE_TYPE_V5_DEFAULT } from "passbolt-styleguide/src/shared/models/entity/resourceType/resourceTypeEntity.test.data";
25
24
  import { METADATA_KEY_TYPE_USER_KEY } from "../../model/entity/resource/resourceEntity";
26
25
  import { defaultResourceDto } from "passbolt-styleguide/src/shared/models/entity/resource/resourceEntity.test.data";
27
26
  import { metadata } from "passbolt-styleguide/test/fixture/encryptedMetadata/metadata";
27
+ import { mockPassboltResponse } from "passbolt-styleguide/test/mocks/mockApiResponse";
28
28
 
29
29
  describe("FindAllByIdsForDisplayPermissionsController", () => {
30
30
  let controller, worker;
@@ -46,7 +46,9 @@ describe("FindAllByIdsForDisplayPermissionsController", () => {
46
46
 
47
47
  const resourcesDto = multipleResourceDtos();
48
48
  const resourceIds = resourcesDto.map((resource) => resource.id);
49
- jest.spyOn(controller.findResourcesService.resourceService, "findAll").mockImplementation(() => resourcesDto);
49
+ jest
50
+ .spyOn(controller.findResourcesService.resourceService, "findAll")
51
+ .mockImplementation(() => mockPassboltResponse(resourcesDto));
50
52
  jest
51
53
  .spyOn(controller.findResourcesService.decryptMetadataService, "decryptAllFromForeignModels")
52
54
  .mockImplementation((collection) => collection);
@@ -73,7 +75,10 @@ describe("FindAllByIdsForDisplayPermissionsController", () => {
73
75
  }),
74
76
  ];
75
77
  const resourceIds = resourcesDto.map((resource) => resource.id);
76
- jest.spyOn(ResourceService.prototype, "findAll").mockImplementation(() => resourcesDto);
78
+ jest
79
+ .spyOn(controller.findResourcesService.resourceService, "findAll")
80
+ .mockImplementation(() => mockPassboltResponse(resourcesDto));
81
+
77
82
  jest.spyOn(controller.getPassphraseService, "getPassphrase").mockReturnValue(pgpKeys.ada.passphrase);
78
83
 
79
84
  const result = await controller.exec(resourceIds);
@@ -28,6 +28,7 @@ import { METADATA_KEY_TYPE_USER_KEY } from "../../model/entity/resource/resource
28
28
  import { defaultResourceDto } from "passbolt-styleguide/src/shared/models/entity/resource/resourceEntity.test.data";
29
29
  import { metadata } from "passbolt-styleguide/test/fixture/encryptedMetadata/metadata";
30
30
  import { pgpKeys } from "passbolt-styleguide/test/fixture/pgpKeys/keys";
31
+ import { mockPassboltResponse } from "passbolt-styleguide/test/mocks/mockApiResponse";
31
32
 
32
33
  describe("FindAllIdsByIsSharedWithGroupController", () => {
33
34
  let controller, worker, groupId;
@@ -52,7 +53,9 @@ describe("FindAllIdsByIsSharedWithGroupController", () => {
52
53
 
53
54
  const resourceCollectionDto = multipleResourceDtos();
54
55
  const expectedResult = new ResourcesCollection(resourceCollectionDto).extract("id");
55
- jest.spyOn(ResourceService.prototype, "findAll").mockImplementation(() => resourceCollectionDto);
56
+ jest
57
+ .spyOn(ResourceService.prototype, "findAll")
58
+ .mockImplementation(() => mockPassboltResponse(resourceCollectionDto));
56
59
 
57
60
  await controller._exec(groupId);
58
61
 
@@ -78,7 +81,9 @@ describe("FindAllIdsByIsSharedWithGroupController", () => {
78
81
 
79
82
  const resourceCollectionDto = multipleResourceDtos();
80
83
  const expectedResult = new ResourcesCollection(resourceCollectionDto).extract("id");
81
- jest.spyOn(ResourceService.prototype, "findAll").mockImplementation(() => resourceCollectionDto);
84
+ jest
85
+ .spyOn(ResourceService.prototype, "findAll")
86
+ .mockImplementation(() => mockPassboltResponse(resourceCollectionDto));
82
87
  jest.spyOn(FindAndUpdateResourcesLocalStorage.prototype, "findAndUpdateByIsSharedWithGroup");
83
88
 
84
89
  const resourceIds = await controller.exec(groupId);
@@ -102,7 +107,7 @@ describe("FindAllIdsByIsSharedWithGroupController", () => {
102
107
  }),
103
108
  ];
104
109
  jest.spyOn(controller.findAndUpdateResourcesLocalStorage, "findAndUpdateByIsSharedWithGroup");
105
- jest.spyOn(ResourceService.prototype, "findAll").mockImplementation(() => resourcesDto);
110
+ jest.spyOn(ResourceService.prototype, "findAll").mockImplementation(() => mockPassboltResponse(resourcesDto));
106
111
  jest.spyOn(controller.getPassphraseService, "getPassphrase").mockReturnValue(pgpKeys.ada.passphrase);
107
112
 
108
113
  const result = await controller.exec(groupId);
@@ -118,7 +123,7 @@ describe("FindAllIdsByIsSharedWithGroupController", () => {
118
123
  it("Should allow a group to not include any resources", async () => {
119
124
  expect.assertions(2);
120
125
 
121
- jest.spyOn(ResourceService.prototype, "findAll").mockImplementation(() => []);
126
+ jest.spyOn(ResourceService.prototype, "findAll").mockImplementation(() => mockPassboltResponse([]));
122
127
  const resourceIds = await controller.exec(groupId);
123
128
 
124
129
  expect(resourceIds.length).toEqual(0);
@@ -24,7 +24,6 @@ import { pgpKeys } from "passbolt-styleguide/test/fixture/pgpKeys/keys";
24
24
  import { enableFetchMocks } from "jest-fetch-mock";
25
25
  import { mockApiResponse } from "../../../../../test/mocks/mockApiResponse";
26
26
  import EncryptMessageService from "../../service/crypto/encryptMessageService";
27
- import ResourceLocalStorage from "../../service/local_storage/resourceLocalStorage";
28
27
  import ResourceTypeService from "../../service/api/resourceType/resourceTypeService";
29
28
  import { resourceTypesCollectionDto } from "passbolt-styleguide/src/shared/models/entity/resourceType/resourceTypesCollection.test.data";
30
29
  import PermissionService from "../../service/api/permission/permissionService";
@@ -116,10 +115,10 @@ describe("ResourceUpdateController", () => {
116
115
 
117
116
  it("Should close progressService when update succeed", async () => {
118
117
  expect.assertions(2);
119
- jest.spyOn(ResourceLocalStorage, "updateResource").mockImplementationOnce(jest.fn);
120
118
  jest
121
119
  .spyOn(controller.verifyOrTrustMetadataKeyService, "verifyTrustedOrTrustNewMetadataKey")
122
120
  .mockImplementationOnce(jest.fn);
121
+ jest.spyOn(controller.resourceUpdateService, "exec").mockImplementationOnce(jest.fn);
123
122
  await controller.exec(defaultResourceDto(), null);
124
123
  expect(controller.progressService.close).toHaveBeenCalledTimes(1);
125
124
  expect(controller.progressService.close).toHaveBeenCalled();
@@ -27,6 +27,7 @@ import { TEST_RESOURCE_TYPE_V5_DEFAULT } from "passbolt-styleguide/src/shared/mo
27
27
  import { METADATA_KEY_TYPE_USER_KEY } from "../../model/entity/resource/resourceEntity";
28
28
  import { v4 as uuidv4 } from "uuid";
29
29
  import { metadata } from "passbolt-styleguide/test/fixture/encryptedMetadata/metadata";
30
+ import { mockPassboltResponse } from "passbolt-styleguide/test/mocks/mockApiResponse";
30
31
 
31
32
  describe("ResourceUpdateLocalStorageController", () => {
32
33
  let controller, worker;
@@ -73,14 +74,16 @@ describe("ResourceUpdateLocalStorageController", () => {
73
74
  it("requests the user passphrase whenever the decryption of the metadata requires it and try to load the data again", async () => {
74
75
  expect.assertions(4);
75
76
 
76
- jest.spyOn(ResourceService.prototype, "findAll").mockImplementation(() => [
77
+ const resources = [
77
78
  defaultResourceDto({
78
79
  resource_type_id: TEST_RESOURCE_TYPE_V5_DEFAULT,
79
80
  metadata_key_type: METADATA_KEY_TYPE_USER_KEY,
80
81
  metadata_key_id: uuidv4(),
81
82
  metadata: metadata.withAdaKey.encryptedMetadata[0],
82
83
  }),
83
- ]);
84
+ ];
85
+
86
+ jest.spyOn(ResourceService.prototype, "findAll").mockImplementation(() => mockPassboltResponse(resources));
84
87
  jest.spyOn(ResourceTypeService.prototype, "findAll").mockImplementation(() => resourceTypesCollectionDto());
85
88
  jest.spyOn(GetPassphraseService.prototype, "requestPassphrase").mockImplementation(() => pgpKeys.ada.passphrase);
86
89
  jest.spyOn(PassphraseStorageService, "set").mockImplementation(() => {});
@@ -0,0 +1,66 @@
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 5.13.0
13
+ */
14
+
15
+ import FindFoldersService from "../../service/folder/findFoldersService";
16
+ import { assertArrayUUID } from "../../utils/assertions";
17
+
18
+ class FindFoldersForShareController {
19
+ /**
20
+ * FindFoldersForShareController constructor
21
+ * @param {Worker} worker
22
+ * @param {string} requestId uuid
23
+ * @param {ApiClientOptions} apiClientOptions
24
+ */
25
+ constructor(worker, requestId, apiClientOptions) {
26
+ this.worker = worker;
27
+ this.requestId = requestId;
28
+ this.findFoldersService = new FindFoldersService(apiClientOptions);
29
+ }
30
+
31
+ /**
32
+ * Wrapper of exec function to run it with worker.
33
+ * @param {Array<string>} foldersIds
34
+ * @return {Promise<void>}
35
+ */
36
+ async _exec(foldersIds) {
37
+ try {
38
+ const result = await this.exec(foldersIds);
39
+ this.worker.port.emit(this.requestId, "SUCCESS", result);
40
+ } catch (error) {
41
+ console.error(error);
42
+ this.worker.port.emit(this.requestId, "ERROR", error);
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Find the folders to share with their permissions, users and groups hydrated.
48
+ * The styleguide share dialog reads `permission.user || permission.group` on each
49
+ * permission, so we must request the nested user.profile and group contains; the
50
+ * generic `permissions` contain alone returns permissions without aro details.
51
+ * @param {Array<string>} foldersIds
52
+ * @return {Promise<FoldersCollection>}
53
+ */
54
+ async exec(foldersIds) {
55
+ assertArrayUUID(foldersIds);
56
+
57
+ const contains = {
58
+ permission: true,
59
+ "permissions.user.profile": true,
60
+ "permissions.group": true,
61
+ };
62
+ return this.findFoldersService.findAllByIds(foldersIds, contains);
63
+ }
64
+ }
65
+
66
+ export default FindFoldersForShareController;