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.
- package/.pre-commit-config.yaml +6 -2
- package/CHANGELOG.md +106 -1
- package/README.md +2 -2
- package/RELEASE_NOTES.md +3 -94
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager/ViewController.swift +5 -5
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager.xcodeproj/project.pbxproj +10 -10
- package/eslint.config.mjs +3 -35
- package/jest.config.json +1 -2
- package/package.json +45 -54
- package/src/all/_locales/locales.test.js +2 -0
- package/src/all/background_page/controller/InformMenuController/InformMenuController.test.js +45 -1
- package/src/all/background_page/controller/accountRecovery/accountRecoverySaveUserSettingController.js +1 -2
- package/src/all/background_page/controller/accountRecovery/accountRecoverySaveUserSettingController.test.js +10 -8
- package/src/all/background_page/controller/accountRecovery/accountRecoveryValidatePublicKeyController.test.js +1 -1
- package/src/all/background_page/controller/auth/authLocalLogoutController.js +3 -14
- package/src/all/background_page/controller/auth/authLocalLogoutController.test.js +3 -3
- package/src/all/background_page/controller/auth/authLoginController.js +2 -2
- package/src/all/background_page/controller/auth/authOfflineLogoutController.js +4 -12
- package/src/all/background_page/controller/auth/authOfflineLogoutController.test.js +3 -3
- package/src/all/background_page/controller/auth/{findAndUpdateActiveSessionLocalStorageController.js → findAndUpdateActiveSessionSessionStorageController.js} +6 -6
- package/src/all/background_page/controller/auth/{findAndUpdateActiveSessionLocalStorageController.test.js → findAndUpdateActiveSessionSessionStorageController.test.js} +30 -30
- package/src/all/background_page/controller/auth/getOrFindActiveSessionController.test.js +22 -20
- package/src/all/background_page/controller/auth/isMfaRequiredController.js +5 -4
- package/src/all/background_page/controller/auth/isMfaRequiredController.test.js +3 -3
- package/src/all/background_page/controller/crypto/getUserKeyInfoController.test.js +1 -1
- package/src/all/background_page/controller/crypto/getUserPrivateKeyController.test.js +1 -1
- package/src/all/background_page/controller/extension/onExtensionInstalledController.js +61 -30
- package/src/all/background_page/controller/extension/onExtensionInstalledController.test.js +131 -19
- package/src/all/background_page/controller/informCallToActionController/informCallToActionController.test.js +46 -0
- package/src/all/background_page/controller/resource/setResourcesExpiryDateController.test.js +1 -1
- package/src/all/background_page/controller/sessionTimestamps/getSessionTimestampsController.js +54 -0
- package/src/all/background_page/controller/sessionTimestamps/getSessionTimestampsController.test.js +91 -0
- package/src/all/background_page/controller/share/shareResourcesController.test.js +2 -2
- package/src/all/background_page/controller/sso/getQualifiedSsoLoginErrorController.test.js +1 -1
- package/src/all/background_page/controller/sso/hasSsoLoginErrorController.test.js +1 -1
- package/src/all/background_page/controller/subscription/createSubscriptionKeyController.js +3 -3
- package/src/all/background_page/controller/subscription/createSubscriptionKeyController.test.js +4 -4
- package/src/all/background_page/controller/subscription/deleteSubscriptionKeyController.js +3 -3
- package/src/all/background_page/controller/subscription/deleteSubscriptionKeyController.test.js +4 -4
- package/src/all/background_page/controller/theme/findThemesController.js +52 -0
- package/src/all/background_page/controller/theme/findThemesController.test.js +68 -0
- package/src/all/background_page/controller/theme/updateThemeController.js +55 -0
- package/src/all/background_page/controller/theme/updateThemeController.test.js +76 -0
- package/src/all/background_page/controller/user/getOrFindLoggedInUserController.test.js +2 -2
- package/src/all/background_page/event/appEvents.js +1 -26
- package/src/all/background_page/event/authEvents.js +2 -2
- package/src/all/background_page/event/configEvents.js +0 -12
- package/src/all/background_page/event/informMenuEvents.js +2 -2
- package/src/all/background_page/event/quickAccessEvents.js +12 -0
- package/src/all/background_page/event/themeEvents.js +9 -21
- package/src/all/background_page/model/auth/authModel.js +3 -3
- package/src/all/background_page/model/auth/authModel.test.js +2 -2
- package/src/all/background_page/model/entity/export/exportResourcesFileEntity.js +2 -0
- package/src/all/background_page/model/entity/export/exportResourcesFileEntity.test.js +1 -0
- package/src/all/background_page/model/entity/import/importResourcesFileEntity.test.data.js +5 -0
- package/src/all/background_page/model/entity/sso/ssoLoginUrlEntity.js +1 -1
- package/src/all/background_page/model/entity/theme/themeEntity.test.data.js +12 -0
- package/src/all/background_page/model/entity/theme/themesCollection.test.data.js +10 -1
- package/src/all/background_page/model/export/resources/csvRowComposer/abstractRowComposer.js +8 -0
- package/src/all/background_page/model/export/resources/csvRowComposer/csvNetwrixRowComposer.js +67 -0
- package/src/all/background_page/model/export/resources/csvRowComposer/csvNetwrixRowComposer.test.js +37 -0
- package/src/all/background_page/model/export/resources/resourcesCsvExporter.js +5 -2
- package/src/all/background_page/model/export/resources/resourcesCsvExporter.test.js +3 -1
- package/src/all/background_page/model/import/resources/csvRowParser/csvNetwrixRowParser.js +98 -0
- package/src/all/background_page/model/import/resources/csvRowParser/csvNetwrixRowParser.test.js +145 -0
- package/src/all/background_page/model/import/resources/resourcesCsvImportParser.js +2 -0
- package/src/all/background_page/model/import/resources/resourcesCsvImportParser.test.js +19 -1
- package/src/all/background_page/model/keyring.test.js +1 -1
- package/src/all/background_page/model/multiFactorAuthentication/multiFactorAuthenticationModel.test.js +1 -1
- package/src/all/background_page/model/user/userModel.test.js +1 -1
- package/src/all/background_page/model/user.js +2 -2
- package/src/all/background_page/model/userSettings/userSettings.js +1 -1
- package/src/all/background_page/pagemod/appBootstrapPagemod.js +6 -5
- package/src/all/background_page/pagemod/appBootstrapPagemod.test.js +7 -12
- package/src/all/background_page/pagemod/authBootstrapPagemod.js +2 -2
- package/src/all/background_page/pagemod/authBootstrapPagemod.test.js +6 -7
- package/src/all/background_page/pagemod/pagemodManager.test.js +14 -20
- package/src/all/background_page/pagemod/webIntegrationPagemod.js +2 -2
- package/src/all/background_page/pagemod/webIntegrationPagemod.test.js +9 -9
- package/src/all/background_page/service/accountRecovery/decryptPrivateKeyPasswordDataService.js +1 -1
- package/src/all/background_page/service/accountRecovery/decryptResponseDataService.js +1 -1
- package/src/all/background_page/service/accountRecovery/parseAccountRecoveryUrlService.js +1 -1
- package/src/all/background_page/service/accountRecovery/validateOrganizationPublicKeyService.test.js +1 -1
- package/src/all/background_page/service/activeSession/{findAndUpdateActiveSessionLocalStorageService.js → findAndUpdateActiveSessionSessionStorageService.js} +27 -60
- package/src/all/background_page/service/activeSession/findAndUpdateActiveSessionSessionStorageService.test.js +720 -0
- package/src/all/background_page/service/activeSession/getOrFindActiveSessionService.js +8 -8
- package/src/all/background_page/service/activeSession/getOrFindActiveSessionService.test.js +16 -16
- package/src/all/background_page/service/api/accountSettings/accountSettingsService.js +0 -29
- package/src/all/background_page/service/api/accountSettings/accountSettingsService.test.data.js +0 -6
- package/src/all/background_page/service/api/accountSettings/accountSettingsService.test.js +1 -32
- package/src/all/background_page/service/api/actionLog/actionLogApiService.test.js +1 -1
- package/src/all/background_page/service/api/comment/commentApiService.test.js +1 -1
- package/src/all/background_page/service/api/metadata/metadataKeysApiService.test.js +1 -1
- package/src/all/background_page/service/api/sessionKey/sessionKeysBundlesApiService.test.js +1 -1
- package/src/all/background_page/service/api/theme/themesApiService.js +57 -0
- package/src/all/background_page/service/api/theme/themesApiService.test.js +83 -0
- package/src/all/background_page/service/app/parseAppUrlService.js +18 -10
- package/src/all/background_page/service/app/parseAppUrlService.test.js +21 -21
- package/src/all/background_page/service/auth/localLogoutService.js +42 -0
- package/src/all/background_page/service/auth/localLogoutService.test.js +43 -0
- package/src/all/background_page/service/auth/offlineLogoutService.js +47 -0
- package/src/all/background_page/service/auth/offlineLogoutService.test.js +46 -0
- package/src/all/background_page/service/auth/offlineSessionExpiryAlarmService.js +2 -2
- package/src/all/background_page/service/auth/offlineSessionExpiryAlarmService.test.js +3 -3
- package/src/all/background_page/service/auth/parseAuthUrlService.js +11 -6
- package/src/all/background_page/service/auth/parseAuthUrlService.test.js +11 -13
- package/src/all/background_page/service/auth/postLoginOfflineService.js +3 -3
- package/src/all/background_page/service/auth/postLoginOfflineService.test.js +3 -3
- package/src/all/background_page/service/auth/postLoginService.js +3 -3
- package/src/all/background_page/service/auth/postLoginService.test.js +3 -3
- package/src/all/background_page/service/auth/startLoopAuthSessionCheckService.js +8 -4
- package/src/all/background_page/service/auth/startLoopAuthSessionCheckService.test.js +36 -13
- package/src/all/background_page/service/authenticationStatusService.test.js +1 -1
- package/src/all/background_page/service/clipboard/clipboardProviderService.js +0 -7
- package/src/all/background_page/service/clipboard/clipboardProviderService.test.js +0 -10
- package/src/all/background_page/service/clipboard/copyToClipboardService.js +1 -5
- package/src/all/background_page/service/crypto/decryptSsoPassphraseService.js +1 -1
- package/src/all/background_page/service/extension/onStartUpService.js +2 -2
- package/src/all/background_page/service/extension/onStartUpService.test.js +3 -3
- package/src/all/background_page/service/localStorage/localStorageService.js +4 -2
- package/src/all/background_page/service/localStorage/localStorageService.test.js +28 -12
- package/src/all/background_page/service/local_storage/sessionTimestampsLocalStorage.js +40 -0
- package/src/all/background_page/service/local_storage/sessionTimestampsLocalStorage.test.js +63 -0
- package/src/all/background_page/service/metadata/rotateMetadata/rotateMetadataKeyService.test.js +2 -2
- package/src/all/background_page/service/metadata/rotateMetadata/rotateResourcesMetadataKeyService.test.js +2 -2
- package/src/all/background_page/service/migrateMetadata/migrateMetadataResourcesService.test.js +2 -2
- package/src/all/background_page/service/offline/canUseOfflineStorageService.js +16 -1
- package/src/all/background_page/service/offline/canUseOfflineStorageService.test.js +14 -6
- package/src/all/background_page/service/offline/getOrFindOfflineSettingsService.js +4 -1
- package/src/all/background_page/service/offline/getOrFindOfflineSettingsService.test.js +10 -1
- package/src/all/background_page/service/offline/offlineRetentionDataFlushService.js +12 -9
- package/src/all/background_page/service/offline/offlineRetentionDataFlushService.test.js +35 -24
- package/src/all/background_page/service/rbac/getOrFindRbacService.js +4 -1
- package/src/all/background_page/service/recover/parseRecoverUrlService.js +1 -1
- package/src/all/background_page/service/resource/export/exportResourcesService.test.js +3 -0
- package/src/all/background_page/service/resource/getOrFindOfflineResourcesService.js +30 -10
- package/src/all/background_page/service/resource/getOrFindOfflineResourcesService.test.js +108 -9
- package/src/all/background_page/service/resource/getOrFindResourcesService.js +30 -10
- package/src/all/background_page/service/resource/getOrFindResourcesService.test.js +99 -9
- package/src/all/background_page/service/resourceType/getOrFindResourceTypesService.js +4 -1
- package/src/all/background_page/service/resourceType/getOrFindResourceTypesService.test.js +10 -2
- package/src/all/background_page/service/secret/decryptAndParseResourceSecretService.js +1 -1
- package/src/all/background_page/service/sessionTimestamps/getSessionTimestampsService.js +48 -0
- package/src/all/background_page/service/sessionTimestamps/getSessionTimestampsService.test.js +66 -0
- package/src/all/background_page/service/sessionTimestamps/updateSessionTimestampsService.js +102 -0
- package/src/all/background_page/service/sessionTimestamps/updateSessionTimestampsService.test.js +221 -0
- package/src/all/background_page/service/{local_storage/activeSessionLocalStorage.js → session_storage/activeSessionSessionStorage.js} +17 -17
- package/src/all/background_page/service/{local_storage/activeSessionLocalStorage.test.js → session_storage/activeSessionSessionStorage.test.js} +31 -34
- package/src/all/background_page/service/setup/parseSetupUrlService.js +3 -2
- package/src/all/background_page/service/setup/parseSetupUrlService.test.js +195 -24
- package/src/all/background_page/service/share/shareFoldersService.test.js +4 -4
- package/src/all/background_page/service/share/shareResourceService.test.js +4 -4
- package/src/all/background_page/service/theme/findThemesService.js +38 -0
- package/src/all/background_page/service/theme/findThemesService.test.js +63 -0
- package/src/all/background_page/service/theme/updateThemeService.js +39 -0
- package/src/all/background_page/service/theme/updateThemeService.test.js +65 -0
- package/src/all/background_page/service/toolbar/toolbarService.js +20 -10
- package/src/all/background_page/service/toolbar/toolbarService.test.js +82 -6
- package/src/all/background_page/service/user/getOrFindMeService.js +4 -1
- package/src/all/background_page/service/user/getOrFindMeService.test.js +10 -2
- package/src/all/background_page/service/webIntegration/parseWebIntegrationUrlService.js +11 -6
- package/src/all/background_page/service/webIntegration/parseWebIntegrationUrlService.test.js +7 -9
- package/src/all/background_page/utils/format/formDataUtils.test.js +1 -1
- package/src/all/background_page/utils/openpgp/openpgpAssertions.js +1 -1
- package/src/all/webAccessibleResources/js/themes/stylesheet.js +1 -1
- package/src/chrome-mv3/manifest.json +1 -1
- package/src/chrome-mv3/serviceWorker/service/network/requestFetchOffscreenService.js +1 -1
- package/src/chrome-mv3/serviceWorker/service/network/responseFetchOffscreenService.js +7 -4
- package/src/firefox/manifest.json +1 -1
- package/src/safari/manifest.json +1 -1
- package/test/matchers/toBeOpenpgpKeySignedBy.js +13 -14
- package/test/mocks/mockJsDomPolyfill.js +0 -2
- package/webpack/common-blocks.js +13 -13
- package/webpack/expectedBuildArtifacts.js +1 -1
- package/webpack/passboltEnvPlugin.js +1 -1
- package/webpack.common.config.js +2 -0
- package/webpack.config.js +4 -5
- package/webpack.safari-background-page.config.js +38 -31
- package/src/all/background_page/model/theme/themeModel.js +0 -66
- package/src/all/background_page/model/theme/themeModel.test.js +0 -73
- package/src/all/background_page/service/activeSession/findAndUpdateActiveSessionLocalStorageService.test.js +0 -776
- package/src/chrome/manifest.json +0 -51
- package/src/chrome/polyfill/clipboard/edgeBackgroundPageClipboardService.js +0 -31
- package/src/chrome/polyfill/clipboard/edgeBackgroundPageClipboardService.test.js +0 -53
- package/webpack.chromium-mv2.config.js +0 -40
|
@@ -32,7 +32,7 @@ import MetadataKeysSettingsLocalStorage from "../local_storage/metadataKeysSetti
|
|
|
32
32
|
import MetadataTypesSettingsLocalStorage from "../local_storage/metadataTypesSettingsLocalStorage";
|
|
33
33
|
import MetadataKeysSessionStorage from "../session_storage/metadataKeysSessionStorage";
|
|
34
34
|
import SessionKeysBundlesSessionStorageService from "../sessionStorage/sessionKeysBundlesSessionStorageService";
|
|
35
|
-
import
|
|
35
|
+
import ActiveSessionSessionStorage from "../session_storage/activeSessionSessionStorage";
|
|
36
36
|
import UserMeLocalStorage from "../local_storage/userMeLocalStorage";
|
|
37
37
|
import SiteSettingsLocalStorage from "../local_storage/siteSettingsLocalStorage";
|
|
38
38
|
import SiteSettingsRuntimeCache from "../siteSettings/siteSettingsRuntimeCache";
|
|
@@ -40,6 +40,7 @@ import OfflineSettingsLocalStorage from "../local_storage/offlineSettingsLocalSt
|
|
|
40
40
|
import CanUseOfflineStorageService from "../offline/canUseOfflineStorageService";
|
|
41
41
|
import OfflineRetentionDataFlushService from "../offline/offlineRetentionDataFlushService";
|
|
42
42
|
import BuildApiClientOptionsService from "../account/buildApiClientOptionsService";
|
|
43
|
+
import SessionTimestampsLocalStorage from "../local_storage/sessionTimestampsLocalStorage";
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* Flush storage data when:
|
|
@@ -118,7 +119,8 @@ class LocalStorageService {
|
|
|
118
119
|
*/
|
|
119
120
|
if (!canUseOfflineStorage) {
|
|
120
121
|
flushes.push(
|
|
121
|
-
new
|
|
122
|
+
new ActiveSessionSessionStorage(account).flush(),
|
|
123
|
+
new SessionTimestampsLocalStorage(account).flush(),
|
|
122
124
|
new RbacsLocalStorage(account).flush(),
|
|
123
125
|
new ResourceTypeLocalStorage(account).flush(),
|
|
124
126
|
new UserMeLocalStorage(account).flush(),
|
|
@@ -34,12 +34,13 @@ import { METADATA_KEYS_SETTINGS_LOCAL_STORAGE_KEY } from "../local_storage/metad
|
|
|
34
34
|
import GroupLocalStorage, { GROUP_LOCAL_STORAGE_KEY } from "../local_storage/groupLocalStorage";
|
|
35
35
|
import UserMeLocalStorage, { USER_ME_STORAGE_KEY_PREFIX } from "../local_storage/userMeLocalStorage";
|
|
36
36
|
import ResourceTypeLocalStorage, { RESOURCE_TYPES_LOCAL_STORAGE_KEY } from "../local_storage/resourceTypeLocalStorage";
|
|
37
|
-
import
|
|
37
|
+
import ActiveSessionSessionStorage, {
|
|
38
38
|
ACTIVE_SESSION_LOCAL_STORAGE_KEY,
|
|
39
|
-
} from "../
|
|
39
|
+
} from "../session_storage/activeSessionSessionStorage";
|
|
40
40
|
import SiteSettingsLocalStorage, { SITE_SETTINGS } from "../local_storage/siteSettingsLocalStorage";
|
|
41
41
|
import CanUseOfflineStorageService from "../offline/canUseOfflineStorageService";
|
|
42
42
|
import OfflineRetentionDataFlushService from "../offline/offlineRetentionDataFlushService";
|
|
43
|
+
import { SESSION_TIMESTAMPS_LOCAL_STORAGE_KEY } from "../local_storage/sessionTimestampsLocalStorage";
|
|
43
44
|
|
|
44
45
|
beforeEach(() => {
|
|
45
46
|
jest.clearAllMocks();
|
|
@@ -62,7 +63,7 @@ describe("LocalStorageService", () => {
|
|
|
62
63
|
jest.spyOn(GroupLocalStorage.prototype, "flush");
|
|
63
64
|
jest.spyOn(ResourceTypeLocalStorage.prototype, "flush");
|
|
64
65
|
jest.spyOn(RbacLocalStorage.prototype, "flush");
|
|
65
|
-
jest.spyOn(
|
|
66
|
+
jest.spyOn(ActiveSessionSessionStorage.prototype, "flush");
|
|
66
67
|
jest.spyOn(SiteSettingsLocalStorage.prototype, "flush");
|
|
67
68
|
// process
|
|
68
69
|
await LocalStorageService.flush();
|
|
@@ -89,14 +90,14 @@ describe("LocalStorageService", () => {
|
|
|
89
90
|
expect(GroupLocalStorage.prototype.flush).not.toHaveBeenCalled();
|
|
90
91
|
expect(ResourceTypeLocalStorage.prototype.flush).not.toHaveBeenCalled();
|
|
91
92
|
expect(RbacLocalStorage.prototype.flush).not.toHaveBeenCalled();
|
|
92
|
-
expect(
|
|
93
|
+
expect(ActiveSessionSessionStorage.prototype.flush).not.toHaveBeenCalled();
|
|
93
94
|
expect(SiteSettingsLocalStorage.prototype.flush).not.toHaveBeenCalled();
|
|
94
95
|
});
|
|
95
96
|
});
|
|
96
97
|
|
|
97
98
|
describe("LocalStorageService::flushAccountBasedStorages", () => {
|
|
98
99
|
it("Should retain the offline-related storages when the user can use offline storage while flushing others", async () => {
|
|
99
|
-
expect.assertions(
|
|
100
|
+
expect.assertions(18);
|
|
100
101
|
// mock data
|
|
101
102
|
await MockExtension.withConfiguredAccount();
|
|
102
103
|
const account = new AccountEntity(defaultAccountDto());
|
|
@@ -143,20 +144,24 @@ describe("LocalStorageService", () => {
|
|
|
143
144
|
expect(browser.storage.local.remove).not.toHaveBeenCalledWith(
|
|
144
145
|
`${RESOURCE_TYPES_LOCAL_STORAGE_KEY}-${account.id}`,
|
|
145
146
|
);
|
|
146
|
-
expect(browser.storage.
|
|
147
|
+
expect(browser.storage.session.remove).not.toHaveBeenCalledWith(
|
|
147
148
|
`${ACTIVE_SESSION_LOCAL_STORAGE_KEY}-${account.id}`,
|
|
148
149
|
);
|
|
150
|
+
expect(browser.storage.local.remove).not.toHaveBeenCalledWith(
|
|
151
|
+
`${SESSION_TIMESTAMPS_LOCAL_STORAGE_KEY}-${account.id}`,
|
|
152
|
+
);
|
|
149
153
|
expect(browser.storage.local.remove).not.toHaveBeenCalledWith(`${SITE_SETTINGS}-${account.id}`);
|
|
150
154
|
expect(OfflineRetentionDataFlushService.prototype.flushIfExceeded).toHaveBeenCalledWith();
|
|
151
155
|
});
|
|
152
156
|
|
|
153
157
|
it("Should flush the offline-related storages when the user cannot use offline storage", async () => {
|
|
154
|
-
expect.assertions(
|
|
158
|
+
expect.assertions(10);
|
|
155
159
|
// mock data
|
|
156
160
|
await MockExtension.withConfiguredAccount();
|
|
157
161
|
const account = new AccountEntity(defaultAccountDto());
|
|
158
162
|
// spy on
|
|
159
163
|
jest.spyOn(browser.storage.local, "remove");
|
|
164
|
+
jest.spyOn(browser.storage.session, "remove");
|
|
160
165
|
jest.spyOn(GetLegacyAccountService, "get").mockImplementation(() => account);
|
|
161
166
|
// The user is not eligible for offline access: the org did not configure it, or its role is denied.
|
|
162
167
|
jest
|
|
@@ -166,26 +171,30 @@ describe("LocalStorageService", () => {
|
|
|
166
171
|
await LocalStorageService.flushAccountBasedStorages();
|
|
167
172
|
// expectations: the offline-related storages are fully flushed.
|
|
168
173
|
expect(CanUseOfflineStorageService.canUseOfflineStorageFromLocalStorage).toHaveBeenCalledWith(account);
|
|
169
|
-
expect(browser.storage.
|
|
174
|
+
expect(browser.storage.session.remove).toHaveBeenCalledWith(`${ACTIVE_SESSION_LOCAL_STORAGE_KEY}-${account.id}`);
|
|
170
175
|
expect(browser.storage.local.remove).toHaveBeenCalledWith(`${SITE_SETTINGS}-${account.id}`);
|
|
171
176
|
expect(browser.storage.local.remove).toHaveBeenCalledWith(`${RBACS_LOCAL_STORAGE_KEY}-metadata-${account.id}`);
|
|
172
177
|
expect(browser.storage.local.remove).toHaveBeenCalledWith(`${RBACS_LOCAL_STORAGE_KEY}-${account.id}`);
|
|
173
178
|
expect(browser.storage.local.remove).toHaveBeenCalledWith(
|
|
174
179
|
`${RESOURCE_TYPES_LOCAL_STORAGE_KEY}-metadata-${account.id}`,
|
|
175
180
|
);
|
|
181
|
+
expect(browser.storage.local.remove).toHaveBeenCalledWith(
|
|
182
|
+
`${SESSION_TIMESTAMPS_LOCAL_STORAGE_KEY}-${account.id}`,
|
|
183
|
+
);
|
|
176
184
|
expect(browser.storage.local.remove).toHaveBeenCalledWith(`${RESOURCE_TYPES_LOCAL_STORAGE_KEY}-${account.id}`);
|
|
177
185
|
expect(browser.storage.local.remove).toHaveBeenCalledWith(`${USER_ME_STORAGE_KEY_PREFIX}-metadata-${account.id}`);
|
|
178
186
|
expect(browser.storage.local.remove).toHaveBeenCalledWith(`${USER_ME_STORAGE_KEY_PREFIX}-${account.id}`);
|
|
179
187
|
});
|
|
180
188
|
|
|
181
189
|
it("Should flush the offline-related storages when the offline capability cannot be resolved", async () => {
|
|
182
|
-
expect.assertions(
|
|
190
|
+
expect.assertions(7);
|
|
183
191
|
// mock data
|
|
184
192
|
await MockExtension.withConfiguredAccount();
|
|
185
193
|
const account = new AccountEntity(defaultAccountDto());
|
|
186
194
|
const error = new Error("Could not resolve the offline capability.");
|
|
187
195
|
// spy on
|
|
188
196
|
jest.spyOn(browser.storage.local, "remove");
|
|
197
|
+
jest.spyOn(browser.storage.session, "remove");
|
|
189
198
|
jest.spyOn(console, "error").mockImplementation(() => {});
|
|
190
199
|
jest.spyOn(GetLegacyAccountService, "get").mockImplementation(() => account);
|
|
191
200
|
jest
|
|
@@ -198,7 +207,10 @@ describe("LocalStorageService", () => {
|
|
|
198
207
|
"LocalStorageService: could not resolve the offline capability, flushing all storages.",
|
|
199
208
|
error,
|
|
200
209
|
);
|
|
201
|
-
expect(browser.storage.local.remove).toHaveBeenCalledWith(
|
|
210
|
+
expect(browser.storage.local.remove).toHaveBeenCalledWith(
|
|
211
|
+
`${SESSION_TIMESTAMPS_LOCAL_STORAGE_KEY}-${account.id}`,
|
|
212
|
+
);
|
|
213
|
+
expect(browser.storage.session.remove).toHaveBeenCalledWith(`${ACTIVE_SESSION_LOCAL_STORAGE_KEY}-${account.id}`);
|
|
202
214
|
expect(browser.storage.local.remove).toHaveBeenCalledWith(`${SITE_SETTINGS}-${account.id}`);
|
|
203
215
|
expect(browser.storage.local.remove).toHaveBeenCalledWith(`${RBACS_LOCAL_STORAGE_KEY}-${account.id}`);
|
|
204
216
|
expect(browser.storage.local.remove).toHaveBeenCalledWith(`${RESOURCE_TYPES_LOCAL_STORAGE_KEY}-${account.id}`);
|
|
@@ -206,13 +218,14 @@ describe("LocalStorageService", () => {
|
|
|
206
218
|
});
|
|
207
219
|
|
|
208
220
|
it("Should log a failing storage flush and carry on with the other ones", async () => {
|
|
209
|
-
expect.assertions(
|
|
221
|
+
expect.assertions(5);
|
|
210
222
|
// mock data
|
|
211
223
|
await MockExtension.withConfiguredAccount();
|
|
212
224
|
const account = new AccountEntity(defaultAccountDto());
|
|
213
225
|
const error = new Error("Could not flush the groups.");
|
|
214
226
|
// spy on
|
|
215
227
|
jest.spyOn(browser.storage.local, "remove");
|
|
228
|
+
jest.spyOn(browser.storage.session, "remove");
|
|
216
229
|
jest.spyOn(console, "error").mockImplementation(() => {});
|
|
217
230
|
jest.spyOn(GetLegacyAccountService, "get").mockImplementation(() => account);
|
|
218
231
|
jest
|
|
@@ -224,7 +237,10 @@ describe("LocalStorageService", () => {
|
|
|
224
237
|
expect(console.error).toHaveBeenCalledTimes(1);
|
|
225
238
|
expect(console.error).toHaveBeenCalledWith("LocalStorageService: a storage flush failed and was ignored.", error);
|
|
226
239
|
// The storages flushed alongside the failing one are not impacted.
|
|
227
|
-
expect(browser.storage.local.remove).toHaveBeenCalledWith(
|
|
240
|
+
expect(browser.storage.local.remove).toHaveBeenCalledWith(
|
|
241
|
+
`${SESSION_TIMESTAMPS_LOCAL_STORAGE_KEY}-${account.id}`,
|
|
242
|
+
);
|
|
243
|
+
expect(browser.storage.session.remove).toHaveBeenCalledWith(`${ACTIVE_SESSION_LOCAL_STORAGE_KEY}-${account.id}`);
|
|
228
244
|
});
|
|
229
245
|
});
|
|
230
246
|
|
|
@@ -0,0 +1,40 @@
|
|
|
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 SessionTimestampsEntity from "passbolt-styleguide/src/shared/models/entity/sessionTimestamps/sessionTimestampsEntity";
|
|
15
|
+
import AbstractLocalStorage from "./abstractLocalStorage";
|
|
16
|
+
|
|
17
|
+
export const SESSION_TIMESTAMPS_LOCAL_STORAGE_KEY = "session_timestamps";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The session timestamps (last_logged_in, last_seen_online).
|
|
21
|
+
*/
|
|
22
|
+
class SessionTimestampsLocalStorage extends AbstractLocalStorage {
|
|
23
|
+
/**
|
|
24
|
+
* Get the key property
|
|
25
|
+
* @return {string}
|
|
26
|
+
*/
|
|
27
|
+
get key() {
|
|
28
|
+
return SESSION_TIMESTAMPS_LOCAL_STORAGE_KEY;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get the entity class
|
|
33
|
+
* @return {SessionTimestampsEntity}
|
|
34
|
+
*/
|
|
35
|
+
get entityClass() {
|
|
36
|
+
return SessionTimestampsEntity;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default SessionTimestampsLocalStorage;
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
|
|
15
|
+
import SessionTimestampsLocalStorage from "./sessionTimestampsLocalStorage";
|
|
16
|
+
import { defaultSessionTimestampsDto } from "passbolt-styleguide/src/shared/models/entity/sessionTimestamps/sessionTimestampsEntity.test.data";
|
|
17
|
+
import SessionTimestampsEntity from "passbolt-styleguide/src/shared/models/entity/sessionTimestamps/sessionTimestampsEntity";
|
|
18
|
+
import AccountEntity from "../../model/entity/account/accountEntity";
|
|
19
|
+
import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
|
|
20
|
+
|
|
21
|
+
describe("SessionTimestampsLocalStorage", () => {
|
|
22
|
+
// mock data
|
|
23
|
+
const account = new AccountEntity(defaultAccountDto());
|
|
24
|
+
|
|
25
|
+
describe("SessionTimestampsLocalStorage::get", () => {
|
|
26
|
+
it("Should return undefined if nothing stored in the storage", async () => {
|
|
27
|
+
expect.assertions(1);
|
|
28
|
+
const sessionTimestampsLocalStorage = new SessionTimestampsLocalStorage(account);
|
|
29
|
+
const result = await sessionTimestampsLocalStorage.getData();
|
|
30
|
+
expect(result).toEqual(undefined);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("Should return content stored in the local storage", async () => {
|
|
34
|
+
const sessionTimestamps = defaultSessionTimestampsDto();
|
|
35
|
+
expect.assertions(1);
|
|
36
|
+
const sessionTimestampsLocalStorage = new SessionTimestampsLocalStorage(account);
|
|
37
|
+
browser.storage.local.set({ [sessionTimestampsLocalStorage.storageDataKey]: sessionTimestamps });
|
|
38
|
+
const result = await sessionTimestampsLocalStorage.getData();
|
|
39
|
+
expect(result).toEqual(sessionTimestamps);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("SessionTimestampsLocalStorage::setData", () => {
|
|
44
|
+
it("Should setData the session timestamps in the local storage", async () => {
|
|
45
|
+
expect.assertions(1);
|
|
46
|
+
const sessionTimestampsLocalStorage = new SessionTimestampsLocalStorage(account);
|
|
47
|
+
const sessionTimestamps = new SessionTimestampsEntity(defaultSessionTimestampsDto());
|
|
48
|
+
await sessionTimestampsLocalStorage.setData(sessionTimestamps);
|
|
49
|
+
const result = await sessionTimestampsLocalStorage.getData();
|
|
50
|
+
expect(result).toEqual(sessionTimestamps.toDto());
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("SessionTimestampsLocalStorage::flush", () => {
|
|
55
|
+
it("Should flush the session timestamps from the local storage", async () => {
|
|
56
|
+
expect.assertions(1);
|
|
57
|
+
const sessionTimestampsLocalStorage = new SessionTimestampsLocalStorage(account);
|
|
58
|
+
await sessionTimestampsLocalStorage.flush();
|
|
59
|
+
const result = await sessionTimestampsLocalStorage.getData();
|
|
60
|
+
expect(result).toEqual(undefined);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
package/src/all/background_page/service/metadata/rotateMetadata/rotateMetadataKeyService.test.js
CHANGED
|
@@ -28,10 +28,10 @@ import { defaultMetadataKeyDto } from "passbolt-styleguide/src/shared/models/ent
|
|
|
28
28
|
describe("RotateMetadataKeyService", () => {
|
|
29
29
|
let account;
|
|
30
30
|
|
|
31
|
-
beforeEach(() => {
|
|
31
|
+
beforeEach(async () => {
|
|
32
32
|
jest.clearAllMocks();
|
|
33
33
|
|
|
34
|
-
MockExtension.withConfiguredAccount();
|
|
34
|
+
await MockExtension.withConfiguredAccount();
|
|
35
35
|
account = new AccountEntity(defaultAccountDto());
|
|
36
36
|
});
|
|
37
37
|
|
|
@@ -38,10 +38,10 @@ import GetOrFindResourceTypesService from "../../resourceType/getOrFindResourceT
|
|
|
38
38
|
describe("RotateResourcesMetadataKeyService", () => {
|
|
39
39
|
let account, metadataKeysDtos;
|
|
40
40
|
|
|
41
|
-
beforeEach(() => {
|
|
41
|
+
beforeEach(async () => {
|
|
42
42
|
jest.clearAllMocks();
|
|
43
43
|
|
|
44
|
-
MockExtension.withConfiguredAccount();
|
|
44
|
+
await MockExtension.withConfiguredAccount();
|
|
45
45
|
account = new AccountEntity(defaultAccountDto());
|
|
46
46
|
metadataKeysDtos = [
|
|
47
47
|
...defaultDecryptedSharedMetadataKeysDtos(),
|
package/src/all/background_page/service/migrateMetadata/migrateMetadataResourcesService.test.js
CHANGED
|
@@ -47,10 +47,10 @@ import GetOrFindResourceTypesService from "../resourceType/getOrFindResourceType
|
|
|
47
47
|
describe("MigrateMetadataResourcesService", () => {
|
|
48
48
|
let account = null;
|
|
49
49
|
|
|
50
|
-
beforeEach(() => {
|
|
50
|
+
beforeEach(async () => {
|
|
51
51
|
jest.clearAllMocks();
|
|
52
52
|
|
|
53
|
-
MockExtension.withConfiguredAccount();
|
|
53
|
+
await MockExtension.withConfiguredAccount();
|
|
54
54
|
account = new AccountEntity(defaultAccountDto());
|
|
55
55
|
const metadataKeysDtos = defaultDecryptedSharedMetadataKeysDtos({ armored_key: pgpKeys.metadataKey.public });
|
|
56
56
|
const metadataKeys = new MetadataKeysCollection(metadataKeysDtos);
|
|
@@ -24,6 +24,7 @@ import UserMeLocalStorage from "../local_storage/userMeLocalStorage";
|
|
|
24
24
|
import RbacsLocalStorage from "../local_storage/rbacLocalStorage";
|
|
25
25
|
import UserEntity from "../../model/entity/user/userEntity";
|
|
26
26
|
import CanUse from "passbolt-styleguide/src/shared/services/rbacs/canUseService";
|
|
27
|
+
import SiteSettingsRuntimeCache from "../siteSettings/siteSettingsRuntimeCache";
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Returns whether the current user can use offline storage for resources.
|
|
@@ -114,8 +115,22 @@ export default class CanUseOfflineStorageService {
|
|
|
114
115
|
*/
|
|
115
116
|
static async canUseOfflineStorageFromLocalStorage(account) {
|
|
116
117
|
const siteSettingsDto = await new SiteSettingsLocalStorage(account).get();
|
|
117
|
-
if (!siteSettingsDto
|
|
118
|
+
if (!siteSettingsDto) {
|
|
118
119
|
return false;
|
|
120
|
+
} else {
|
|
121
|
+
const siteSettings = new SiteSettingsEntity(siteSettingsDto);
|
|
122
|
+
if (!siteSettings?.isPluginEnabled("offlineMode")) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
/*
|
|
126
|
+
* Mirror the persisted settings into the in-memory runtime cache. The cache is
|
|
127
|
+
* service-worker-lifetime and is flushed on login (postLoginService) and lost on
|
|
128
|
+
* service-worker restart, whereas SiteSettingsLocalStorage survives both. Seeding it
|
|
129
|
+
* here keeps AppEmailValidatorService.validate - which reads SiteSettingsRuntimeCache
|
|
130
|
+
* synchronously to validate account usernames - in sync with the persisted settings,
|
|
131
|
+
* so a custom email validation regex is honored even after the cache has been dropped.
|
|
132
|
+
*/
|
|
133
|
+
SiteSettingsRuntimeCache.set(siteSettings);
|
|
119
134
|
}
|
|
120
135
|
|
|
121
136
|
const offlineSettingsDto = await new OfflineSettingsLocalStorage(account).getData();
|
|
@@ -39,6 +39,7 @@ import SiteSettingsLocalStorage from "../local_storage/siteSettingsLocalStorage"
|
|
|
39
39
|
import UserMeLocalStorage from "../local_storage/userMeLocalStorage";
|
|
40
40
|
import RbacsLocalStorage from "../local_storage/rbacLocalStorage";
|
|
41
41
|
import CanUseOfflineStorageService from "./canUseOfflineStorageService";
|
|
42
|
+
import SiteSettingsRuntimeCache from "../siteSettings/siteSettingsRuntimeCache";
|
|
42
43
|
|
|
43
44
|
const allowOfflineAccessRbac = (data = {}) =>
|
|
44
45
|
defaultRbacWithActionData({ action: defaultActionData({ name: actions.OFFLINE_ITEMS_VIEW }), ...data });
|
|
@@ -155,6 +156,7 @@ describe("CanUseOfflineStorageService", () => {
|
|
|
155
156
|
jest.spyOn(OfflineSettingsLocalStorage.prototype, "getData").mockResolvedValue(offlineSettings);
|
|
156
157
|
jest.spyOn(UserMeLocalStorage.prototype, "getData").mockResolvedValue(user);
|
|
157
158
|
jest.spyOn(RbacsLocalStorage.prototype, "getData").mockResolvedValue(rbacs);
|
|
159
|
+
jest.spyOn(SiteSettingsRuntimeCache, "set");
|
|
158
160
|
};
|
|
159
161
|
|
|
160
162
|
it("returns false when the site settings storage is empty, without reading the other storages.", async () => {
|
|
@@ -186,30 +188,33 @@ describe("CanUseOfflineStorageService", () => {
|
|
|
186
188
|
});
|
|
187
189
|
|
|
188
190
|
it("returns false when the offline settings storage is empty, without reading the other storages.", async () => {
|
|
189
|
-
expect.assertions(
|
|
191
|
+
expect.assertions(4);
|
|
190
192
|
mockStorages({ offlineSettings: undefined, user: defaultAdminUserDto(), rbacs: [] });
|
|
191
193
|
|
|
192
194
|
expect(await CanUseOfflineStorageService.canUseOfflineStorageFromLocalStorage(account)).toBe(false);
|
|
193
195
|
expect(UserMeLocalStorage.prototype.getData).not.toHaveBeenCalled();
|
|
194
196
|
expect(RbacsLocalStorage.prototype.getData).not.toHaveBeenCalled();
|
|
197
|
+
expect(SiteSettingsRuntimeCache.set).toHaveBeenCalled();
|
|
195
198
|
});
|
|
196
199
|
|
|
197
200
|
it("returns false when the user me storage is empty.", async () => {
|
|
198
|
-
expect.assertions(
|
|
201
|
+
expect.assertions(2);
|
|
199
202
|
mockStorages({ offlineSettings: defaultOfflineSettingsDto(), user: undefined, rbacs: [] });
|
|
200
203
|
|
|
201
204
|
expect(await CanUseOfflineStorageService.canUseOfflineStorageFromLocalStorage(account)).toBe(false);
|
|
205
|
+
expect(SiteSettingsRuntimeCache.set).toHaveBeenCalled();
|
|
202
206
|
});
|
|
203
207
|
|
|
204
208
|
it("returns true for an administrator even when the rbacs storage is empty.", async () => {
|
|
205
|
-
expect.assertions(
|
|
209
|
+
expect.assertions(2);
|
|
206
210
|
mockStorages({ offlineSettings: defaultOfflineSettingsDto(), user: defaultAdminUserDto(), rbacs: undefined });
|
|
207
211
|
|
|
208
212
|
expect(await CanUseOfflineStorageService.canUseOfflineStorageFromLocalStorage(account)).toBe(true);
|
|
213
|
+
expect(SiteSettingsRuntimeCache.set).toHaveBeenCalled();
|
|
209
214
|
});
|
|
210
215
|
|
|
211
216
|
it("returns false for a user when the rbacs storage is empty.", async () => {
|
|
212
|
-
expect.assertions(
|
|
217
|
+
expect.assertions(2);
|
|
213
218
|
mockStorages({
|
|
214
219
|
offlineSettings: defaultOfflineSettingsDto(),
|
|
215
220
|
user: defaultUserDto({}, { withRole: true }),
|
|
@@ -217,10 +222,11 @@ describe("CanUseOfflineStorageService", () => {
|
|
|
217
222
|
});
|
|
218
223
|
|
|
219
224
|
expect(await CanUseOfflineStorageService.canUseOfflineStorageFromLocalStorage(account)).toBe(false);
|
|
225
|
+
expect(SiteSettingsRuntimeCache.set).toHaveBeenCalled();
|
|
220
226
|
});
|
|
221
227
|
|
|
222
228
|
it("returns true when the user role is allowed.", async () => {
|
|
223
|
-
expect.assertions(
|
|
229
|
+
expect.assertions(2);
|
|
224
230
|
const userDto = defaultUserDto({}, { withRole: true });
|
|
225
231
|
mockStorages({
|
|
226
232
|
offlineSettings: defaultOfflineSettingsDto(),
|
|
@@ -229,10 +235,11 @@ describe("CanUseOfflineStorageService", () => {
|
|
|
229
235
|
});
|
|
230
236
|
|
|
231
237
|
expect(await CanUseOfflineStorageService.canUseOfflineStorageFromLocalStorage(account)).toBe(true);
|
|
238
|
+
expect(SiteSettingsRuntimeCache.set).toHaveBeenCalled();
|
|
232
239
|
});
|
|
233
240
|
|
|
234
241
|
it("returns false when the user role is denied.", async () => {
|
|
235
|
-
expect.assertions(
|
|
242
|
+
expect.assertions(2);
|
|
236
243
|
const userDto = defaultUserDto({}, { withRole: true });
|
|
237
244
|
mockStorages({
|
|
238
245
|
offlineSettings: defaultOfflineSettingsDto(),
|
|
@@ -241,6 +248,7 @@ describe("CanUseOfflineStorageService", () => {
|
|
|
241
248
|
});
|
|
242
249
|
|
|
243
250
|
expect(await CanUseOfflineStorageService.canUseOfflineStorageFromLocalStorage(account)).toBe(false);
|
|
251
|
+
expect(SiteSettingsRuntimeCache.set).toHaveBeenCalled();
|
|
244
252
|
});
|
|
245
253
|
|
|
246
254
|
it("throws when a stored dto does not validate, return false to not block the process.", async () => {
|
|
@@ -15,6 +15,7 @@ import OfflineSettingsEntity from "passbolt-styleguide/src/shared/models/entity/
|
|
|
15
15
|
import OfflineSettingsLocalStorage from "../local_storage/offlineSettingsLocalStorage";
|
|
16
16
|
import FindAndUpdateOfflineSettingsLocalStorageService from "./findAndUpdateOfflineSettingsLocalStorageService";
|
|
17
17
|
import GetOrFindActiveSessionService from "../activeSession/getOrFindActiveSessionService";
|
|
18
|
+
import GetSessionTimestampsService from "../sessionTimestamps/getSessionTimestampsService";
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* The service aims to get offline settings from the local storage if it is set, or retrieve them from the API and
|
|
@@ -33,6 +34,7 @@ export default class GetOrFindOfflineSettingsService {
|
|
|
33
34
|
apiClientOptions,
|
|
34
35
|
);
|
|
35
36
|
this.getOrFindActiveSessionService = new GetOrFindActiveSessionService(account, apiClientOptions);
|
|
37
|
+
this.getSessionTimestampsService = new GetSessionTimestampsService(account);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
/**
|
|
@@ -41,11 +43,12 @@ export default class GetOrFindOfflineSettingsService {
|
|
|
41
43
|
*/
|
|
42
44
|
async getOrFind() {
|
|
43
45
|
const activeSession = await this.getOrFindActiveSessionService.getOrFind();
|
|
46
|
+
const lastLoggedIn = (await this.getSessionTimestampsService.get())?.lastLoggedIn;
|
|
44
47
|
// Only an online session with a server reachable refreshes stale data; an offline session cannot reach the API.
|
|
45
48
|
const isStale =
|
|
46
49
|
activeSession.isSessionOnline &&
|
|
47
50
|
activeSession.isServerReachable &&
|
|
48
|
-
(await this.offlineSettingsLocalStorage.isStaleSinceLastLoggedIn(
|
|
51
|
+
(await this.offlineSettingsLocalStorage.isStaleSinceLastLoggedIn(lastLoggedIn));
|
|
49
52
|
if (!isStale) {
|
|
50
53
|
const offlineSettingsDto = await this.offlineSettingsLocalStorage.getData();
|
|
51
54
|
if (offlineSettingsDto) {
|
|
@@ -26,11 +26,20 @@ import UserActiveSessionEntity, {
|
|
|
26
26
|
import { defaultUserActiveSessionDto } from "passbolt-styleguide/src/shared/models/entity/session/userActiveSessionEntity.test.data";
|
|
27
27
|
import LocalStorageMetadataEntity from "../../model/entity/localStorage/localStorageMetadataEntity";
|
|
28
28
|
import GetOrFindActiveSessionService from "../activeSession/getOrFindActiveSessionService";
|
|
29
|
+
import GetSessionTimestampsService from "../sessionTimestamps/getSessionTimestampsService";
|
|
30
|
+
import SessionTimestampsEntity from "passbolt-styleguide/src/shared/models/entity/sessionTimestamps/sessionTimestampsEntity";
|
|
31
|
+
import { defaultSessionTimestampsDto } from "passbolt-styleguide/src/shared/models/entity/sessionTimestamps/sessionTimestampsEntity.test.data";
|
|
29
32
|
|
|
30
|
-
const mockActiveSession = (data) =>
|
|
33
|
+
const mockActiveSession = ({ last_logged_in, ...data } = {}) => {
|
|
31
34
|
jest
|
|
32
35
|
.spyOn(GetOrFindActiveSessionService.prototype, "getOrFind")
|
|
33
36
|
.mockResolvedValue(new UserActiveSessionEntity(defaultUserActiveSessionDto(data)));
|
|
37
|
+
jest
|
|
38
|
+
.spyOn(GetSessionTimestampsService.prototype, "get")
|
|
39
|
+
.mockResolvedValue(
|
|
40
|
+
last_logged_in ? new SessionTimestampsEntity(defaultSessionTimestampsDto({ last_logged_in })) : null,
|
|
41
|
+
);
|
|
42
|
+
};
|
|
34
43
|
|
|
35
44
|
beforeEach(() => {
|
|
36
45
|
jest.clearAllMocks();
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
* @link https://www.passbolt.com Passbolt(tm)
|
|
12
12
|
* @since 6.0.0
|
|
13
13
|
*/
|
|
14
|
-
import GetOrFindActiveSessionService from "../activeSession/getOrFindActiveSessionService";
|
|
15
14
|
import GetOrFindOfflineSettingsService from "./getOrFindOfflineSettingsService";
|
|
16
15
|
import MetadataKeyOPFSStorage from "../opfsStorage/metadataKeyOPFSStorage";
|
|
17
16
|
import OfflineResourcesOPFSStorage from "../opfsStorage/offlineResourcesOPFSStorage";
|
|
18
17
|
import OfflineSecretsOPFSStorage from "../opfsStorage/offlineSecretsOPFSStorage";
|
|
18
|
+
import GetSessionTimestampsService from "../sessionTimestamps/getSessionTimestampsService";
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Flush offline data if time is exceeded.
|
|
@@ -28,7 +28,7 @@ export default class OfflineRetentionDataFlushService {
|
|
|
28
28
|
* @param {ApiClientOptions} apiClientOptions The api client options.
|
|
29
29
|
*/
|
|
30
30
|
constructor(account, apiClientOptions) {
|
|
31
|
-
this.
|
|
31
|
+
this.getSessionTimestampsService = new GetSessionTimestampsService(account, apiClientOptions);
|
|
32
32
|
this.getOrFindOfflineSettingsService = new GetOrFindOfflineSettingsService(account, apiClientOptions);
|
|
33
33
|
this.metadataKeyOPFSStorage = new MetadataKeyOPFSStorage(account);
|
|
34
34
|
this.offlineResourcesOPFSStorage = new OfflineResourcesOPFSStorage(account);
|
|
@@ -42,18 +42,21 @@ export default class OfflineRetentionDataFlushService {
|
|
|
42
42
|
*/
|
|
43
43
|
async flushIfExceeded() {
|
|
44
44
|
try {
|
|
45
|
-
const
|
|
45
|
+
const sessionTimestampsEntity = await this.getSessionTimestampsService.get();
|
|
46
46
|
const offlineSettingsEntity = await this.getOrFindOfflineSettingsService.getOrFind();
|
|
47
47
|
|
|
48
|
-
if (
|
|
48
|
+
if (offlineSettingsEntity === null) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
// A missing last seen online date counts as expired.
|
|
53
|
+
let isExpired = !sessionTimestampsEntity?.lastSeenOnline;
|
|
54
|
+
if (!isExpired) {
|
|
55
|
+
// Create the date (last seen online + maximum retention period in days) to compare with now
|
|
56
|
+
const retentionPeriodDate = new Date(sessionTimestampsEntity.lastSeenOnline);
|
|
57
|
+
retentionPeriodDate.setDate(retentionPeriodDate.getDate() + offlineSettingsEntity.maximumRetentionPeriod);
|
|
58
|
+
isExpired = retentionPeriodDate.getTime() < Date.now();
|
|
59
|
+
}
|
|
57
60
|
if (isExpired) {
|
|
58
61
|
// Keep a trace if any error happen during the flush
|
|
59
62
|
const logErrorFlushOPFSStorage = (settledResults) => {
|