passbolt-browser-extension 4.8.1 → 4.8.2

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 (59) hide show
  1. package/CHANGELOG.md +12 -3
  2. package/RELEASE_NOTES.md +9 -7
  3. package/package.json +1 -1
  4. package/src/all/background_page/controller/extension/onExtensionInstalledController.js +64 -6
  5. package/src/all/background_page/controller/extension/onExtensionInstalledController.test.js +57 -3
  6. package/src/all/background_page/controller/passwordExpiry/deletePasswordExpirySettingsController.test.js +1 -1
  7. package/src/all/background_page/controller/passwordExpiry/getOrFindPasswordExpirySettingsController.test.js +1 -1
  8. package/src/all/background_page/controller/passwordExpiry/savePasswordExpirySettingsController.test.js +1 -1
  9. package/src/all/background_page/controller/passwordPolicies/findPasswordPoliciesController.test.js +1 -1
  10. package/src/all/background_page/controller/passwordPolicies/savePasswordPoliciesController.test.js +1 -1
  11. package/src/all/background_page/controller/userPassphrasePolicies/findUserPassphrasePoliciesController.test.js +1 -1
  12. package/src/all/background_page/controller/userPassphrasePolicies/saveUserPassphrasePoliciesController.test.js +1 -1
  13. package/src/all/background_page/model/passwordExpiry/passwordExpirySettingsModel.test.js +1 -1
  14. package/src/all/background_page/model/passwordPolicies/passwordPoliciesModel.test.js +1 -1
  15. package/src/all/background_page/model/user.js +1 -0
  16. package/src/all/background_page/model/userPassphrasePolicies/userPassphrasePoliciesModel.test.js +1 -1
  17. package/src/all/background_page/pagemod/accountRecoveryPagemod.js +1 -1
  18. package/src/all/background_page/pagemod/appBootstrapPagemod.js +9 -7
  19. package/src/all/background_page/pagemod/appBootstrapPagemod.test.js +4 -4
  20. package/src/all/background_page/pagemod/appPagemod.js +3 -3
  21. package/src/all/background_page/pagemod/appPagemod.test.js +4 -6
  22. package/src/all/background_page/pagemod/authBootstrapPagemod.js +9 -7
  23. package/src/all/background_page/pagemod/authBootstrapPagemod.test.js +4 -4
  24. package/src/all/background_page/pagemod/authPagemod.js +3 -3
  25. package/src/all/background_page/pagemod/authPagemod.test.js +4 -4
  26. package/src/all/background_page/pagemod/informCallToActionPagemod.js +3 -3
  27. package/src/all/background_page/pagemod/informCallToActionPagemod.test.js +3 -3
  28. package/src/all/background_page/pagemod/informMenuPagemod.js +3 -3
  29. package/src/all/background_page/pagemod/informMenuPagemod.test.js +3 -3
  30. package/src/all/background_page/pagemod/pagemodManager.js +7 -3
  31. package/src/all/background_page/pagemod/pagemodManager.test.js +13 -13
  32. package/src/all/background_page/pagemod/publicWebsiteSignInPagemod.js +12 -8
  33. package/src/all/background_page/pagemod/publicWebsiteSignInPagemod.test.js +5 -6
  34. package/src/all/background_page/pagemod/quickAccessPagemod.js +3 -3
  35. package/src/all/background_page/pagemod/quickAccessPagemod.test.js +3 -4
  36. package/src/all/background_page/pagemod/recoverPagemod.js +1 -1
  37. package/src/all/background_page/pagemod/setupPagemod.js +1 -1
  38. package/src/all/background_page/pagemod/webIntegrationPagemod.js +9 -7
  39. package/src/all/background_page/service/account/buildApiClientOptionsService.js +4 -4
  40. package/src/all/background_page/service/account/buildApiClientOptionsService.test.js +4 -4
  41. package/src/all/background_page/service/account/getActiveAccountService.js +41 -0
  42. package/src/all/background_page/service/account/getActiveAccountService.test.js +53 -0
  43. package/src/all/background_page/service/account/getLegacyAccountService.js +2 -2
  44. package/src/all/background_page/service/api/passwordExpiry/passwordExpiryResourceService.test.js +1 -1
  45. package/src/all/background_page/service/api/passwordExpiry/passwordExpirySettingsService.test.js +1 -1
  46. package/src/all/background_page/service/api/passwordPolicies/passwordPoliciesService.test.js +1 -1
  47. package/src/all/background_page/service/api/userPassphrasePolicies/userPassphrasePoliciesService.test.js +1 -1
  48. package/src/all/background_page/service/auth/checkAuthStatusService.js +1 -1
  49. package/src/all/background_page/service/auth/startLoopAuthSessionCheckService.js +0 -1
  50. package/src/all/background_page/service/authenticationStatusService.js +6 -8
  51. package/src/all/background_page/service/authenticationStatusService.test.js +2 -2
  52. package/src/all/background_page/service/passwordExpirySettings/passwordExpirySettingsGetOrFindService.test.js +1 -1
  53. package/src/all/background_page/service/session_storage/keepSessionAliveService.js +4 -4
  54. package/src/all/background_page/service/toolbar/toolbarService.js +1 -1
  55. package/src/chrome/manifest.json +1 -1
  56. package/src/chrome-mv3/manifest.json +1 -1
  57. package/src/firefox/manifest.json +1 -1
  58. package/src/safari/manifest.json +1 -1
  59. package/test/mocks/mockExtension.js +2 -4
package/CHANGELOG.md CHANGED
@@ -3,8 +3,16 @@ All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
5
  ## [Unreleased]
6
+ ## [4.8.2] - 2024-06-13
7
+ ### Improved
8
+ - PB-33686 As a user I should be signed out after browser update
9
+
10
+ ### Fixed
11
+ - PB-33727 Fix session extension, service worker awaken and user instance storage not set
12
+ - PB-33801 Remove active account cache in memory
13
+
6
14
  ## [4.8.1] - 2024-05-18
7
- ### Fix
15
+ ### Fixed
8
16
  - PB-33595 As a user running an instance serving an invalid certificate I should be able to sync the gpgkeyring
9
17
 
10
18
  ## [4.8.0] - 2024-05-16
@@ -1623,8 +1631,9 @@ self registration settings option in the left-side bar
1623
1631
  - AP: User with plugin installed
1624
1632
  - LU: Logged in user
1625
1633
 
1626
- [Unreleased]: https://github.com/passbolt/passbolt_browser_extension/compare/v4.8.1...HEAD
1627
- [4.8.0]: https://github.com/passbolt/passbolt_browser_extension/compare/v4.8.0...4.8.1
1634
+ [Unreleased]: https://github.com/passbolt/passbolt_browser_extension/compare/v4.8.2...HEAD
1635
+ [4.8.2]: https://github.com/passbolt/passbolt_browser_extension/compare/v4.8.1...4.8.2
1636
+ [4.8.1]: https://github.com/passbolt/passbolt_browser_extension/compare/v4.8.0...4.8.1
1628
1637
  [4.8.0]: https://github.com/passbolt/passbolt_browser_extension/compare/v4.7.8...4.8.0
1629
1638
  [4.7.8]: https://github.com/passbolt/passbolt_browser_extension/compare/v4.7.7...v4.7.8
1630
1639
  [4.7.7]: https://github.com/passbolt/passbolt_browser_extension/compare/v4.7.6...v4.7.7
package/RELEASE_NOTES.md CHANGED
@@ -1,11 +1,13 @@
1
- Song: https://www.youtube.com/watch?v=hbe3CQamF8k
1
+ Song: https://www.youtube.com/watch?v=OypXGyN6OZw
2
2
 
3
- Passbolt v4.8.1 is a maintenance update that addresses issues related to servers serving invalid SSL certificates, which affected the accessibility of the API with certain user journeys.
3
+ Passbolt v4.8.2 is a maintenance update that addresses issues related to MV3.
4
4
 
5
5
  We hope these updates enhance your experience with Passbolt. Your feedback is always valuable to us.
6
6
 
7
- ## [4.8.1] - 2024-05-18
8
- ### Fix
9
- - PB-33595 As a user running an instance serving an invalid certificate I should be able to sync the gpgkeyring
10
- - PB-33596 As a user running an instance serving an invalid certificate I cannot sync my account settings
11
- - PB-33597 As a user running an instance serving an invalid certificate I cannot install passbolt extension using an API < v3
7
+ ## [4.8.2] - 2024-06-13
8
+ ### Improved
9
+ - PB-33686 As a user I should be signed out after browser update
10
+
11
+ ### Fixed
12
+ - PB-33727 Fix session extension, service worker awaken and user instance storage not set
13
+ - PB-33801 Remove active account cache in memory
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passbolt-browser-extension",
3
- "version": "4.8.1",
3
+ "version": "4.8.2",
4
4
  "license": "AGPL-3.0",
5
5
  "copyright": "Copyright 2022 Passbolt SA",
6
6
  "description": "Passbolt web extension for the open source password manager for teams",
@@ -23,6 +23,8 @@ import Log from "../../model/log";
23
23
  import {BrowserExtensionIconService} from "../../service/ui/browserExtensionIcon.service";
24
24
  import storage from "../../sdk/storage";
25
25
  import {Config} from "../../model/config";
26
+ import AuthModel from "../../model/auth/authModel";
27
+ import AppBootstrapPagemod from "../../pagemod/appBootstrapPagemod";
26
28
 
27
29
  class OnExtensionInstalledController {
28
30
  /**
@@ -45,6 +47,11 @@ class OnExtensionInstalledController {
45
47
  case browser.runtime.OnInstalledReason.UPDATE:
46
48
  await OnExtensionInstalledController.onUpdate();
47
49
  break;
50
+ case browser.runtime.OnInstalledReason.CHROME_UPDATE:
51
+ case browser.runtime.OnInstalledReason.BROWSER_UPDATE:
52
+ // Force logout for users to not ask passphrase after a browser update which clear the session storage
53
+ await OnExtensionInstalledController.onBrowserUpdate();
54
+ break;
48
55
  default:
49
56
  console.debug(`The install reason ${details.reason} is not supported`);
50
57
  break;
@@ -67,6 +74,45 @@ class OnExtensionInstalledController {
67
74
  await OnExtensionInstalledController.updateToolbarIcon();
68
75
  }
69
76
 
77
+ /**
78
+ * On update of the browser, logout the user. It helps mitigate issue where users update their browser, are still
79
+ * signed-in but session memory used to store user passphrase or other information is flushed. These behavior
80
+ * deteriorates the user experience, therefore it has been decided to sign the user out.
81
+ */
82
+ static async onBrowserUpdate() {
83
+ const user = User.getInstance();
84
+ // Check if user is valid
85
+ if (!user.isValid()) {
86
+ return;
87
+ }
88
+ let authStatus;
89
+ try {
90
+ const checkAuthStatusService = new CheckAuthStatusService();
91
+ // use the cached data as the worker could wake up every 30 secondes.
92
+ authStatus = await checkAuthStatusService.checkAuthStatus(false);
93
+ } catch (error) {
94
+ // Service is unavailable, do nothing...
95
+ Log.write({level: 'debug', message: 'Could not check if the user is authenticated, the service is unavailable.'});
96
+ return;
97
+ }
98
+ // Do nothing if user is not authenticated
99
+ if (!authStatus.isAuthenticated) {
100
+ return;
101
+ }
102
+ // Logout authenticated user to prevent to ask passphrase for SSO users
103
+ const apiClientOptions = await user.getApiClientOptions();
104
+ const authModel = new AuthModel(apiClientOptions);
105
+ await authModel.logout();
106
+ /*
107
+ * Reload only tabs that match passbolt app url. Reload is necessary as the application loaded in the tab
108
+ * could be unresponsive due to the forced triggered sign-out.
109
+ * - When the tab is started the API didn't redirect the user as the user is still signed-in.
110
+ * - This script sign-out the user
111
+ * - The pagemod of the app starts and throw an error as the user has been signed-out
112
+ */
113
+ await browser.tabs.query({}).then(reloadTabsMatchPassboltAppUrl);
114
+ }
115
+
70
116
  /**
71
117
  * Updates the Passbolt icon in the toolbar according to the sign-in status of the current user.
72
118
  * @returns {Promise<void>}
@@ -81,11 +127,11 @@ class OnExtensionInstalledController {
81
127
  let authStatus;
82
128
  try {
83
129
  const checkAuthStatusService = new CheckAuthStatusService();
84
- // user the cached data as the worker could wake up every 30 secondes.
130
+ // use the cached data as the worker could wake up every 30 secondes.
85
131
  authStatus = await checkAuthStatusService.checkAuthStatus(false);
86
132
  } catch (error) {
87
133
  // Service is unavailable, do nothing...
88
- Log.write({level: 'debug', message: 'The Service is unavailable to check if the user is authenticated'});
134
+ Log.write({level: 'debug', message: 'Could not check if the user is authenticated, the service is unavailable.'});
89
135
  return;
90
136
  }
91
137
 
@@ -127,13 +173,25 @@ const closeTabWebStore = tabs => {
127
173
  };
128
174
 
129
175
 
176
+ /**
177
+ * Reload the tabs that match passsbolt app url
178
+ * @param tabs
179
+ */
180
+ const reloadTabsMatchPassboltAppUrl = async tabs => {
181
+ for (const tab of tabs) {
182
+ if (await AppBootstrapPagemod.assertUrlAttachConstraint(tab)) {
183
+ browser.tabs.reload(tab.id);
184
+ }
185
+ }
186
+ };
187
+
130
188
  /**
131
189
  * Reload the tabs that match pagemod url
132
190
  * @param tabs
133
191
  */
134
- const reloadTabsMatchPagemodUrl = tabs => {
135
- tabs.map(tab => {
136
- if (PagemodManager.hasPagemodMatchUrlToReload(tab.url)) {
192
+ const reloadTabsMatchPagemodUrl = async tabs => {
193
+ for (const tab of tabs) {
194
+ if (await PagemodManager.hasPagemodMatchUrlToReload(tab.url)) {
137
195
  browser.tabs.reload(tab.id);
138
196
  } else {
139
197
  // For other tabs detect and inject the new content script
@@ -144,7 +202,7 @@ const reloadTabsMatchPagemodUrl = tabs => {
144
202
  };
145
203
  WebNavigationService.exec(frameDetails);
146
204
  }
147
- });
205
+ }
148
206
  };
149
207
 
150
208
  export default OnExtensionInstalledController;
@@ -13,9 +13,12 @@
13
13
  */
14
14
 
15
15
  import OnExtensionInstalledController from "./onExtensionInstalledController";
16
- import User from "../../model/user";
17
16
  import UserSettings from "../../model/userSettings/userSettings";
18
17
  import WebNavigationService from "../../service/webNavigation/webNavigationService";
18
+ import AuthModel from "../../model/auth/authModel";
19
+ import CheckAuthStatusService from "../../service/auth/checkAuthStatusService";
20
+ import GetActiveAccountService from "../../service/account/getActiveAccountService";
21
+ import User from "../../model/user";
19
22
 
20
23
  // Reset the modules before each test.
21
24
  beforeEach(() => {
@@ -73,7 +76,7 @@ describe("OnExtensionInstalledController", () => {
73
76
  jest.spyOn(OnExtensionInstalledController, "onUpdate");
74
77
  jest.spyOn(WebNavigationService, "exec");
75
78
  jest.spyOn(browser.tabs, "query").mockImplementationOnce(() => Promise.resolve(tabs));
76
- jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => true);
79
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => {});
77
80
  jest.spyOn(UserSettings.prototype, "getDomain").mockImplementation(() => "https://passbolt.dev");
78
81
  // process
79
82
  await OnExtensionInstalledController.exec(details);
@@ -89,8 +92,57 @@ describe("OnExtensionInstalledController", () => {
89
92
  expect(WebNavigationService.exec).toHaveBeenCalledTimes(2);
90
93
  });
91
94
 
95
+ it("Should exec browser update if the reason is chrome update", async() => {
96
+ expect.assertions(3);
97
+ // data mocked
98
+ const details = {
99
+ reason: browser.runtime.OnInstalledReason.CHROME_UPDATE
100
+ };
101
+ // mock function
102
+ jest.spyOn(OnExtensionInstalledController, "onBrowserUpdate");
103
+ jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => false);
104
+ jest.spyOn(AuthModel.prototype, "logout");
105
+ // process
106
+ await OnExtensionInstalledController.exec(details);
107
+ // expectation
108
+ expect(OnExtensionInstalledController.onBrowserUpdate).toHaveBeenCalled();
109
+ expect(User.getInstance().isValid).toHaveBeenCalledTimes(1);
110
+ expect(AuthModel.prototype.logout).toHaveBeenCalledTimes(0);
111
+ });
112
+
113
+ it("Should exec browser update if the reason is browser update", async() => {
114
+ expect.assertions(4);
115
+ // data mocked
116
+ const details = {
117
+ reason: browser.runtime.OnInstalledReason.BROWSER_UPDATE
118
+ };
119
+ const tabs = [
120
+ {id: 1, url: "https://passbolt.dev/app/passwords"},
121
+ {id: 2, url: "https://passbolt.dev/setup/recover/start/571bec7e-6cce-451d-b53a-f8c93e147228/5ea0fc9c-b180-4873-8e00-9457862e43e0"},
122
+ {id: 3, url: "https://passbolt.dev/auth/login"},
123
+ {id: 4, url: "https://passbolt.dev"},
124
+ {id: 5, url: "https://passbolt.com"},
125
+ {id: 6, url: "https://localhost"}
126
+ ];
127
+ // mock function
128
+ jest.spyOn(OnExtensionInstalledController, "onBrowserUpdate");
129
+ jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => true);
130
+ jest.spyOn(UserSettings.prototype, "getDomain").mockImplementation(() => "https://passbolt.dev");
131
+ jest.spyOn(AuthModel.prototype, "logout").mockImplementation(() => {});
132
+ jest.spyOn(browser.tabs, "query").mockImplementation(() => Promise.resolve(tabs));
133
+ jest.spyOn(browser.tabs, "reload");
134
+ jest.spyOn(CheckAuthStatusService.prototype, "checkAuthStatus").mockImplementation(() => ({isAuthenticated: true}));
135
+ // process
136
+ await OnExtensionInstalledController.exec(details);
137
+ // expectation
138
+ expect(OnExtensionInstalledController.onBrowserUpdate).toHaveBeenCalled();
139
+ expect(AuthModel.prototype.logout).toHaveBeenCalledTimes(1);
140
+ expect(browser.tabs.query).toHaveBeenCalledTimes(1);
141
+ expect(browser.tabs.reload).toHaveBeenCalledWith(tabs[0].id);
142
+ });
143
+
92
144
  it("Should not exec update neither install if the reason is unknown", async() => {
93
- expect.assertions(2);
145
+ expect.assertions(3);
94
146
  // data mocked
95
147
  const details = {
96
148
  reason: "unknown"
@@ -98,12 +150,14 @@ describe("OnExtensionInstalledController", () => {
98
150
  // mock function
99
151
  jest.spyOn(OnExtensionInstalledController, "onUpdate");
100
152
  jest.spyOn(OnExtensionInstalledController, "onInstall");
153
+ jest.spyOn(OnExtensionInstalledController, "onBrowserUpdate");
101
154
 
102
155
  // process
103
156
  await OnExtensionInstalledController.exec(details);
104
157
  // expectation
105
158
  expect(OnExtensionInstalledController.onUpdate).not.toHaveBeenCalled();
106
159
  expect(OnExtensionInstalledController.onInstall).not.toHaveBeenCalled();
160
+ expect(OnExtensionInstalledController.onBrowserUpdate).not.toHaveBeenCalled();
107
161
  });
108
162
  });
109
163
  });
@@ -29,7 +29,7 @@ describe("DeletePasswordExpirySettingsController", () => {
29
29
  jest.spyOn(browser.cookies, "get").mockImplementationOnce(() => ({value: "csrf-token"}));
30
30
 
31
31
  account = new AccountEntity(defaultAccountDto());
32
- apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
32
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
33
33
  });
34
34
 
35
35
  it("Should delete the entity from the API given an ID", () => {
@@ -39,7 +39,7 @@ describe("GetOrFindPasswordExpirySettingsController", () => {
39
39
  jest.spyOn(browser.cookies, "get").mockImplementationOnce(() => ({value: "csrf-token"}));
40
40
 
41
41
  account = new AccountEntity(defaultAccountDto());
42
- apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
42
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
43
43
  });
44
44
 
45
45
  it("Should return the value from the API", async() => {
@@ -42,7 +42,7 @@ describe("SavePasswordExpirySettingsController", () => {
42
42
  fetch.resetMocks();
43
43
  jest.spyOn(browser.cookies, "get").mockImplementationOnce(() => ({value: "csrf-token"}));
44
44
  account = new AccountEntity(defaultAccountDto());
45
- apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
45
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
46
46
  });
47
47
 
48
48
  it("Should save the given dto on the API using PasswordExpirySettingsEntity", async() => {
@@ -30,7 +30,7 @@ describe("FindPasswordPoliciesController::exec", () => {
30
30
  jest.spyOn(browser.cookies, "get").mockImplementationOnce(() => ({value: "csrf-token"}));
31
31
 
32
32
  account = new AccountEntity(defaultAccountDto());
33
- apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
33
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
34
34
  });
35
35
 
36
36
  it("Should return the registered password policies", async() => {
@@ -32,7 +32,7 @@ describe("SavePasswordPoliciesController::exec", () => {
32
32
  jest.spyOn(browser.cookies, "get").mockImplementationOnce(() => ({value: "csrf-token"}));
33
33
 
34
34
  account = new AccountEntity(defaultAccountDto());
35
- apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
35
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
36
36
  });
37
37
 
38
38
  it("Should save the given data", async() => {
@@ -29,7 +29,7 @@ describe("FindUserPassphrasePoliciesController", () => {
29
29
  jest.spyOn(browser.cookies, "get").mockImplementationOnce(() => ({value: "csrf-token"}));
30
30
 
31
31
  const account = new AccountEntity(defaultAccountDto());
32
- apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
32
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
33
33
  });
34
34
 
35
35
  it("Should return the value from the API", async() => {
@@ -31,7 +31,7 @@ describe("SaveUserPassphrasePoliciesController", () => {
31
31
  jest.spyOn(browser.cookies, "get").mockImplementationOnce(() => ({value: "csrf-token"}));
32
32
 
33
33
  const account = new AccountEntity(defaultAccountDto());
34
- apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
34
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
35
35
  });
36
36
 
37
37
  it("Should save the given dto on the API", async() => {
@@ -35,7 +35,7 @@ describe("PasswordExpiry model", () => {
35
35
  jest.spyOn(browser.cookies, "get").mockImplementationOnce(() => ({value: "csrf-token"}));
36
36
 
37
37
  const account = new AccountEntity(defaultAccountDto());
38
- apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
38
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
39
39
  model = new PasswordExpirySettingsModel(account, apiClientOptions);
40
40
  jest.spyOn(model.organisationSettingsModel, "getOrFind").mockImplementation(() => (Promise.resolve({
41
41
  isPluginEnabled: () => false
@@ -31,7 +31,7 @@ describe("PasswordPoliciesModel", () => {
31
31
  jest.spyOn(browser.cookies, "get").mockImplementationOnce(() => ({value: "csrf-token"}));
32
32
 
33
33
  account = new AccountEntity(defaultAccountDto());
34
- apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
34
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
35
35
  });
36
36
 
37
37
  describe("::get", () => {
@@ -11,6 +11,7 @@ import Validator from "validator";
11
11
  import {ValidatorRule} from "../utils/validatorRules";
12
12
 
13
13
  /**
14
+ * @deprecated
14
15
  * The class that deals with users.
15
16
  */
16
17
  const User = (function() {
@@ -32,7 +32,7 @@ describe("UserPassphrasePolicies model", () => {
32
32
  jest.spyOn(browser.cookies, "get").mockImplementationOnce(() => ({value: "csrf-token"}));
33
33
 
34
34
  const account = new AccountEntity(defaultAccountDto());
35
- apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
35
+ apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
36
36
  });
37
37
 
38
38
  describe('::findOrDefault', () => {
@@ -43,7 +43,7 @@ class AccountRecovery extends Pagemod {
43
43
  try {
44
44
  const tab = port._port.sender.tab;
45
45
  const account = await GetRequestLocalAccountService.getAccountMatchingContinueUrl(tab.url);
46
- const apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
46
+ const apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
47
47
  for (const event of this.events) {
48
48
  event.listen({port, tab}, apiClientOptions, account);
49
49
  }
@@ -12,11 +12,11 @@
12
12
  * @since 4.0.0
13
13
  */
14
14
  import Pagemod from "./pagemod";
15
- import User from "../model/user";
16
15
  import {AppBootstrapEvents} from "../event/appBootstrapEvents";
17
16
  import ParseAppUrlService from "../service/app/parseAppUrlService";
18
17
  import {PortEvents} from "../event/portEvents";
19
18
  import CheckAuthStatusService from "../service/auth/checkAuthStatusService";
19
+ import GetActiveAccountService from "../service/account/getActiveAccountService";
20
20
 
21
21
  class AppBootstrap extends Pagemod {
22
22
  /**
@@ -63,7 +63,7 @@ class AppBootstrap extends Pagemod {
63
63
  */
64
64
  async canBeAttachedTo(frameDetails) {
65
65
  return this.assertTopFrameAttachConstraint(frameDetails)
66
- && this.assertUrlAttachConstraint(frameDetails) &&
66
+ && await this.assertUrlAttachConstraint(frameDetails) &&
67
67
  await this.assertUserAuthenticated();
68
68
  }
69
69
 
@@ -79,14 +79,16 @@ class AppBootstrap extends Pagemod {
79
79
  /**
80
80
  * Assert that the attached frame is a top frame.
81
81
  * @param {Object} frameDetails
82
- * @returns {boolean}
82
+ * @returns {Promise<boolean>}
83
83
  */
84
- assertUrlAttachConstraint(frameDetails) {
85
- const user = User.getInstance();
86
- if (user.isValid()) {
84
+ async assertUrlAttachConstraint(frameDetails) {
85
+ try {
86
+ await GetActiveAccountService.get();
87
87
  return ParseAppUrlService.test(frameDetails.url);
88
+ } catch (error) {
89
+ console.log(error);
90
+ return false;
88
91
  }
89
- return false;
90
92
  }
91
93
 
92
94
  /**
@@ -11,7 +11,6 @@
11
11
  * @link https://www.passbolt.com Passbolt(tm)
12
12
  * @since 3.8.0
13
13
  */
14
- import User from "../model/user";
15
14
  import UserSettings from "../model/userSettings/userSettings";
16
15
  import AppBootstrap from "./appBootstrapPagemod";
17
16
  import WorkersSessionStorage from "../service/sessionStorage/workersSessionStorage";
@@ -23,6 +22,7 @@ import each from "jest-each";
23
22
  import {PortEvents} from "../event/portEvents";
24
23
  import CheckAuthStatusService from "../service/auth/checkAuthStatusService";
25
24
  import {userLoggedInAuthStatus, userLoggedOutAuthStatus} from "../controller/auth/authCheckStatus.test.data";
25
+ import GetActiveAccountService from "../service/account/getActiveAccountService";
26
26
 
27
27
  const spyAddWorker = jest.spyOn(WorkersSessionStorage, "addWorker");
28
28
  jest.spyOn(ScriptExecution.prototype, "injectPortname").mockImplementation(jest.fn());
@@ -60,7 +60,7 @@ describe("AppBootstrap", () => {
60
60
  it("Should be able to attach app bootstrap pagemod to browser frame", async() => {
61
61
  expect.assertions(1);
62
62
  // mock functions
63
- jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => true);
63
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => {});
64
64
  jest.spyOn(CheckAuthStatusService.prototype, "checkAuthStatus").mockImplementation(async() => userLoggedInAuthStatus());
65
65
  jest.spyOn(UserSettings.prototype, "getDomain").mockImplementation(() => "https://passbolt.dev");
66
66
  const result = await AppBootstrap.canBeAttachedTo({frameId: Pagemod.TOP_FRAME_ID, url: "https://passbolt.dev/app"});
@@ -81,7 +81,7 @@ describe("AppBootstrap", () => {
81
81
  it("Should not be able to attach a pagemod if the user is not valid", async() => {
82
82
  expect.assertions(1);
83
83
  // mock functions
84
- jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => false);
84
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => { throw new Error(); });
85
85
  // process
86
86
  const result = await AppBootstrap.canBeAttachedTo({frameId: 0});
87
87
  // expectations
@@ -91,7 +91,7 @@ describe("AppBootstrap", () => {
91
91
  it("Should not be able to attach a pagemod if the user is not authenticated", async() => {
92
92
  expect.assertions(1);
93
93
  // mock functions
94
- jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => true);
94
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => {});
95
95
  jest.spyOn(CheckAuthStatusService.prototype, "checkAuthStatus").mockImplementation(async() => userLoggedOutAuthStatus());
96
96
  jest.spyOn(UserSettings.prototype, "getDomain").mockImplementation(() => "https://passbolt");
97
97
  // process
@@ -12,7 +12,6 @@
12
12
  * @since 4.0.0
13
13
  */
14
14
  import Pagemod from "./pagemod";
15
- import GetLegacyAccountService from "../service/account/getLegacyAccountService";
16
15
  import AppInitController from "../controller/app/appInitController";
17
16
  import {AppEvents} from "../event/appEvents";
18
17
  import {ConfigEvents} from "../event/configEvents";
@@ -44,6 +43,7 @@ import {ClipboardEvents} from "../event/clipboardEvents";
44
43
  import BuildApiClientOptionsService from "../service/account/buildApiClientOptionsService";
45
44
  import {RememberMeEvents} from "../event/rememberMeEvents";
46
45
  import CheckAuthStatusService from "../service/auth/checkAuthStatusService";
46
+ import GetActiveAccountService from "../service/account/getActiveAccountService";
47
47
 
48
48
  class App extends Pagemod {
49
49
  /**
@@ -107,8 +107,8 @@ class App extends Pagemod {
107
107
  const appInitController = new AppInitController();
108
108
  await appInitController.main();
109
109
 
110
- const account = await GetLegacyAccountService.get({role: true});
111
- const apiClientOptions = await BuildApiClientOptionsService.buildFromAccount(account);
110
+ const account = await GetActiveAccountService.get({role: true});
111
+ const apiClientOptions = BuildApiClientOptionsService.buildFromAccount(account);
112
112
  for (const event of this.events) {
113
113
  event.listen({port, tab}, apiClientOptions, account);
114
114
  }
@@ -13,7 +13,6 @@
13
13
  */
14
14
  import {ConfigEvents} from "../event/configEvents";
15
15
  import App from "./appPagemod";
16
- import GetLegacyAccountService from "../service/account/getLegacyAccountService";
17
16
  import {UserEvents} from "../event/userEvents";
18
17
  import {KeyringEvents} from "../event/keyringEvents";
19
18
  import {AuthEvents} from "../event/authEvents";
@@ -46,6 +45,7 @@ import {enableFetchMocks} from "jest-fetch-mock";
46
45
  import {RememberMeEvents} from "../event/rememberMeEvents";
47
46
  import CheckAuthStatusService from "../service/auth/checkAuthStatusService";
48
47
  import {userLoggedInAuthStatus} from "../controller/auth/authCheckStatus.test.data";
48
+ import GetActiveAccountService from "../service/account/getActiveAccountService";
49
49
 
50
50
  jest.spyOn(ConfigEvents, "listen").mockImplementation(jest.fn());
51
51
  jest.spyOn(AppEvents, "listen").mockImplementation(jest.fn());
@@ -96,19 +96,17 @@ describe("App", () => {
96
96
  }
97
97
  }
98
98
  };
99
- jest.spyOn(GetLegacyAccountService, 'get').mockImplementation(() => mockedAccount);
100
-
101
99
  // mock functions
102
100
  jest.spyOn(browser.cookies, "get").mockImplementation(() => ({value: "csrf-token"}));
103
101
  jest.spyOn(CheckAuthStatusService.prototype, "checkAuthStatus").mockImplementation(async() => userLoggedInAuthStatus());
104
102
  const mockedAccount = {user_id: uuid(), domain: "https://test-domain.passbolt.com"};
105
- const mockApiClient = await BuildApiClientOptionsService.buildFromAccount(mockedAccount);
106
- jest.spyOn(GetLegacyAccountService, 'get').mockImplementation(() => mockedAccount);
103
+ const mockApiClient = BuildApiClientOptionsService.buildFromAccount(mockedAccount);
104
+ jest.spyOn(GetActiveAccountService, 'get').mockImplementation(() => mockedAccount);
107
105
  // process
108
106
  await App.attachEvents(port);
109
107
  // expectations
110
108
  const expectedPortAndTab = {port: port, tab: port._port.sender.tab};
111
- expect(GetLegacyAccountService.get).toHaveBeenCalledWith({role: true});
109
+ expect(GetActiveAccountService.get).toHaveBeenCalledWith({role: true});
112
110
  expect(ConfigEvents.listen).toHaveBeenCalledWith(expectedPortAndTab, mockApiClient, mockedAccount);
113
111
  expect(AppEvents.listen).toHaveBeenCalledWith(expectedPortAndTab, mockApiClient, mockedAccount);
114
112
  expect(AuthEvents.listen).toHaveBeenCalledWith(expectedPortAndTab, mockApiClient, mockedAccount);
@@ -12,9 +12,9 @@
12
12
  * @since 4.0.0
13
13
  */
14
14
  import Pagemod from "./pagemod";
15
- import User from "../model/user";
16
15
  import {PortEvents} from "../event/portEvents";
17
16
  import ParseAuthUrlService from "../service/auth/parseAuthUrlService";
17
+ import GetActiveAccountService from "../service/account/getActiveAccountService";
18
18
 
19
19
  class AuthBootstrap extends Pagemod {
20
20
  /**
@@ -61,7 +61,7 @@ class AuthBootstrap extends Pagemod {
61
61
  */
62
62
  async canBeAttachedTo(frameDetails) {
63
63
  return this.assertTopFrameAttachConstraint(frameDetails)
64
- && this.assertUrlAttachConstraint(frameDetails);
64
+ && await this.assertUrlAttachConstraint(frameDetails);
65
65
  }
66
66
 
67
67
  /**
@@ -76,14 +76,16 @@ class AuthBootstrap extends Pagemod {
76
76
  /**
77
77
  * Assert that the attached frame is a top frame.
78
78
  * @param {Object} frameDetails
79
- * @returns {boolean}
79
+ * @returns {Promise<boolean>}
80
80
  */
81
- assertUrlAttachConstraint(frameDetails) {
82
- const user = User.getInstance();
83
- if (user.isValid()) {
81
+ async assertUrlAttachConstraint(frameDetails) {
82
+ try {
83
+ await GetActiveAccountService.get();
84
84
  return ParseAuthUrlService.test(frameDetails.url);
85
+ } catch (error) {
86
+ console.log(error);
87
+ return false;
85
88
  }
86
- return false;
87
89
  }
88
90
  }
89
91
 
@@ -11,7 +11,6 @@
11
11
  * @link https://www.passbolt.com Passbolt(tm)
12
12
  * @since 3.8.0
13
13
  */
14
- import User from "../model/user";
15
14
  import UserSettings from "../model/userSettings/userSettings";
16
15
  import AuthBootstrap from "./authBootstrapPagemod";
17
16
  import WorkersSessionStorage from "../service/sessionStorage/workersSessionStorage";
@@ -20,6 +19,7 @@ import ScriptExecution from "../sdk/scriptExecution";
20
19
  import {PortEvents} from "../event/portEvents";
21
20
  import each from "jest-each";
22
21
  import Pagemod from "./pagemod";
22
+ import GetActiveAccountService from "../service/account/getActiveAccountService";
23
23
 
24
24
  const spyAddWorker = jest.spyOn(WorkersSessionStorage, "addWorker");
25
25
  jest.spyOn(ScriptExecution.prototype, "injectPortname").mockImplementation(jest.fn());
@@ -56,7 +56,7 @@ describe("AuthBootstrap", () => {
56
56
  it("Should be able to attach auth bootstrap pagemod to browser frame", async() => {
57
57
  expect.assertions(1);
58
58
  // mock functions
59
- jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => true);
59
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => {});
60
60
  jest.spyOn(UserSettings.prototype, "getDomain").mockImplementation(() => "https://passbolt.dev");
61
61
  const result = await AuthBootstrap.canBeAttachedTo({frameId: Pagemod.TOP_FRAME_ID, url: "https://passbolt.dev/auth/login"});
62
62
  expect(result).toBeTruthy();
@@ -69,7 +69,7 @@ describe("AuthBootstrap", () => {
69
69
  it(`Should be able to attach a pagemod to browser frame: ${_props.scenario}`, async() => {
70
70
  expect.assertions(1);
71
71
  // mock functions
72
- jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => true);
72
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => {});
73
73
  jest.spyOn(UserSettings.prototype, "getDomain").mockImplementation(() => "https://passbolt.dev");
74
74
  const result = await AuthBootstrap.canBeAttachedTo({frameId: _props.frameId, url: _props.url});
75
75
  expect(result).toBeFalsy();
@@ -79,7 +79,7 @@ describe("AuthBootstrap", () => {
79
79
  it("Should have the constraint not valid if the user is not valid", async() => {
80
80
  expect.assertions(1);
81
81
  // mock functions
82
- jest.spyOn(User.getInstance(), "isValid").mockImplementation(() => false);
82
+ jest.spyOn(GetActiveAccountService, "get").mockImplementation(() => { throw new Error(); });
83
83
  // process
84
84
  const result = await AuthBootstrap.canBeAttachedTo({frameId: 0});
85
85
  // expectations