passbolt-browser-extension 5.17.0 → 5.18.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.
Files changed (185) hide show
  1. package/.pre-commit-config.yaml +6 -2
  2. package/CHANGELOG.md +106 -1
  3. package/README.md +2 -2
  4. package/RELEASE_NOTES.md +3 -94
  5. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager/ViewController.swift +5 -5
  6. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager.xcodeproj/project.pbxproj +10 -10
  7. package/eslint.config.mjs +3 -35
  8. package/jest.config.json +1 -2
  9. package/package.json +45 -54
  10. package/src/all/_locales/locales.test.js +2 -0
  11. package/src/all/background_page/controller/InformMenuController/InformMenuController.test.js +45 -1
  12. package/src/all/background_page/controller/accountRecovery/accountRecoverySaveUserSettingController.js +1 -2
  13. package/src/all/background_page/controller/accountRecovery/accountRecoverySaveUserSettingController.test.js +10 -8
  14. package/src/all/background_page/controller/accountRecovery/accountRecoveryValidatePublicKeyController.test.js +1 -1
  15. package/src/all/background_page/controller/auth/authLocalLogoutController.js +3 -14
  16. package/src/all/background_page/controller/auth/authLocalLogoutController.test.js +3 -3
  17. package/src/all/background_page/controller/auth/authLoginController.js +2 -2
  18. package/src/all/background_page/controller/auth/authOfflineLogoutController.js +4 -12
  19. package/src/all/background_page/controller/auth/authOfflineLogoutController.test.js +3 -3
  20. package/src/all/background_page/controller/auth/{findAndUpdateActiveSessionLocalStorageController.js → findAndUpdateActiveSessionSessionStorageController.js} +6 -6
  21. package/src/all/background_page/controller/auth/{findAndUpdateActiveSessionLocalStorageController.test.js → findAndUpdateActiveSessionSessionStorageController.test.js} +30 -30
  22. package/src/all/background_page/controller/auth/getOrFindActiveSessionController.test.js +22 -20
  23. package/src/all/background_page/controller/auth/isMfaRequiredController.js +5 -4
  24. package/src/all/background_page/controller/auth/isMfaRequiredController.test.js +3 -3
  25. package/src/all/background_page/controller/crypto/getUserKeyInfoController.test.js +1 -1
  26. package/src/all/background_page/controller/crypto/getUserPrivateKeyController.test.js +1 -1
  27. package/src/all/background_page/controller/extension/onExtensionInstalledController.js +61 -30
  28. package/src/all/background_page/controller/extension/onExtensionInstalledController.test.js +131 -19
  29. package/src/all/background_page/controller/informCallToActionController/informCallToActionController.test.js +46 -0
  30. package/src/all/background_page/controller/resource/setResourcesExpiryDateController.test.js +1 -1
  31. package/src/all/background_page/controller/sessionTimestamps/getSessionTimestampsController.js +54 -0
  32. package/src/all/background_page/controller/sessionTimestamps/getSessionTimestampsController.test.js +91 -0
  33. package/src/all/background_page/controller/share/shareResourcesController.test.js +2 -2
  34. package/src/all/background_page/controller/sso/getQualifiedSsoLoginErrorController.test.js +1 -1
  35. package/src/all/background_page/controller/sso/hasSsoLoginErrorController.test.js +1 -1
  36. package/src/all/background_page/controller/subscription/createSubscriptionKeyController.js +3 -3
  37. package/src/all/background_page/controller/subscription/createSubscriptionKeyController.test.js +4 -4
  38. package/src/all/background_page/controller/subscription/deleteSubscriptionKeyController.js +3 -3
  39. package/src/all/background_page/controller/subscription/deleteSubscriptionKeyController.test.js +4 -4
  40. package/src/all/background_page/controller/theme/findThemesController.js +52 -0
  41. package/src/all/background_page/controller/theme/findThemesController.test.js +68 -0
  42. package/src/all/background_page/controller/theme/updateThemeController.js +55 -0
  43. package/src/all/background_page/controller/theme/updateThemeController.test.js +76 -0
  44. package/src/all/background_page/controller/user/getOrFindLoggedInUserController.test.js +2 -2
  45. package/src/all/background_page/event/appEvents.js +1 -26
  46. package/src/all/background_page/event/authEvents.js +2 -2
  47. package/src/all/background_page/event/configEvents.js +0 -12
  48. package/src/all/background_page/event/informMenuEvents.js +2 -2
  49. package/src/all/background_page/event/quickAccessEvents.js +12 -0
  50. package/src/all/background_page/event/themeEvents.js +9 -21
  51. package/src/all/background_page/model/auth/authModel.js +3 -3
  52. package/src/all/background_page/model/auth/authModel.test.js +2 -2
  53. package/src/all/background_page/model/entity/export/exportResourcesFileEntity.js +2 -0
  54. package/src/all/background_page/model/entity/export/exportResourcesFileEntity.test.js +1 -0
  55. package/src/all/background_page/model/entity/import/importResourcesFileEntity.test.data.js +5 -0
  56. package/src/all/background_page/model/entity/sso/ssoLoginUrlEntity.js +1 -1
  57. package/src/all/background_page/model/entity/theme/themeEntity.test.data.js +12 -0
  58. package/src/all/background_page/model/entity/theme/themesCollection.test.data.js +10 -1
  59. package/src/all/background_page/model/export/resources/csvRowComposer/abstractRowComposer.js +8 -0
  60. package/src/all/background_page/model/export/resources/csvRowComposer/csvNetwrixRowComposer.js +67 -0
  61. package/src/all/background_page/model/export/resources/csvRowComposer/csvNetwrixRowComposer.test.js +37 -0
  62. package/src/all/background_page/model/export/resources/resourcesCsvExporter.js +5 -2
  63. package/src/all/background_page/model/export/resources/resourcesCsvExporter.test.js +3 -1
  64. package/src/all/background_page/model/import/resources/csvRowParser/csvNetwrixRowParser.js +98 -0
  65. package/src/all/background_page/model/import/resources/csvRowParser/csvNetwrixRowParser.test.js +145 -0
  66. package/src/all/background_page/model/import/resources/resourcesCsvImportParser.js +2 -0
  67. package/src/all/background_page/model/import/resources/resourcesCsvImportParser.test.js +19 -1
  68. package/src/all/background_page/model/keyring.test.js +1 -1
  69. package/src/all/background_page/model/multiFactorAuthentication/multiFactorAuthenticationModel.test.js +1 -1
  70. package/src/all/background_page/model/user/userModel.test.js +1 -1
  71. package/src/all/background_page/model/user.js +2 -2
  72. package/src/all/background_page/model/userSettings/userSettings.js +1 -1
  73. package/src/all/background_page/pagemod/appBootstrapPagemod.js +6 -5
  74. package/src/all/background_page/pagemod/appBootstrapPagemod.test.js +7 -12
  75. package/src/all/background_page/pagemod/authBootstrapPagemod.js +2 -2
  76. package/src/all/background_page/pagemod/authBootstrapPagemod.test.js +6 -7
  77. package/src/all/background_page/pagemod/pagemodManager.test.js +14 -20
  78. package/src/all/background_page/pagemod/webIntegrationPagemod.js +2 -2
  79. package/src/all/background_page/pagemod/webIntegrationPagemod.test.js +9 -9
  80. package/src/all/background_page/service/accountRecovery/decryptPrivateKeyPasswordDataService.js +1 -1
  81. package/src/all/background_page/service/accountRecovery/decryptResponseDataService.js +1 -1
  82. package/src/all/background_page/service/accountRecovery/parseAccountRecoveryUrlService.js +1 -1
  83. package/src/all/background_page/service/accountRecovery/validateOrganizationPublicKeyService.test.js +1 -1
  84. package/src/all/background_page/service/activeSession/{findAndUpdateActiveSessionLocalStorageService.js → findAndUpdateActiveSessionSessionStorageService.js} +27 -60
  85. package/src/all/background_page/service/activeSession/findAndUpdateActiveSessionSessionStorageService.test.js +720 -0
  86. package/src/all/background_page/service/activeSession/getOrFindActiveSessionService.js +8 -8
  87. package/src/all/background_page/service/activeSession/getOrFindActiveSessionService.test.js +16 -16
  88. package/src/all/background_page/service/api/accountSettings/accountSettingsService.js +0 -29
  89. package/src/all/background_page/service/api/accountSettings/accountSettingsService.test.data.js +0 -6
  90. package/src/all/background_page/service/api/accountSettings/accountSettingsService.test.js +1 -32
  91. package/src/all/background_page/service/api/actionLog/actionLogApiService.test.js +1 -1
  92. package/src/all/background_page/service/api/comment/commentApiService.test.js +1 -1
  93. package/src/all/background_page/service/api/metadata/metadataKeysApiService.test.js +1 -1
  94. package/src/all/background_page/service/api/sessionKey/sessionKeysBundlesApiService.test.js +1 -1
  95. package/src/all/background_page/service/api/theme/themesApiService.js +57 -0
  96. package/src/all/background_page/service/api/theme/themesApiService.test.js +83 -0
  97. package/src/all/background_page/service/app/parseAppUrlService.js +18 -10
  98. package/src/all/background_page/service/app/parseAppUrlService.test.js +21 -21
  99. package/src/all/background_page/service/auth/localLogoutService.js +42 -0
  100. package/src/all/background_page/service/auth/localLogoutService.test.js +43 -0
  101. package/src/all/background_page/service/auth/offlineLogoutService.js +47 -0
  102. package/src/all/background_page/service/auth/offlineLogoutService.test.js +46 -0
  103. package/src/all/background_page/service/auth/offlineSessionExpiryAlarmService.js +2 -2
  104. package/src/all/background_page/service/auth/offlineSessionExpiryAlarmService.test.js +3 -3
  105. package/src/all/background_page/service/auth/parseAuthUrlService.js +11 -6
  106. package/src/all/background_page/service/auth/parseAuthUrlService.test.js +11 -13
  107. package/src/all/background_page/service/auth/postLoginOfflineService.js +3 -3
  108. package/src/all/background_page/service/auth/postLoginOfflineService.test.js +3 -3
  109. package/src/all/background_page/service/auth/postLoginService.js +3 -3
  110. package/src/all/background_page/service/auth/postLoginService.test.js +3 -3
  111. package/src/all/background_page/service/auth/startLoopAuthSessionCheckService.js +8 -4
  112. package/src/all/background_page/service/auth/startLoopAuthSessionCheckService.test.js +36 -13
  113. package/src/all/background_page/service/authenticationStatusService.test.js +1 -1
  114. package/src/all/background_page/service/clipboard/clipboardProviderService.js +0 -7
  115. package/src/all/background_page/service/clipboard/clipboardProviderService.test.js +0 -10
  116. package/src/all/background_page/service/clipboard/copyToClipboardService.js +1 -5
  117. package/src/all/background_page/service/crypto/decryptSsoPassphraseService.js +1 -1
  118. package/src/all/background_page/service/extension/onStartUpService.js +2 -2
  119. package/src/all/background_page/service/extension/onStartUpService.test.js +3 -3
  120. package/src/all/background_page/service/localStorage/localStorageService.js +4 -2
  121. package/src/all/background_page/service/localStorage/localStorageService.test.js +28 -12
  122. package/src/all/background_page/service/local_storage/sessionTimestampsLocalStorage.js +40 -0
  123. package/src/all/background_page/service/local_storage/sessionTimestampsLocalStorage.test.js +63 -0
  124. package/src/all/background_page/service/metadata/rotateMetadata/rotateMetadataKeyService.test.js +2 -2
  125. package/src/all/background_page/service/metadata/rotateMetadata/rotateResourcesMetadataKeyService.test.js +2 -2
  126. package/src/all/background_page/service/migrateMetadata/migrateMetadataResourcesService.test.js +2 -2
  127. package/src/all/background_page/service/offline/canUseOfflineStorageService.js +16 -1
  128. package/src/all/background_page/service/offline/canUseOfflineStorageService.test.js +14 -6
  129. package/src/all/background_page/service/offline/getOrFindOfflineSettingsService.js +4 -1
  130. package/src/all/background_page/service/offline/getOrFindOfflineSettingsService.test.js +10 -1
  131. package/src/all/background_page/service/offline/offlineRetentionDataFlushService.js +12 -9
  132. package/src/all/background_page/service/offline/offlineRetentionDataFlushService.test.js +35 -24
  133. package/src/all/background_page/service/rbac/getOrFindRbacService.js +4 -1
  134. package/src/all/background_page/service/recover/parseRecoverUrlService.js +1 -1
  135. package/src/all/background_page/service/resource/export/exportResourcesService.test.js +3 -0
  136. package/src/all/background_page/service/resource/getOrFindOfflineResourcesService.js +30 -10
  137. package/src/all/background_page/service/resource/getOrFindOfflineResourcesService.test.js +108 -9
  138. package/src/all/background_page/service/resource/getOrFindResourcesService.js +30 -10
  139. package/src/all/background_page/service/resource/getOrFindResourcesService.test.js +99 -9
  140. package/src/all/background_page/service/resourceType/getOrFindResourceTypesService.js +4 -1
  141. package/src/all/background_page/service/resourceType/getOrFindResourceTypesService.test.js +10 -2
  142. package/src/all/background_page/service/secret/decryptAndParseResourceSecretService.js +1 -1
  143. package/src/all/background_page/service/sessionTimestamps/getSessionTimestampsService.js +48 -0
  144. package/src/all/background_page/service/sessionTimestamps/getSessionTimestampsService.test.js +66 -0
  145. package/src/all/background_page/service/sessionTimestamps/updateSessionTimestampsService.js +102 -0
  146. package/src/all/background_page/service/sessionTimestamps/updateSessionTimestampsService.test.js +221 -0
  147. package/src/all/background_page/service/{local_storage/activeSessionLocalStorage.js → session_storage/activeSessionSessionStorage.js} +17 -17
  148. package/src/all/background_page/service/{local_storage/activeSessionLocalStorage.test.js → session_storage/activeSessionSessionStorage.test.js} +31 -34
  149. package/src/all/background_page/service/setup/parseSetupUrlService.js +3 -2
  150. package/src/all/background_page/service/setup/parseSetupUrlService.test.js +195 -24
  151. package/src/all/background_page/service/share/shareFoldersService.test.js +4 -4
  152. package/src/all/background_page/service/share/shareResourceService.test.js +4 -4
  153. package/src/all/background_page/service/theme/findThemesService.js +38 -0
  154. package/src/all/background_page/service/theme/findThemesService.test.js +63 -0
  155. package/src/all/background_page/service/theme/updateThemeService.js +39 -0
  156. package/src/all/background_page/service/theme/updateThemeService.test.js +65 -0
  157. package/src/all/background_page/service/toolbar/toolbarService.js +20 -10
  158. package/src/all/background_page/service/toolbar/toolbarService.test.js +82 -6
  159. package/src/all/background_page/service/user/getOrFindMeService.js +4 -1
  160. package/src/all/background_page/service/user/getOrFindMeService.test.js +10 -2
  161. package/src/all/background_page/service/webIntegration/parseWebIntegrationUrlService.js +11 -6
  162. package/src/all/background_page/service/webIntegration/parseWebIntegrationUrlService.test.js +7 -9
  163. package/src/all/background_page/utils/format/formDataUtils.test.js +1 -1
  164. package/src/all/background_page/utils/openpgp/openpgpAssertions.js +1 -1
  165. package/src/all/webAccessibleResources/js/themes/stylesheet.js +1 -1
  166. package/src/chrome-mv3/manifest.json +1 -1
  167. package/src/chrome-mv3/serviceWorker/service/network/requestFetchOffscreenService.js +1 -1
  168. package/src/chrome-mv3/serviceWorker/service/network/responseFetchOffscreenService.js +7 -4
  169. package/src/firefox/manifest.json +1 -1
  170. package/src/safari/manifest.json +1 -1
  171. package/test/matchers/toBeOpenpgpKeySignedBy.js +13 -14
  172. package/test/mocks/mockJsDomPolyfill.js +0 -2
  173. package/webpack/common-blocks.js +13 -13
  174. package/webpack/expectedBuildArtifacts.js +1 -1
  175. package/webpack/passboltEnvPlugin.js +1 -1
  176. package/webpack.common.config.js +2 -0
  177. package/webpack.config.js +4 -5
  178. package/webpack.safari-background-page.config.js +38 -31
  179. package/src/all/background_page/model/theme/themeModel.js +0 -66
  180. package/src/all/background_page/model/theme/themeModel.test.js +0 -73
  181. package/src/all/background_page/service/activeSession/findAndUpdateActiveSessionLocalStorageService.test.js +0 -776
  182. package/src/chrome/manifest.json +0 -51
  183. package/src/chrome/polyfill/clipboard/edgeBackgroundPageClipboardService.js +0 -31
  184. package/src/chrome/polyfill/clipboard/edgeBackgroundPageClipboardService.test.js +0 -53
  185. package/webpack.chromium-mv2.config.js +0 -40
@@ -11,11 +11,11 @@
11
11
  * @link https://www.passbolt.com Passbolt(tm)
12
12
  * @since 2.11.0
13
13
  */
14
- import FindAndUpdateActiveSessionLocalStorageService from "../../service/activeSession/findAndUpdateActiveSessionLocalStorageService";
14
+ import FindAndUpdateActiveSessionSessionStorageService from "../../service/activeSession/findAndUpdateActiveSessionSessionStorageService";
15
15
 
16
16
  class IsMfaRequiredController {
17
17
  /**
18
- * FindAndUpdateActiveSessionLocalStorageController Constructor
18
+ * FindAndUpdateActiveSessionSessionStorageController Constructor
19
19
  *
20
20
  * @param {Worker} worker
21
21
  * @param {string} requestId
@@ -25,7 +25,7 @@ class IsMfaRequiredController {
25
25
  constructor(worker, requestId, apiClientOptions, account) {
26
26
  this.worker = worker;
27
27
  this.requestId = requestId;
28
- this.findAndUpdateActiveSessionLocalStorageService = new FindAndUpdateActiveSessionLocalStorageService(
28
+ this.findAndUpdateActiveSessionSessionStorageService = new FindAndUpdateActiveSessionSessionStorageService(
29
29
  account,
30
30
  apiClientOptions,
31
31
  );
@@ -48,7 +48,8 @@ class IsMfaRequiredController {
48
48
  * @returns {Promise<boolean>}
49
49
  */
50
50
  async exec() {
51
- const activeSession = await this.findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
51
+ const activeSession =
52
+ await this.findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
52
53
  return activeSession.isMfaRequired;
53
54
  }
54
55
  }
@@ -30,7 +30,7 @@ describe("IsMfaRequiredController", () => {
30
30
  const account = new AccountEntity(defaultAccountDto());
31
31
  const controller = new IsMfaRequiredController(null, null, defaultApiClientOptions(), account);
32
32
  jest
33
- .spyOn(controller.findAndUpdateActiveSessionLocalStorageService, "findAndUpdateAuthenticationStatus")
33
+ .spyOn(controller.findAndUpdateActiveSessionSessionStorageService, "findAndUpdateAuthenticationStatus")
34
34
  .mockImplementation(
35
35
  async () =>
36
36
  new UserActiveSessionEntity(
@@ -51,7 +51,7 @@ describe("IsMfaRequiredController", () => {
51
51
  const account = new AccountEntity(defaultAccountDto());
52
52
  const controller = new IsMfaRequiredController(null, null, defaultApiClientOptions(), account);
53
53
  jest
54
- .spyOn(controller.findAndUpdateActiveSessionLocalStorageService, "findAndUpdateAuthenticationStatus")
54
+ .spyOn(controller.findAndUpdateActiveSessionSessionStorageService, "findAndUpdateAuthenticationStatus")
55
55
  .mockImplementation(
56
56
  async () =>
57
57
  new UserActiveSessionEntity(defaultUserActiveSessionDto({ is_authenticated: true, is_mfa_required: false })),
@@ -69,7 +69,7 @@ describe("IsMfaRequiredController", () => {
69
69
 
70
70
  const authStatus = defaultUserActiveSessionDto({ is_authenticated: false, is_mfa_required: false });
71
71
  jest
72
- .spyOn(controller.findAndUpdateActiveSessionLocalStorageService, "findAndUpdateAuthenticationStatus")
72
+ .spyOn(controller.findAndUpdateActiveSessionSessionStorageService, "findAndUpdateAuthenticationStatus")
73
73
  .mockImplementation(async () => new UserActiveSessionEntity(authStatus));
74
74
 
75
75
  const isMfaRequired = await controller.exec();
@@ -23,7 +23,7 @@ import { OpenpgpAssertion } from "../../utils/openpgp/openpgpAssertions";
23
23
 
24
24
  const keyring = new Keyring();
25
25
 
26
- beforeAll(() => {
26
+ beforeEach(() => {
27
27
  enableFetchMocks();
28
28
  });
29
29
 
@@ -26,7 +26,7 @@ import { adminAccountDto } from "../../model/entity/account/accountEntity.test.d
26
26
  const keyring = new Keyring();
27
27
  jest.mock("../../service/passphrase/getPassphraseService");
28
28
 
29
- beforeAll(() => {
29
+ beforeEach(() => {
30
30
  enableFetchMocks();
31
31
  });
32
32
 
@@ -27,6 +27,10 @@ import AppBootstrapPagemod from "../../pagemod/appBootstrapPagemod";
27
27
  import GetActiveAccountService from "../../service/account/getActiveAccountService";
28
28
  import BuildApiClientOptionsService from "../../service/account/buildApiClientOptionsService";
29
29
  import GetOrFindActiveSessionService from "../../service/activeSession/getOrFindActiveSessionService";
30
+ import ActiveSessionSessionStorage from "../../service/session_storage/activeSessionSessionStorage";
31
+ import AuthenticationStatusService from "../../service/authenticationStatusService";
32
+ import MfaAuthenticationRequiredError from "../../error/mfaAuthenticationRequiredError";
33
+ import LocalLogoutService from "../../service/auth/localLogoutService";
30
34
 
31
35
  class OnExtensionInstalledController {
32
36
  /**
@@ -68,9 +72,11 @@ class OnExtensionInstalledController {
68
72
  }
69
73
 
70
74
  /**
71
- * On update the extension, for pagemod with refresh option and tabs that match the url refresh it
75
+ * On update the extension, sign the user out, then for pagemod with refresh option and tabs that match the url
76
+ * refresh it.
72
77
  */
73
78
  static async onUpdate() {
79
+ await OnExtensionInstalledController.signOutIfAuthenticated();
74
80
  // Apply on tabs that match the pagemod url regex with refresh option
75
81
  await browser.tabs.query({}).then(reloadTabsMatchPagemodUrl);
76
82
  await OnExtensionInstalledController.updateToolbarIcon();
@@ -82,35 +88,7 @@ class OnExtensionInstalledController {
82
88
  * deteriorates the user experience, therefore it has been decided to sign the user out.
83
89
  */
84
90
  static async onBrowserUpdate() {
85
- const user = User.getInstance();
86
- // Check if user is valid
87
- if (!user.isValid()) {
88
- return;
89
- }
90
- let activeSessionEntity, account;
91
- try {
92
- account = await GetActiveAccountService.get();
93
- const apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
94
- const getOrFindActiveSessionService = new GetOrFindActiveSessionService(account, apiClientOptions);
95
- // use the cached data as the worker could wake up every 30 secondes.
96
- activeSessionEntity = await getOrFindActiveSessionService.getOrFind();
97
- } catch (error) {
98
- console.error(error);
99
- // Service is unavailable, do nothing...
100
- Log.write({
101
- level: "debug",
102
- message: "Could not check if the user is authenticated, the service is unavailable.",
103
- });
104
- return;
105
- }
106
- // Do nothing if user is not authenticated
107
- if (!activeSessionEntity.isAuthenticated) {
108
- return;
109
- }
110
- // Logout authenticated user to prevent to ask passphrase for SSO users
111
- const apiClientOptions = await user.getApiClientOptions();
112
- const authModel = new AuthModel(apiClientOptions, account);
113
- await authModel.logout();
91
+ await OnExtensionInstalledController.signOutIfAuthenticated();
114
92
  /*
115
93
  * Reload only tabs that match passbolt app url. Reload is necessary as the application loaded in the tab
116
94
  * could be unresponsive due to the forced triggered sign-out.
@@ -121,6 +99,59 @@ class OnExtensionInstalledController {
121
99
  await browser.tabs.query({}).then(reloadTabsMatchPassboltAppUrl);
122
100
  }
123
101
 
102
+ /**
103
+ * Sign the user out if they are still signed in on the server, or if the server cannot be reached.
104
+ * The extension and browser updates clear the session storage (passphrase, metadata keys, active session), the user
105
+ * is still signed in on the server but would be asked for their passphrase, which SSO users may not know. Therefore
106
+ * it has been decided to sign the user out.
107
+ * - Signed in on the server: sign out with the API, and locally if the API logout fails.
108
+ * - Server not reachable: the session cookie may still be valid (online session) or an offline session may have
109
+ * been running, sign out locally.
110
+ * The active session was kept in the local storage before it moved to the session storage, the legacy entry is
111
+ * removed.
112
+ * It never throws, so the callers can continue with the tabs reload.
113
+ * @returns {Promise<void>}
114
+ */
115
+ static async signOutIfAuthenticated() {
116
+ let account, apiClientOptions;
117
+ try {
118
+ // Throws if no account is associated with the extension.
119
+ account = await GetActiveAccountService.get();
120
+ // Remove any residual legacy local storage for active session
121
+ await browser.storage.local.remove(new ActiveSessionSessionStorage(account).storageKey);
122
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
123
+ } catch (error) {
124
+ console.error(error);
125
+ Log.write({ level: "debug", message: "Could not retrieve the account associated with the extension." });
126
+ return;
127
+ }
128
+
129
+ try {
130
+ // The session storage is cleared, ask the server if the user is still signed in.
131
+ let isAuthenticated;
132
+ try {
133
+ isAuthenticated = await new AuthenticationStatusService(apiClientOptions).isAuthenticated();
134
+ } catch (error) {
135
+ if (!(error instanceof MfaAuthenticationRequiredError)) {
136
+ throw error;
137
+ }
138
+ isAuthenticated = true;
139
+ }
140
+ if (isAuthenticated) {
141
+ await new AuthModel(apiClientOptions, account).logout();
142
+ }
143
+ } catch (error) {
144
+ console.error(error);
145
+ // The server is not reachable or the API logout failed, the session cookie may still be valid.
146
+ try {
147
+ await new LocalLogoutService(account, apiClientOptions).exec();
148
+ } catch (error) {
149
+ console.error(error);
150
+ Log.write({ level: "debug", message: "Could not sign the user out after the update." });
151
+ }
152
+ }
153
+ }
154
+
124
155
  /**
125
156
  * Updates the Passbolt icon in the toolbar according to the sign-in status of the current user.
126
157
  * @returns {Promise<void>}
@@ -23,6 +23,9 @@ import AccountEntity from "../../model/entity/account/accountEntity";
23
23
  import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
24
24
  import { defaultUserActiveSessionDto } from "passbolt-styleguide/src/shared/models/entity/session/userActiveSessionEntity.test.data";
25
25
  import GetOrFindActiveSessionService from "../../service/activeSession/getOrFindActiveSessionService";
26
+ import AuthenticationStatusService from "../../service/authenticationStatusService";
27
+ import MfaAuthenticationRequiredError from "../../error/mfaAuthenticationRequiredError";
28
+ import LocalLogoutService from "../../service/auth/localLogoutService";
26
29
 
27
30
  // Reset the modules before each test.
28
31
  beforeEach(() => {
@@ -41,13 +44,13 @@ describe("OnExtensionInstalledController", () => {
41
44
  const tabs = [
42
45
  {
43
46
  id: 1,
44
- url: "https://passbolt.dev/setup/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0",
47
+ url: "https://passbolt.local/setup/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0",
45
48
  },
46
49
  {
47
50
  id: 2,
48
- url: "https://passbolt.dev/setup/recover/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0",
51
+ url: "https://passbolt.local/setup/recover/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0",
49
52
  },
50
- { id: 3, url: "https://passbolt.dev/auth/login" },
53
+ { id: 3, url: "https://passbolt.local/auth/login" },
51
54
  { id: 4, url: "https://localhost" },
52
55
  { id: 5, url: "https://chromewebstore.google.com/id/passbolt" },
53
56
  { id: 6, url: "https://addons.mozilla.org/id/passbolt" },
@@ -83,14 +86,14 @@ describe("OnExtensionInstalledController", () => {
83
86
  const tabs = [
84
87
  {
85
88
  id: 1,
86
- url: "https://passbolt.dev/setup/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0",
89
+ url: "https://passbolt.local/setup/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0",
87
90
  },
88
91
  {
89
92
  id: 2,
90
- url: "https://passbolt.dev/setup/recover/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0",
93
+ url: "https://passbolt.local/setup/recover/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0",
91
94
  },
92
- { id: 3, url: "https://passbolt.dev/auth/login" },
93
- { id: 4, url: "https://passbolt.dev" },
95
+ { id: 3, url: "https://passbolt.local/auth/login" },
96
+ { id: 4, url: "https://passbolt.local" },
94
97
  { id: 5, url: "https://passbolt.com" },
95
98
  { id: 6, url: "https://localhost" },
96
99
  ];
@@ -98,8 +101,9 @@ describe("OnExtensionInstalledController", () => {
98
101
  jest.spyOn(OnExtensionInstalledController, "onUpdate");
99
102
  jest.spyOn(WebNavigationService, "exec");
100
103
  jest.spyOn(browser.tabs, "query").mockImplementationOnce(() => Promise.resolve(tabs));
101
- jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => {});
102
- jest.spyOn(UserSettings.prototype, "getDomain").mockImplementation(() => "https://passbolt.dev");
104
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => new AccountEntity(defaultAccountDto()));
105
+ jest.spyOn(UserSettings.prototype, "getDomain").mockImplementation(() => "https://passbolt.local");
106
+ jest.spyOn(AuthenticationStatusService.prototype, "isAuthenticated").mockImplementation(async () => false);
103
107
  // process
104
108
  await OnExtensionInstalledController.exec(details);
105
109
  // expectation
@@ -122,14 +126,17 @@ describe("OnExtensionInstalledController", () => {
122
126
  };
123
127
  // mock function
124
128
  jest.spyOn(OnExtensionInstalledController, "onBrowserUpdate");
125
- jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => false);
129
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => {
130
+ throw new Error("No account");
131
+ });
126
132
  jest.spyOn(AuthModel.prototype, "logout");
133
+ jest.spyOn(browser.tabs, "reload");
127
134
  // process
128
135
  await OnExtensionInstalledController.exec(details);
129
136
  // expectation
130
137
  expect(OnExtensionInstalledController.onBrowserUpdate).toHaveBeenCalled();
131
- expect(User.getInstance().isValid).toHaveBeenCalledTimes(1);
132
138
  expect(AuthModel.prototype.logout).toHaveBeenCalledTimes(0);
139
+ expect(browser.tabs.reload).not.toHaveBeenCalled();
133
140
  });
134
141
 
135
142
  it("Should exec browser update if the reason is browser update", async () => {
@@ -139,27 +146,25 @@ describe("OnExtensionInstalledController", () => {
139
146
  reason: browser.runtime.OnInstalledReason.BROWSER_UPDATE,
140
147
  };
141
148
  const tabs = [
142
- { id: 1, url: "https://passbolt.dev/app/passwords" },
149
+ { id: 1, url: "https://passbolt.local/app/passwords" },
143
150
  {
144
151
  id: 2,
145
- url: "https://passbolt.dev/setup/recover/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0",
152
+ url: "https://passbolt.local/setup/recover/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0",
146
153
  },
147
- { id: 3, url: "https://passbolt.dev/auth/login" },
148
- { id: 4, url: "https://passbolt.dev" },
154
+ { id: 3, url: "https://passbolt.local/auth/login" },
155
+ { id: 4, url: "https://passbolt.local" },
149
156
  { id: 5, url: "https://passbolt.com" },
150
157
  { id: 6, url: "https://localhost" },
151
158
  ];
152
159
  // mock function
153
160
  jest.spyOn(OnExtensionInstalledController, "onBrowserUpdate");
154
161
  jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => true);
155
- jest.spyOn(UserSettings.prototype, "getDomain").mockImplementation(() => "https://passbolt.dev");
162
+ jest.spyOn(UserSettings.prototype, "getDomain").mockImplementation(() => "https://passbolt.local");
156
163
  jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => new AccountEntity(defaultAccountDto()));
157
164
  jest.spyOn(AuthModel.prototype, "logout").mockImplementation(() => {});
158
165
  jest.spyOn(browser.tabs, "query").mockImplementation(() => Promise.resolve(tabs));
159
166
  jest.spyOn(browser.tabs, "reload");
160
- jest
161
- .spyOn(GetOrFindActiveSessionService.prototype, "getOrFind")
162
- .mockImplementation(() => new UserActiveSessionEntity(defaultUserActiveSessionDto({ is_authenticated: true })));
167
+ jest.spyOn(AuthenticationStatusService.prototype, "isAuthenticated").mockImplementation(async () => true);
163
168
  // process
164
169
  await OnExtensionInstalledController.exec(details);
165
170
  // expectation
@@ -188,4 +193,111 @@ describe("OnExtensionInstalledController", () => {
188
193
  expect(OnExtensionInstalledController.onBrowserUpdate).not.toHaveBeenCalled();
189
194
  });
190
195
  });
196
+
197
+ describe("OnExtensionInstalledController::signOutIfAuthenticated", () => {
198
+ const appTab = { id: 1, url: "https://passbolt.local/app/passwords" };
199
+
200
+ beforeEach(() => {
201
+ jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => true);
202
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => new AccountEntity(defaultAccountDto()));
203
+ jest.spyOn(browser.tabs, "query").mockImplementation(() => Promise.resolve([appTab]));
204
+ jest.spyOn(browser.tabs, "reload");
205
+ jest.spyOn(AuthModel.prototype, "logout").mockImplementation(() => {});
206
+ // The toolbar icon reads the active session once the user is signed out.
207
+ jest
208
+ .spyOn(GetOrFindActiveSessionService.prototype, "getOrFind")
209
+ .mockImplementation(
210
+ () => new UserActiveSessionEntity(defaultUserActiveSessionDto({ is_authenticated: false })),
211
+ );
212
+ });
213
+
214
+ it("Should sign out a user who still has to complete the MFA on the server", async () => {
215
+ expect.assertions(2);
216
+ jest.spyOn(AuthenticationStatusService.prototype, "isAuthenticated").mockImplementation(async () => {
217
+ throw new MfaAuthenticationRequiredError();
218
+ });
219
+ jest.spyOn(LocalLogoutService.prototype, "exec");
220
+
221
+ await OnExtensionInstalledController.exec({ reason: browser.runtime.OnInstalledReason.UPDATE });
222
+
223
+ expect(AuthModel.prototype.logout).toHaveBeenCalledTimes(1);
224
+ expect(LocalLogoutService.prototype.exec).not.toHaveBeenCalled();
225
+ });
226
+
227
+ it("Should not sign out a user who is not signed in on the server", async () => {
228
+ expect.assertions(3);
229
+ jest.spyOn(AuthenticationStatusService.prototype, "isAuthenticated").mockImplementation(async () => false);
230
+ jest.spyOn(LocalLogoutService.prototype, "exec");
231
+
232
+ await OnExtensionInstalledController.exec({ reason: browser.runtime.OnInstalledReason.UPDATE });
233
+
234
+ expect(AuthModel.prototype.logout).not.toHaveBeenCalled();
235
+ expect(LocalLogoutService.prototype.exec).not.toHaveBeenCalled();
236
+ expect(browser.tabs.reload).toHaveBeenCalledWith(appTab.id);
237
+ });
238
+
239
+ it("Should sign out with the local logout if the server is not reachable", async () => {
240
+ expect.assertions(3);
241
+ jest.spyOn(AuthenticationStatusService.prototype, "isAuthenticated").mockImplementation(async () => {
242
+ throw new Error("Server not reachable");
243
+ });
244
+ jest.spyOn(LocalLogoutService.prototype, "exec").mockImplementation(() => {});
245
+
246
+ await OnExtensionInstalledController.exec({ reason: browser.runtime.OnInstalledReason.UPDATE });
247
+
248
+ expect(AuthModel.prototype.logout).not.toHaveBeenCalled();
249
+ expect(LocalLogoutService.prototype.exec).toHaveBeenCalledTimes(1);
250
+ expect(browser.tabs.reload).toHaveBeenCalledWith(appTab.id);
251
+ });
252
+
253
+ it("Should sign out with the local logout if the server logout fails", async () => {
254
+ expect.assertions(2);
255
+ jest.spyOn(AuthenticationStatusService.prototype, "isAuthenticated").mockImplementation(async () => true);
256
+ jest.spyOn(AuthModel.prototype, "logout").mockImplementation(() => {
257
+ throw new Error("Unexpected error");
258
+ });
259
+ jest.spyOn(LocalLogoutService.prototype, "exec").mockImplementation(() => {});
260
+
261
+ await OnExtensionInstalledController.exec({ reason: browser.runtime.OnInstalledReason.UPDATE });
262
+
263
+ expect(LocalLogoutService.prototype.exec).toHaveBeenCalledTimes(1);
264
+ expect(browser.tabs.reload).toHaveBeenCalledWith(appTab.id);
265
+ });
266
+
267
+ it("Should remove the legacy active session from the local storage", async () => {
268
+ expect.assertions(1);
269
+ const account = new AccountEntity(defaultAccountDto());
270
+ jest.spyOn(AuthenticationStatusService.prototype, "isAuthenticated").mockImplementation(async () => false);
271
+ const legacyStorageKey = `active_session-${account.id}`;
272
+ await browser.storage.local.set({ [legacyStorageKey]: defaultUserActiveSessionDto() });
273
+
274
+ await OnExtensionInstalledController.exec({ reason: browser.runtime.OnInstalledReason.UPDATE });
275
+
276
+ expect(browser.storage.local.store[legacyStorageKey]).toBeUndefined();
277
+ });
278
+
279
+ it("Should still process the tabs if no account is associated with the extension", async () => {
280
+ expect.assertions(3);
281
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => {
282
+ throw new Error("No account");
283
+ });
284
+ jest.spyOn(AuthenticationStatusService.prototype, "isAuthenticated");
285
+
286
+ await OnExtensionInstalledController.exec({ reason: browser.runtime.OnInstalledReason.UPDATE });
287
+
288
+ expect(AuthenticationStatusService.prototype.isAuthenticated).not.toHaveBeenCalled();
289
+ expect(AuthModel.prototype.logout).not.toHaveBeenCalled();
290
+ expect(browser.tabs.query).toHaveBeenCalledTimes(1);
291
+ });
292
+
293
+ it("Should reload the app tabs on browser update even if the user was not signed in", async () => {
294
+ expect.assertions(2);
295
+ jest.spyOn(AuthenticationStatusService.prototype, "isAuthenticated").mockImplementation(async () => false);
296
+
297
+ await OnExtensionInstalledController.exec({ reason: browser.runtime.OnInstalledReason.BROWSER_UPDATE });
298
+
299
+ expect(AuthModel.prototype.logout).not.toHaveBeenCalled();
300
+ expect(browser.tabs.reload).toHaveBeenCalledWith(appTab.id);
301
+ });
302
+ });
191
303
  });
@@ -31,6 +31,17 @@ import {
31
31
  } from "passbolt-styleguide/src/shared/models/entity/session/userActiveSessionEntity.test.data";
32
32
  import GetOrFindResourcesService from "../../service/resource/getOrFindResourcesService";
33
33
  import GetOrFindOfflineResourcesService from "../../service/resource/getOrFindOfflineResourcesService";
34
+ import GetOrFindActiveSessionService from "../../service/activeSession/getOrFindActiveSessionService";
35
+ import ResourceLocalStorage from "../../service/local_storage/resourceLocalStorage";
36
+ import ResourceTypeLocalStorage from "../../service/local_storage/resourceTypeLocalStorage";
37
+ import { resourceTypesCollectionDto } from "passbolt-styleguide/src/shared/models/entity/resourceType/resourceTypesCollection.test.data";
38
+ import {
39
+ defaultResourceDto,
40
+ resourceStandaloneCustomFieldsDto,
41
+ resourceStandaloneNoteDto,
42
+ resourceStandaloneTotpDto,
43
+ } from "passbolt-styleguide/src/shared/models/entity/resource/resourceEntity.test.data";
44
+ import { defaultResourceMetadataDto } from "passbolt-styleguide/src/shared/models/entity/resource/metadata/resourceMetadataEntity.test.data";
34
45
 
35
46
  describe("InformCallToActionController", () => {
36
47
  let requestId, worker, port, controller, suggestedResources;
@@ -97,6 +108,41 @@ describe("InformCallToActionController", () => {
97
108
  expect(port.emit).toHaveBeenCalledWith(requestId, "SUCCESS", suggestedResources.length);
98
109
  });
99
110
 
111
+ it.each(["username", "password", "otp"])(
112
+ "Should count only the password or TOTP resource, never a matching note or custom fields resource, for a %s field",
113
+ async (fieldType) => {
114
+ expect.assertions(1);
115
+ // Let the real service run against the local storage to check the resource type filtering.
116
+ GetOrFindResourcesService.prototype.getOrFindSuggested.mockRestore();
117
+
118
+ const matchingPassword = defaultResourceDto({
119
+ metadata: defaultResourceMetadataDto({ uris: ["https://passbolt.com"] }),
120
+ });
121
+ const matchingTotp = resourceStandaloneTotpDto({
122
+ metadata: defaultResourceMetadataDto({ uris: ["https://passbolt.com"] }),
123
+ });
124
+ const matchingNote = resourceStandaloneNoteDto({
125
+ metadata: defaultResourceMetadataDto({ uris: ["https://passbolt.com"] }),
126
+ });
127
+ const matchingCustomFields = resourceStandaloneCustomFieldsDto({
128
+ metadata: defaultResourceMetadataDto({ uris: ["https://passbolt.com"] }),
129
+ });
130
+
131
+ jest
132
+ .spyOn(GetOrFindActiveSessionService.prototype, "getOrFind")
133
+ .mockResolvedValue(new UserActiveSessionEntity(defaultUserActiveSessionDto()));
134
+ jest
135
+ .spyOn(ResourceLocalStorage, "get")
136
+ .mockResolvedValue([matchingPassword, matchingTotp, matchingNote, matchingCustomFields]);
137
+ jest.spyOn(ResourceTypeLocalStorage.prototype, "isStaleSinceLastLoggedIn").mockResolvedValue(false);
138
+ jest.spyOn(ResourceTypeLocalStorage.prototype, "getData").mockResolvedValue(resourceTypesCollectionDto());
139
+
140
+ await controller.getSuggestedResourcesCount(requestId, fieldType);
141
+
142
+ expect(port.emit).toHaveBeenCalledWith(requestId, "SUCCESS", 1);
143
+ },
144
+ );
145
+
100
146
  it("Should catch and emit ERROR when getOrFindSuggested throws an error", async () => {
101
147
  expect.assertions(1);
102
148
 
@@ -25,7 +25,7 @@ import MockPort from "passbolt-styleguide/src/react-extension/test/mock/MockPort
25
25
  jest.mock("../../service/progress/progressService");
26
26
  jest.mock("../../service/local_storage/resourceLocalStorage");
27
27
 
28
- beforeAll(() => {
28
+ beforeEach(() => {
29
29
  enableFetchMocks();
30
30
  });
31
31
 
@@ -0,0 +1,54 @@
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.18.0
13
+ */
14
+ import GetSessionTimestampsService from "../../service/sessionTimestamps/getSessionTimestampsService";
15
+
16
+ /**
17
+ * Returns the session timestamps (last_logged_in, last_seen_online).
18
+ */
19
+ class GetSessionTimestampsController {
20
+ /**
21
+ * @param {Worker} worker The worker
22
+ * @param {string} requestId The request identifier
23
+ * @param {AccountEntity} account The user account
24
+ */
25
+ constructor(worker, requestId, account) {
26
+ this.worker = worker;
27
+ this.requestId = requestId;
28
+ this.getSessionTimestampsService = new GetSessionTimestampsService(account);
29
+ }
30
+
31
+ /**
32
+ * Wrapper of exec function to run it with worker.
33
+ * @return {Promise<void>}
34
+ */
35
+ async _exec() {
36
+ try {
37
+ const sessionTimestampsEntity = await this.exec();
38
+ this.worker.port.emit(this.requestId, "SUCCESS", sessionTimestampsEntity);
39
+ } catch (error) {
40
+ console.error(error);
41
+ this.worker.port.emit(this.requestId, "ERROR", error);
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Get the session timestamps.
47
+ * @return {Promise<SessionTimestampsEntity|null>} null if none are stored.
48
+ */
49
+ async exec() {
50
+ return this.getSessionTimestampsService.get();
51
+ }
52
+ }
53
+
54
+ export default GetSessionTimestampsController;
@@ -0,0 +1,91 @@
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.18.0
13
+ */
14
+ import GetSessionTimestampsController from "./getSessionTimestampsController";
15
+ import SessionTimestampsEntity from "passbolt-styleguide/src/shared/models/entity/sessionTimestamps/sessionTimestampsEntity";
16
+ import { defaultSessionTimestampsDto } from "passbolt-styleguide/src/shared/models/entity/sessionTimestamps/sessionTimestampsEntity.test.data";
17
+ import AccountEntity from "../../model/entity/account/accountEntity";
18
+ import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
19
+
20
+ beforeEach(() => {
21
+ jest.clearAllMocks();
22
+ });
23
+
24
+ describe("GetSessionTimestampsController", () => {
25
+ let account, worker, controller;
26
+
27
+ beforeEach(async () => {
28
+ account = new AccountEntity(defaultAccountDto());
29
+ worker = { port: { emit: jest.fn() } };
30
+ controller = new GetSessionTimestampsController(worker, "request-id", account);
31
+ await controller.getSessionTimestampsService.sessionTimestampsLocalStorage.flush();
32
+ });
33
+
34
+ describe("::exec", () => {
35
+ it("should return the session timestamps stored in the local storage.", async () => {
36
+ expect.assertions(2);
37
+ const sessionTimestampsDto = defaultSessionTimestampsDto();
38
+ await controller.getSessionTimestampsService.sessionTimestampsLocalStorage.setData(
39
+ new SessionTimestampsEntity(sessionTimestampsDto),
40
+ );
41
+
42
+ const result = await controller.exec();
43
+
44
+ expect(result).toBeInstanceOf(SessionTimestampsEntity);
45
+ expect(result.toDto()).toEqual(sessionTimestampsDto);
46
+ });
47
+
48
+ it("should return null if no session timestamps are stored.", async () => {
49
+ expect.assertions(1);
50
+ const result = await controller.exec();
51
+ expect(result).toBeNull();
52
+ });
53
+
54
+ it("should throw if the session timestamps cannot be retrieved.", async () => {
55
+ expect.assertions(1);
56
+ const error = new Error("Failed to retrieve the session timestamps");
57
+ jest.spyOn(controller.getSessionTimestampsService, "get").mockRejectedValue(error);
58
+
59
+ await expect(controller.exec()).rejects.toThrow(error.message);
60
+ });
61
+ });
62
+
63
+ describe("::_exec", () => {
64
+ it("should emit SUCCESS with the session timestamps on the worker port.", async () => {
65
+ expect.assertions(1);
66
+ const sessionTimestampsEntity = new SessionTimestampsEntity(defaultSessionTimestampsDto());
67
+ await controller.getSessionTimestampsService.sessionTimestampsLocalStorage.setData(sessionTimestampsEntity);
68
+
69
+ await controller._exec();
70
+
71
+ expect(worker.port.emit).toHaveBeenCalledWith("request-id", "SUCCESS", sessionTimestampsEntity);
72
+ });
73
+
74
+ it("should emit SUCCESS with null on the worker port if no session timestamps are stored.", async () => {
75
+ expect.assertions(1);
76
+ await controller._exec();
77
+ expect(worker.port.emit).toHaveBeenCalledWith("request-id", "SUCCESS", null);
78
+ });
79
+
80
+ it("should emit ERROR on the worker port if the session timestamps cannot be retrieved.", async () => {
81
+ expect.assertions(1);
82
+ const error = new Error("Failed to retrieve the session timestamps");
83
+ jest.spyOn(controller.getSessionTimestampsService, "get").mockRejectedValue(error);
84
+ jest.spyOn(console, "error").mockImplementation(() => {});
85
+
86
+ await controller._exec();
87
+
88
+ expect(worker.port.emit).toHaveBeenCalledWith("request-id", "ERROR", error);
89
+ });
90
+ });
91
+ });
@@ -105,7 +105,7 @@ describe("ShareResourcesController", () => {
105
105
  JSON.stringify(secretDto),
106
106
  await OpenpgpAssertion.readKeyOrFail(pgpKeys.admin.public),
107
107
  );
108
- const resourceForShareDto = new defaultResourceV4Dto({
108
+ const resourceForShareDto = defaultResourceV4Dto({
109
109
  ...resourceDto,
110
110
  secrets: [plaintextSecretPasswordAndDescriptionDto({ resource_id: resourceId, data: resourceSecretData })],
111
111
  });
@@ -115,7 +115,7 @@ describe("ShareResourcesController", () => {
115
115
  // Mock keyring.
116
116
  jest.spyOn(Keyring.prototype, "sync").mockImplementation(jest.fn);
117
117
  const keyring = new Keyring();
118
- keyring.importPublic(pgpKeys.carol.public, pgpKeys.carol.userId);
118
+ await keyring.importPublic(pgpKeys.carol.public, pgpKeys.carol.userId);
119
119
  // Mock the share request.
120
120
  let shareRequestData;
121
121
  jest