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
|
@@ -0,0 +1,720 @@
|
|
|
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 6.0.0
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import AccountEntity from "../../model/entity/account/accountEntity";
|
|
16
|
+
import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
|
|
17
|
+
import { defaultApiClientOptions } from "passbolt-styleguide/src/shared/lib/apiClient/apiClientOptions.test.data";
|
|
18
|
+
import FindAndUpdateActiveSessionSessionStorageService from "./findAndUpdateActiveSessionSessionStorageService";
|
|
19
|
+
import UserActiveSessionEntity, {
|
|
20
|
+
USER_ACTIVE_SESSION_OFFLINE,
|
|
21
|
+
USER_ACTIVE_SESSION_ONLINE,
|
|
22
|
+
} from "passbolt-styleguide/src/shared/models/entity/session/userActiveSessionEntity";
|
|
23
|
+
import MfaAuthenticationRequiredError from "../../error/mfaAuthenticationRequiredError";
|
|
24
|
+
import SessionTimestampsEntity from "passbolt-styleguide/src/shared/models/entity/sessionTimestamps/sessionTimestampsEntity";
|
|
25
|
+
import { defaultSessionTimestampsDto } from "passbolt-styleguide/src/shared/models/entity/sessionTimestamps/sessionTimestampsEntity.test.data";
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
jest.clearAllMocks();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("FindAndUpdateActiveSessionSessionStorageService", () => {
|
|
32
|
+
let findAndUpdateActiveSessionSessionStorageService, account, apiClientOptions;
|
|
33
|
+
|
|
34
|
+
beforeEach(async () => {
|
|
35
|
+
account = new AccountEntity(defaultAccountDto());
|
|
36
|
+
apiClientOptions = defaultApiClientOptions();
|
|
37
|
+
findAndUpdateActiveSessionSessionStorageService = new FindAndUpdateActiveSessionSessionStorageService(
|
|
38
|
+
account,
|
|
39
|
+
apiClientOptions,
|
|
40
|
+
);
|
|
41
|
+
// flush account related storage before each.
|
|
42
|
+
await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.flush();
|
|
43
|
+
await findAndUpdateActiveSessionSessionStorageService.updateSessionTimestampsService.sessionTimestampsLocalStorage.flush();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the stored session timestamps.
|
|
48
|
+
* @returns {Promise<object|undefined>}
|
|
49
|
+
*/
|
|
50
|
+
const getStoredSessionTimestamps = () =>
|
|
51
|
+
findAndUpdateActiveSessionSessionStorageService.updateSessionTimestampsService.sessionTimestampsLocalStorage.getData();
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Store session timestamps of a previous session.
|
|
55
|
+
* @returns {Promise<void>}
|
|
56
|
+
*/
|
|
57
|
+
const setPreviousSessionTimestamps = () =>
|
|
58
|
+
findAndUpdateActiveSessionSessionStorageService.updateSessionTimestampsService.sessionTimestampsLocalStorage.setData(
|
|
59
|
+
new SessionTimestampsEntity(
|
|
60
|
+
defaultSessionTimestampsDto({
|
|
61
|
+
last_seen_online: "2025-08-06T10:05:46+00:00",
|
|
62
|
+
last_logged_in: "2025-08-06T09:00:00+00:00",
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
describe("::findAndUpdateAuthenticationStatus", () => {
|
|
68
|
+
it("If no active session create a new one and store it into the local storage.", async () => {
|
|
69
|
+
expect.assertions(3);
|
|
70
|
+
const userActiveSession = {
|
|
71
|
+
is_authenticated: false,
|
|
72
|
+
is_mfa_required: false,
|
|
73
|
+
is_server_reachable: true,
|
|
74
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
75
|
+
};
|
|
76
|
+
jest
|
|
77
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
78
|
+
.mockImplementation(() => true);
|
|
79
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
80
|
+
|
|
81
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
82
|
+
|
|
83
|
+
expect(entity.toDto()).toEqual(userActiveSession);
|
|
84
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
85
|
+
expect(storageValue).toEqual(userActiveSession);
|
|
86
|
+
expect(
|
|
87
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
88
|
+
).not.toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("User having an online authenticated active session and server become not reachable, update is_server_reachable to false and store it into the local storage.", async () => {
|
|
92
|
+
expect.assertions(4);
|
|
93
|
+
const userActiveSession = {
|
|
94
|
+
is_authenticated: true,
|
|
95
|
+
is_mfa_required: false,
|
|
96
|
+
is_server_reachable: true,
|
|
97
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
98
|
+
};
|
|
99
|
+
jest
|
|
100
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
101
|
+
.mockImplementation(() => false);
|
|
102
|
+
jest
|
|
103
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
104
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
105
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
106
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
107
|
+
|
|
108
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
109
|
+
|
|
110
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
111
|
+
expectedEntity.isServerReachable = false;
|
|
112
|
+
expect(entity).toEqual(expectedEntity);
|
|
113
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
114
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
115
|
+
expect(
|
|
116
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
117
|
+
).not.toHaveBeenCalled();
|
|
118
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
119
|
+
expectedEntity,
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("User having online authenticated active session, update is mfa authenticated to true and store it into the local storage.", async () => {
|
|
124
|
+
expect.assertions(4);
|
|
125
|
+
const userActiveSession = {
|
|
126
|
+
is_authenticated: true,
|
|
127
|
+
is_mfa_required: false,
|
|
128
|
+
is_server_reachable: true,
|
|
129
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
130
|
+
};
|
|
131
|
+
jest
|
|
132
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
133
|
+
.mockImplementation(() => true);
|
|
134
|
+
jest
|
|
135
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
136
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
137
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
138
|
+
jest
|
|
139
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated")
|
|
140
|
+
.mockImplementationOnce(() => true);
|
|
141
|
+
|
|
142
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
143
|
+
|
|
144
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
145
|
+
expectedEntity.isMfaRequired = false;
|
|
146
|
+
expect(entity).toEqual(expectedEntity);
|
|
147
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
148
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
149
|
+
expect(
|
|
150
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
151
|
+
).toHaveBeenCalledTimes(1);
|
|
152
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
153
|
+
expectedEntity,
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("User having online authenticated active session, update is authenticated to false and store it into the local storage.", async () => {
|
|
158
|
+
expect.assertions(4);
|
|
159
|
+
const userActiveSession = {
|
|
160
|
+
is_authenticated: true,
|
|
161
|
+
is_mfa_required: false,
|
|
162
|
+
is_server_reachable: true,
|
|
163
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
164
|
+
};
|
|
165
|
+
jest
|
|
166
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
167
|
+
.mockImplementation(() => true);
|
|
168
|
+
jest
|
|
169
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
170
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
171
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
172
|
+
jest
|
|
173
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated")
|
|
174
|
+
.mockImplementationOnce(() => false);
|
|
175
|
+
|
|
176
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
177
|
+
|
|
178
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
179
|
+
expectedEntity.isAuthenticated = false;
|
|
180
|
+
expect(entity).toEqual(expectedEntity);
|
|
181
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
182
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
183
|
+
expect(
|
|
184
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
185
|
+
).toHaveBeenCalledTimes(1);
|
|
186
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
187
|
+
expectedEntity,
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("User having online authenticated active session, update is mfa authenticated to false and store it into the local storage.", async () => {
|
|
192
|
+
expect.assertions(4);
|
|
193
|
+
const userActiveSession = {
|
|
194
|
+
is_authenticated: true,
|
|
195
|
+
is_mfa_required: false,
|
|
196
|
+
is_server_reachable: true,
|
|
197
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
198
|
+
};
|
|
199
|
+
jest
|
|
200
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
201
|
+
.mockImplementation(() => true);
|
|
202
|
+
jest
|
|
203
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
204
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
205
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
206
|
+
jest
|
|
207
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated")
|
|
208
|
+
.mockImplementationOnce(() => {
|
|
209
|
+
throw new MfaAuthenticationRequiredError();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
213
|
+
|
|
214
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
215
|
+
expectedEntity.isMfaRequired = true;
|
|
216
|
+
expect(entity).toEqual(expectedEntity);
|
|
217
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
218
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
219
|
+
expect(
|
|
220
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
221
|
+
).toHaveBeenCalledTimes(1);
|
|
222
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
223
|
+
expectedEntity,
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("User having offline authenticated active session and server become reachable, update is_server_reachable to true and store it into the local storage.", async () => {
|
|
228
|
+
expect.assertions(4);
|
|
229
|
+
const userActiveSession = {
|
|
230
|
+
is_authenticated: true,
|
|
231
|
+
is_mfa_required: false,
|
|
232
|
+
is_server_reachable: false,
|
|
233
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
234
|
+
};
|
|
235
|
+
jest
|
|
236
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
237
|
+
.mockImplementation(() => true);
|
|
238
|
+
jest
|
|
239
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
240
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
241
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
242
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
243
|
+
|
|
244
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
245
|
+
|
|
246
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
247
|
+
expectedEntity.isServerReachable = true;
|
|
248
|
+
expect(entity).toEqual(expectedEntity);
|
|
249
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
250
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
251
|
+
expect(
|
|
252
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
253
|
+
).not.toHaveBeenCalled();
|
|
254
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
255
|
+
expectedEntity,
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("User having offline authenticated active session and server is still not reachable, update the local storage with same values.", async () => {
|
|
260
|
+
expect.assertions(4);
|
|
261
|
+
const userActiveSession = {
|
|
262
|
+
is_authenticated: true,
|
|
263
|
+
is_mfa_required: false,
|
|
264
|
+
is_server_reachable: false,
|
|
265
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
266
|
+
};
|
|
267
|
+
jest
|
|
268
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
269
|
+
.mockImplementation(() => false);
|
|
270
|
+
jest
|
|
271
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
272
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
273
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
274
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
275
|
+
|
|
276
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
277
|
+
|
|
278
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
279
|
+
expect(entity).toEqual(expectedEntity);
|
|
280
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
281
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
282
|
+
expect(
|
|
283
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
284
|
+
).not.toHaveBeenCalled();
|
|
285
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
286
|
+
expectedEntity,
|
|
287
|
+
);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("User having online not authenticated active session and server become not reachable, active session become offline and store it into the local storage.", async () => {
|
|
291
|
+
expect.assertions(4);
|
|
292
|
+
const userActiveSession = {
|
|
293
|
+
is_authenticated: false,
|
|
294
|
+
is_mfa_required: false,
|
|
295
|
+
is_server_reachable: true,
|
|
296
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
297
|
+
};
|
|
298
|
+
jest
|
|
299
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
300
|
+
.mockImplementation(() => false);
|
|
301
|
+
jest
|
|
302
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
303
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
304
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
305
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
306
|
+
|
|
307
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
308
|
+
|
|
309
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
310
|
+
expectedEntity.isServerReachable = false;
|
|
311
|
+
expectedEntity.type = USER_ACTIVE_SESSION_OFFLINE;
|
|
312
|
+
expect(entity).toEqual(expectedEntity);
|
|
313
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
314
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
315
|
+
expect(
|
|
316
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
317
|
+
).not.toHaveBeenCalled();
|
|
318
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
319
|
+
expectedEntity,
|
|
320
|
+
);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("User having online not authenticated active session and server is still reachable, update the local storage with same values.", async () => {
|
|
324
|
+
expect.assertions(4);
|
|
325
|
+
const userActiveSession = {
|
|
326
|
+
is_authenticated: false,
|
|
327
|
+
is_mfa_required: false,
|
|
328
|
+
is_server_reachable: true,
|
|
329
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
330
|
+
};
|
|
331
|
+
jest
|
|
332
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
333
|
+
.mockImplementation(() => true);
|
|
334
|
+
jest
|
|
335
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
336
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
337
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
338
|
+
jest
|
|
339
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated")
|
|
340
|
+
.mockImplementationOnce(() => false);
|
|
341
|
+
|
|
342
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
343
|
+
|
|
344
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
345
|
+
expect(entity).toEqual(expectedEntity);
|
|
346
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
347
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
348
|
+
expect(
|
|
349
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
350
|
+
).toHaveBeenCalledTimes(1);
|
|
351
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
352
|
+
expectedEntity,
|
|
353
|
+
);
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
describe("::resetAuthentication", () => {
|
|
358
|
+
it("resets authentication in place, without touching the session timestamps", async () => {
|
|
359
|
+
expect.assertions(4);
|
|
360
|
+
await setPreviousSessionTimestamps();
|
|
361
|
+
const existing = {
|
|
362
|
+
is_authenticated: true,
|
|
363
|
+
is_mfa_required: true,
|
|
364
|
+
is_server_reachable: false,
|
|
365
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
366
|
+
};
|
|
367
|
+
jest
|
|
368
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
369
|
+
.mockImplementationOnce(() => existing);
|
|
370
|
+
|
|
371
|
+
await findAndUpdateActiveSessionSessionStorageService.resetAuthentication();
|
|
372
|
+
|
|
373
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
374
|
+
expect(storageValue.is_authenticated).toBe(false);
|
|
375
|
+
expect(storageValue.is_mfa_required).toBe(false);
|
|
376
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_OFFLINE);
|
|
377
|
+
expect(await getStoredSessionTimestamps()).toStrictEqual({
|
|
378
|
+
last_seen_online: "2025-08-06T10:05:46+00:00",
|
|
379
|
+
last_logged_in: "2025-08-06T09:00:00+00:00",
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("does nothing when there is no active session", async () => {
|
|
384
|
+
expect.assertions(2);
|
|
385
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
386
|
+
|
|
387
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.resetAuthentication();
|
|
388
|
+
|
|
389
|
+
expect(entity).toBeNull();
|
|
390
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).not.toHaveBeenCalled();
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it("fails safe to an unauthenticated session when the reset errors", async () => {
|
|
394
|
+
expect.assertions(2);
|
|
395
|
+
const corrupt = { is_authenticated: "not-a-boolean", type: USER_ACTIVE_SESSION_ONLINE };
|
|
396
|
+
jest
|
|
397
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
398
|
+
.mockImplementationOnce(() => corrupt);
|
|
399
|
+
jest
|
|
400
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
401
|
+
.mockImplementation(() => false);
|
|
402
|
+
|
|
403
|
+
await findAndUpdateActiveSessionSessionStorageService.resetAuthentication();
|
|
404
|
+
|
|
405
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
406
|
+
expect(storageValue.is_authenticated).toBe(false);
|
|
407
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_OFFLINE);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
describe("::authenticateOnline", () => {
|
|
412
|
+
it("creates an online authenticated session stamped with the login date when none exists", async () => {
|
|
413
|
+
expect.assertions(5);
|
|
414
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find");
|
|
415
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
416
|
+
|
|
417
|
+
await findAndUpdateActiveSessionSessionStorageService.authenticateOnline();
|
|
418
|
+
|
|
419
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
420
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
421
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_ONLINE);
|
|
422
|
+
const sessionTimestamps = await getStoredSessionTimestamps();
|
|
423
|
+
expect(typeof sessionTimestamps.last_logged_in).toBe("string");
|
|
424
|
+
expect(sessionTimestamps.last_seen_online).toBe(sessionTimestamps.last_logged_in);
|
|
425
|
+
expect(findAndUpdateActiveSessionSessionStorageService.findServerStatusService.find).not.toHaveBeenCalled();
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("asserts online authenticated and refreshes the login and last seen online dates", async () => {
|
|
429
|
+
expect.assertions(7);
|
|
430
|
+
await setPreviousSessionTimestamps();
|
|
431
|
+
const existing = {
|
|
432
|
+
is_authenticated: false,
|
|
433
|
+
is_mfa_required: false,
|
|
434
|
+
is_server_reachable: false,
|
|
435
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
436
|
+
};
|
|
437
|
+
jest
|
|
438
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
439
|
+
.mockImplementationOnce(() => existing);
|
|
440
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
441
|
+
|
|
442
|
+
await findAndUpdateActiveSessionSessionStorageService.authenticateOnline();
|
|
443
|
+
|
|
444
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
445
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
446
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_ONLINE);
|
|
447
|
+
// The login date and last seen online date are refreshed to the current date, not kept from the previous session.
|
|
448
|
+
const sessionTimestamps = await getStoredSessionTimestamps();
|
|
449
|
+
expect(sessionTimestamps.last_logged_in).not.toBe("2025-08-06T09:00:00+00:00");
|
|
450
|
+
expect(typeof sessionTimestamps.last_logged_in).toBe("string");
|
|
451
|
+
expect(sessionTimestamps.last_seen_online).not.toBe("2025-08-06T10:05:46+00:00");
|
|
452
|
+
expect(typeof sessionTimestamps.last_seen_online).toBe("string");
|
|
453
|
+
expect(
|
|
454
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
455
|
+
).not.toHaveBeenCalled();
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it("fails safe to a minimal authenticated online session when the write errors, so the user stays signed in", async () => {
|
|
459
|
+
expect.assertions(3);
|
|
460
|
+
const corrupt = {
|
|
461
|
+
is_authenticated: false,
|
|
462
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
463
|
+
is_server_reachable: "not-a-boolean",
|
|
464
|
+
};
|
|
465
|
+
jest
|
|
466
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
467
|
+
.mockImplementationOnce(() => corrupt);
|
|
468
|
+
|
|
469
|
+
await findAndUpdateActiveSessionSessionStorageService.authenticateOnline();
|
|
470
|
+
|
|
471
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
472
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
473
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_ONLINE);
|
|
474
|
+
expect(typeof (await getStoredSessionTimestamps()).last_logged_in).toBe("string");
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
describe("::authenticateOffline", () => {
|
|
479
|
+
it("creates an offline authenticated session without creating session timestamps when none exists", async () => {
|
|
480
|
+
expect.assertions(4);
|
|
481
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find");
|
|
482
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
483
|
+
|
|
484
|
+
await findAndUpdateActiveSessionSessionStorageService.authenticateOffline();
|
|
485
|
+
|
|
486
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
487
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
488
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_OFFLINE);
|
|
489
|
+
// Session timestamps are only created at an online sign-in.
|
|
490
|
+
expect(await getStoredSessionTimestamps()).toBeUndefined();
|
|
491
|
+
expect(findAndUpdateActiveSessionSessionStorageService.findServerStatusService.find).not.toHaveBeenCalled();
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it("asserts offline authenticated and refreshes the login date while preserving the last seen online date", async () => {
|
|
495
|
+
expect.assertions(7);
|
|
496
|
+
await setPreviousSessionTimestamps();
|
|
497
|
+
const existing = {
|
|
498
|
+
is_authenticated: false,
|
|
499
|
+
is_mfa_required: false,
|
|
500
|
+
is_server_reachable: false,
|
|
501
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
502
|
+
};
|
|
503
|
+
jest
|
|
504
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
505
|
+
.mockImplementationOnce(() => existing);
|
|
506
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
507
|
+
|
|
508
|
+
await findAndUpdateActiveSessionSessionStorageService.authenticateOffline();
|
|
509
|
+
|
|
510
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
511
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
512
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_OFFLINE);
|
|
513
|
+
expect(storageValue.is_server_reachable).toBe(false);
|
|
514
|
+
const sessionTimestamps = await getStoredSessionTimestamps();
|
|
515
|
+
expect(sessionTimestamps.last_seen_online).toBe("2025-08-06T10:05:46+00:00");
|
|
516
|
+
expect(sessionTimestamps.last_logged_in).not.toBe("2025-08-06T09:00:00+00:00");
|
|
517
|
+
expect(typeof sessionTimestamps.last_logged_in).toBe("string");
|
|
518
|
+
expect(
|
|
519
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
520
|
+
).not.toHaveBeenCalled();
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it("fails safe to a minimal authenticated offline session when the write errors, so the user stays signed in offline", async () => {
|
|
524
|
+
expect.assertions(3);
|
|
525
|
+
await setPreviousSessionTimestamps();
|
|
526
|
+
const corrupt = {
|
|
527
|
+
is_authenticated: false,
|
|
528
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
529
|
+
is_server_reachable: "not-a-boolean",
|
|
530
|
+
};
|
|
531
|
+
jest
|
|
532
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
533
|
+
.mockImplementationOnce(() => corrupt);
|
|
534
|
+
jest
|
|
535
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
536
|
+
.mockImplementation(() => false);
|
|
537
|
+
|
|
538
|
+
await findAndUpdateActiveSessionSessionStorageService.authenticateOffline();
|
|
539
|
+
|
|
540
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
541
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
542
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_OFFLINE);
|
|
543
|
+
expect(typeof (await getStoredSessionTimestamps()).last_logged_in).toBe("string");
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
it("User having offline not authenticated active session and server become reachable, active session become online and store it into the local storage.", async () => {
|
|
548
|
+
expect.assertions(4);
|
|
549
|
+
const userActiveSession = {
|
|
550
|
+
is_authenticated: false,
|
|
551
|
+
is_mfa_required: false,
|
|
552
|
+
is_server_reachable: false,
|
|
553
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
554
|
+
};
|
|
555
|
+
jest
|
|
556
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
557
|
+
.mockImplementation(() => true);
|
|
558
|
+
jest
|
|
559
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
560
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
561
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
562
|
+
jest
|
|
563
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated")
|
|
564
|
+
.mockImplementationOnce(() => false);
|
|
565
|
+
|
|
566
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
567
|
+
|
|
568
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
569
|
+
expectedEntity.isServerReachable = true;
|
|
570
|
+
expectedEntity.type = USER_ACTIVE_SESSION_ONLINE;
|
|
571
|
+
expect(entity).toEqual(expectedEntity);
|
|
572
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
573
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
574
|
+
expect(
|
|
575
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
576
|
+
).toHaveBeenCalledTimes(1);
|
|
577
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
578
|
+
expectedEntity,
|
|
579
|
+
);
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
it("User having offline not authenticated active session and server is still not reachable, update the local storage with same values.", async () => {
|
|
583
|
+
expect.assertions(4);
|
|
584
|
+
const userActiveSession = {
|
|
585
|
+
is_authenticated: false,
|
|
586
|
+
is_mfa_required: false,
|
|
587
|
+
is_server_reachable: false,
|
|
588
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
589
|
+
};
|
|
590
|
+
jest
|
|
591
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
592
|
+
.mockImplementation(() => false);
|
|
593
|
+
jest
|
|
594
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
595
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
596
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
597
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
598
|
+
|
|
599
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
600
|
+
|
|
601
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
602
|
+
expect(entity).toEqual(expectedEntity);
|
|
603
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
604
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
605
|
+
expect(
|
|
606
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
607
|
+
).not.toHaveBeenCalled();
|
|
608
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
609
|
+
expectedEntity,
|
|
610
|
+
);
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it("If active session is not valid and server is still not reachable, create offline active session and store it into the local storage.", async () => {
|
|
614
|
+
expect.assertions(4);
|
|
615
|
+
const userActiveSession = {
|
|
616
|
+
is_authenticated: "false",
|
|
617
|
+
is_server_reachable: true,
|
|
618
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
619
|
+
};
|
|
620
|
+
jest
|
|
621
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
622
|
+
.mockImplementation(() => false);
|
|
623
|
+
jest
|
|
624
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
625
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
626
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
627
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated");
|
|
628
|
+
|
|
629
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
630
|
+
|
|
631
|
+
const expectedEntity = new UserActiveSessionEntity({
|
|
632
|
+
is_authenticated: false,
|
|
633
|
+
is_mfa_required: false,
|
|
634
|
+
is_server_reachable: false,
|
|
635
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
636
|
+
});
|
|
637
|
+
expect(entity).toEqual(expectedEntity);
|
|
638
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
639
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
640
|
+
expect(
|
|
641
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
642
|
+
).not.toHaveBeenCalled();
|
|
643
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
644
|
+
expectedEntity,
|
|
645
|
+
);
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
it("If active session is not valid and server is reachable, create online active session and store it into the local storage.", async () => {
|
|
649
|
+
expect.assertions(4);
|
|
650
|
+
const userActiveSession = {
|
|
651
|
+
is_authenticated: "false",
|
|
652
|
+
is_server_reachable: true,
|
|
653
|
+
is_mfa_required: false,
|
|
654
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
655
|
+
};
|
|
656
|
+
jest
|
|
657
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
658
|
+
.mockImplementation(() => true);
|
|
659
|
+
jest
|
|
660
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
661
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
662
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
663
|
+
jest
|
|
664
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated")
|
|
665
|
+
.mockImplementationOnce(() => true);
|
|
666
|
+
|
|
667
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
668
|
+
|
|
669
|
+
const expectedEntity = new UserActiveSessionEntity({
|
|
670
|
+
is_authenticated: true,
|
|
671
|
+
is_mfa_required: false,
|
|
672
|
+
is_server_reachable: true,
|
|
673
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
674
|
+
});
|
|
675
|
+
expect(entity).toEqual(expectedEntity);
|
|
676
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
677
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
678
|
+
expect(
|
|
679
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
680
|
+
).toHaveBeenCalledTimes(1);
|
|
681
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
682
|
+
expectedEntity,
|
|
683
|
+
);
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
it("User having online authenticated active session, server is reachable with an error when isAuthenticated is fetched, do not update is_server_reachable and store it into the local storage.", async () => {
|
|
687
|
+
expect.assertions(4);
|
|
688
|
+
const userActiveSession = {
|
|
689
|
+
is_authenticated: true,
|
|
690
|
+
is_mfa_required: false,
|
|
691
|
+
is_server_reachable: true,
|
|
692
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
693
|
+
};
|
|
694
|
+
jest
|
|
695
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.findServerStatusService, "find")
|
|
696
|
+
.mockImplementation(() => true);
|
|
697
|
+
jest
|
|
698
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "get")
|
|
699
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
700
|
+
jest.spyOn(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage, "set");
|
|
701
|
+
jest
|
|
702
|
+
.spyOn(findAndUpdateActiveSessionSessionStorageService.authenticationStatusService, "isAuthenticated")
|
|
703
|
+
.mockImplementationOnce(() => {
|
|
704
|
+
throw new Error();
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
const entity = await findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
708
|
+
|
|
709
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
710
|
+
expect(entity).toEqual(expectedEntity);
|
|
711
|
+
const storageValue = await findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.get();
|
|
712
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
713
|
+
expect(
|
|
714
|
+
findAndUpdateActiveSessionSessionStorageService.authenticationStatusService.isAuthenticated,
|
|
715
|
+
).toHaveBeenCalledTimes(1);
|
|
716
|
+
expect(findAndUpdateActiveSessionSessionStorageService.activeSessionSessionStorage.set).toHaveBeenCalledWith(
|
|
717
|
+
expectedEntity,
|
|
718
|
+
);
|
|
719
|
+
});
|
|
720
|
+
});
|