passbolt-browser-extension 5.14.3 → 5.16.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/.devcontainer/Dockerfile +1 -1
- package/.devcontainer/devcontainer.json +1 -1
- package/.github/workflows/codeql-analysis.yml +1 -1
- package/.github/workflows/release_candidate.yaml +1 -1
- package/CHANGELOG.md +205 -1
- package/RELEASE_NOTES.md +6 -7
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/SafariWebExtensionHandler.swift +1 -0
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/WriteClipboardController.swift +65 -0
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/SafariWebExtensionHandlerTests.swift +2 -1
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/WriteClipboardControllerTests.swift +34 -0
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager.xcodeproj/project.pbxproj +8 -8
- package/package.json +7 -7
- package/src/all/_locales/ro/messages.json +1 -1
- package/src/all/background_page/controller/InformMenuController/InformMenuController.js +21 -2
- package/src/all/background_page/controller/InformMenuController/InformMenuController.test.js +48 -5
- package/src/all/background_page/controller/account/updatePrivateKeyController.js +1 -1
- package/src/all/background_page/controller/accountRecovery/accountRecoveryLoginController.js +3 -1
- package/src/all/background_page/controller/applicationOverlaid/IsApplicationOverlaidController.js +1 -1
- package/src/all/background_page/controller/auth/authLocalLogoutController.js +65 -0
- package/src/all/background_page/controller/auth/authLocalLogoutController.test.js +78 -0
- package/src/all/background_page/controller/auth/authLoginController.js +7 -1
- package/src/all/background_page/controller/auth/authLoginOfflineController.js +69 -0
- package/src/all/background_page/controller/auth/authLoginOfflineController.test.js +95 -0
- package/src/all/background_page/controller/auth/authLogoutController.js +3 -2
- package/src/all/background_page/controller/auth/authLogoutController.test.js +6 -2
- package/src/all/background_page/controller/auth/authOfflineLogoutController.js +62 -0
- package/src/all/background_page/controller/auth/authOfflineLogoutController.test.js +73 -0
- package/src/all/background_page/controller/auth/findAndUpdateActiveSessionLocalStorageController.js +57 -0
- package/src/all/background_page/controller/auth/findAndUpdateActiveSessionLocalStorageController.test.js +192 -0
- package/src/all/background_page/controller/auth/{authCheckStatusController.js → getOrFindActiveSessionController.js} +12 -14
- package/src/all/background_page/controller/auth/getOrFindActiveSessionController.test.js +135 -0
- package/src/all/background_page/controller/auth/{authIsMfaRequiredController.js → isMfaRequiredController.js} +11 -8
- package/src/all/background_page/controller/auth/{authIsMfaRequiredController.test.js → isMfaRequiredController.test.js} +26 -15
- package/src/all/background_page/controller/autofill/AutofillController.js +29 -13
- package/src/all/background_page/controller/autofill/AutofillController.test.js +116 -0
- package/src/all/background_page/controller/export/exportResourcesFileController.test.js +6 -0
- package/src/all/background_page/controller/extension/onExtensionInstalledController.js +11 -11
- package/src/all/background_page/controller/extension/onExtensionInstalledController.test.js +5 -4
- package/src/all/background_page/controller/favorite/favoriteResourceController.js +1 -1
- package/src/all/background_page/controller/favorite/unfavoriteResourceController.js +1 -1
- package/src/all/background_page/controller/folder/deleteFolderController.js +55 -0
- package/src/all/background_page/controller/folder/deleteFolderController.test.js +81 -0
- package/src/all/background_page/controller/folder/findFolderDetailsController.js +1 -1
- package/src/all/background_page/controller/folder/findFolderDetailsController.test.js +2 -2
- package/src/all/background_page/controller/folder/updateFolderController.js +55 -0
- package/src/all/background_page/controller/folder/updateFolderController.test.js +69 -0
- package/src/all/background_page/controller/group/deleteDryRunGroupController.js +54 -0
- package/src/all/background_page/controller/group/deleteDryRunGroupController.test.js +49 -0
- package/src/all/background_page/controller/group/deleteGroupController.js +56 -0
- package/src/all/background_page/controller/group/deleteGroupController.test.js +75 -0
- package/src/all/background_page/controller/group/findGroupsByIdsForShareController.js +1 -1
- package/src/all/background_page/controller/import/importResourcesFileController.test.js +8 -2
- package/src/all/background_page/controller/informCallToActionController/informCallToActionController.js +31 -10
- package/src/all/background_page/controller/informCallToActionController/informCallToActionController.test.js +72 -35
- package/src/all/background_page/controller/metadata/shareMetadataKeyPrivateController.js +1 -1
- package/src/all/background_page/controller/move/moveFolderController.js +1 -1
- package/src/all/background_page/controller/move/moveResourcesController.js +1 -1
- package/src/all/background_page/controller/offline/deleteOfflineSettingsController.js +57 -0
- package/src/all/background_page/controller/offline/deleteOfflineSettingsController.test.js +61 -0
- package/src/all/background_page/controller/offline/findOfflineSettingsController.js +57 -0
- package/src/all/background_page/controller/offline/findOfflineSettingsController.test.js +64 -0
- package/src/all/background_page/controller/offline/getOrFindOfflineSettingsController.js +54 -0
- package/src/all/background_page/controller/offline/getOrFindOfflineSettingsController.test.js +125 -0
- package/src/all/background_page/controller/offline/saveOfflineSettingsController.js +57 -0
- package/src/all/background_page/controller/offline/saveOfflineSettingsController.test.js +63 -0
- package/src/all/background_page/controller/offline/unmarkItemOfflineAvailableController.js +57 -0
- package/src/all/background_page/controller/offline/unmarkItemOfflineAvailableController.test.js +59 -0
- package/src/all/background_page/controller/offlineResourceController/markResourceOfflineAvailableController.js +57 -0
- package/src/all/background_page/controller/offlineResourceController/markResourceOfflineAvailableController.test.js +62 -0
- package/src/all/background_page/controller/passwordExpiry/savePasswordExpirySettingsController.js +1 -1
- package/src/all/background_page/controller/permission/FindAcoPermissionsForDisplayController.js +2 -1
- package/src/all/background_page/controller/permission/FindAcoPermissionsForDisplayController.test.js +2 -2
- package/src/all/background_page/controller/permission/findPermissionsByIdsForShareController.js +1 -1
- package/src/all/background_page/controller/recover/generateRecoverAccountRecoveryRequestKeyController.test.js +14 -0
- package/src/all/background_page/controller/resource/findAllIdsByIsSharedWithGroupController.js +1 -1
- package/src/all/background_page/controller/resource/findAllIdsByIsSharedWithGroupController.test.js +6 -0
- package/src/all/background_page/controller/resource/findResourceDetailsController.js +1 -1
- package/src/all/background_page/controller/resource/updateResourceLocalStorageByFolderParentIdController.js +1 -1
- package/src/all/background_page/controller/resourceLocalStorage/findAndUpdateResourcesLocalStorageFromOPFSController.js +74 -0
- package/src/all/background_page/controller/resourceLocalStorage/findAndUpdateResourcesLocalStorageFromOPFSController.test.js +227 -0
- package/src/all/background_page/controller/resourceLocalStorage/resourceUpdateLocalStorageController.test.js +8 -0
- package/src/all/background_page/controller/rotateMetadata/rotateMetadataKeyController.js +1 -1
- package/src/all/background_page/controller/scimSettings/disableScimSettingsController.js +1 -1
- package/src/all/background_page/controller/scimSettings/updateScimSettingsController.js +1 -1
- package/src/all/background_page/controller/secret/findSecretByResourceIdController.js +1 -1
- package/src/all/background_page/controller/secret/findSecretByResourceIdController.test.js +7 -0
- package/src/all/background_page/controller/secret/findSecretByResourceIdFromOPFSController.js +59 -0
- package/src/all/background_page/controller/secret/findSecretByResourceIdFromOPFSController.test.js +123 -0
- package/src/all/background_page/controller/secretRevision/findResourceSecretRevisionsForDisplayController.js +1 -1
- package/src/all/background_page/controller/setup/signInSetupController.js +1 -1
- package/src/all/background_page/controller/share/findFoldersForShareController.js +1 -1
- package/src/all/background_page/controller/share/findFoldersForShareController.test.js +2 -2
- package/src/all/background_page/controller/share/shareOneFolderController.js +2 -1
- package/src/all/background_page/controller/share/shareResourcesController.js +2 -1
- package/src/all/background_page/controller/siteSettings/findAndUpdateSiteSettingsLocalStorageController.js +58 -0
- package/src/all/background_page/controller/siteSettings/findAndUpdateSiteSettingsLocalStorageController.test.js +134 -0
- package/src/all/background_page/controller/siteSettings/getOrFindSiteSettingsController.js +6 -9
- package/src/all/background_page/controller/siteSettings/getOrFindSiteSettingsController.test.js +50 -27
- package/src/all/background_page/controller/sso/activateSsoSettingsController.js +1 -1
- package/src/all/background_page/controller/sso/deleteSsoSettingsController.js +1 -1
- package/src/all/background_page/controller/sso/ssoAuthenticationController.js +2 -1
- package/src/all/background_page/controller/sso/testSsoAuthenticationController.js +1 -1
- package/src/all/background_page/controller/subscription/createSubscriptionKeyController.js +9 -1
- package/src/all/background_page/controller/subscription/createSubscriptionKeyController.test.js +13 -5
- package/src/all/background_page/controller/subscription/deleteSubscriptionKeyController.js +9 -1
- package/src/all/background_page/controller/subscription/deleteSubscriptionKeyController.test.js +13 -5
- package/src/all/background_page/controller/tag/addTagsToResourcesController.js +4 -3
- package/src/all/background_page/controller/tag/addTagsToResourcesController.test.js +11 -8
- package/src/all/background_page/controller/tag/deleteTagController.js +4 -3
- package/src/all/background_page/controller/tag/deleteTagController.test.js +6 -3
- package/src/all/background_page/controller/tag/tagController.js +1 -1
- package/src/all/background_page/controller/tag/updateResourceTagsController.js +4 -3
- package/src/all/background_page/controller/tag/updateResourceTagsController.test.js +7 -4
- package/src/all/background_page/controller/tag/updateTagController.js +3 -2
- package/src/all/background_page/controller/tag/updateTagController.test.js +6 -3
- package/src/all/background_page/controller/user/getOrFindLoggedInUserController.test.js +8 -0
- package/src/all/background_page/controller/user/getOrFindUsersController.js +1 -1
- package/src/all/background_page/event/accountRecoveryEvents.js +10 -4
- package/src/all/background_page/event/appEvents.js +86 -6
- package/src/all/background_page/event/authEvents.js +27 -10
- package/src/all/background_page/event/folderEvents.js +6 -20
- package/src/all/background_page/event/groupEvents.js +8 -24
- package/src/all/background_page/event/informCallToActionEvents.js +5 -5
- package/src/all/background_page/event/informMenuEvents.js +45 -0
- package/src/all/background_page/event/quickAccessEvents.js +79 -0
- package/src/all/background_page/event/recoverEvents.js +10 -4
- package/src/all/background_page/event/setupEvents.js +10 -4
- package/src/all/background_page/event/siteSettingsEvents.js +22 -5
- package/src/all/background_page/model/actionLog/findActionLogService.js +2 -1
- package/src/all/background_page/model/auth/authModel.js +9 -1
- package/src/all/background_page/model/auth/authModel.test.js +11 -3
- package/src/all/background_page/model/comment/commentService.js +2 -1
- package/src/all/background_page/model/entity/mfa/mfaPolicyEntity.js +2 -19
- package/src/all/background_page/model/entity/mfa/mfaPolicyEntity.test.js +48 -0
- package/src/all/background_page/model/entity/permission/change/permissionChangeEntity.js +8 -56
- package/src/all/background_page/model/entity/permission/change/permissionChangeEntity.test.data.js +36 -0
- package/src/all/background_page/model/entity/permission/change/permissionChangeEntity.test.js +264 -0
- package/src/all/background_page/model/entity/permission/change/permissionChangesCollection.js +0 -15
- package/src/all/background_page/model/entity/resource/resourceEntity.js +47 -0
- package/src/all/background_page/model/entity/resource/resourceEntity.test.js +86 -12
- package/src/all/background_page/model/entity/resource/resourcesCollection.js +22 -1
- package/src/all/background_page/model/entity/resource/resourcesCollection.test.js +51 -0
- package/src/all/background_page/model/entity/totp/externalTotpEntity.js +15 -0
- package/src/all/background_page/model/folder/folderModel.js +3 -35
- package/src/all/background_page/model/group/groupModel.js +0 -60
- package/src/all/background_page/model/import/resources/csvRowParser/csvBitWardenRowParser.js +9 -6
- package/src/all/background_page/model/import/resources/csvRowParser/csvBitWardenRowParser.test.js +47 -0
- package/src/all/background_page/model/locale/localeModel.js +4 -4
- package/src/all/background_page/model/passwordExpiry/passwordExpirySettingsModel.js +4 -3
- package/src/all/background_page/model/sso/ssoDryRunModel.js +1 -1
- package/src/all/background_page/model/sso/ssoKitServerPartModel.js +1 -1
- package/src/all/background_page/model/sso/ssoLoginModel.js +1 -1
- package/src/all/background_page/model/user/userModel.js +1 -1
- package/src/all/background_page/pagemod/appBootstrapPagemod.js +7 -4
- package/src/all/background_page/pagemod/appBootstrapPagemod.test.js +50 -7
- package/src/all/background_page/pagemod/appPagemod.js +4 -4
- package/src/all/background_page/pagemod/appPagemod.test.js +9 -8
- package/src/all/background_page/pagemod/authPagemod.test.js +2 -0
- package/src/all/background_page/pagemod/pagemodManager.test.js +5 -5
- package/src/all/background_page/pagemod/recoverPagemod.js +2 -2
- package/src/all/background_page/pagemod/recoverPagemod.test.js +2 -2
- package/src/all/background_page/pagemod/setupPagemod.js +2 -2
- package/src/all/background_page/pagemod/setupPagemod.test.js +2 -2
- package/src/all/background_page/service/account/updateSsoCredentialsService.js +1 -1
- package/src/all/background_page/service/accountRecovery/buildApprovedAccountRecoveryUserSettingEntityService.js +2 -2
- package/src/all/background_page/service/activeSession/findAndUpdateActiveSessionLocalStorageService.js +288 -0
- package/src/all/background_page/service/activeSession/findAndUpdateActiveSessionLocalStorageService.test.js +776 -0
- package/src/all/background_page/service/activeSession/getOrFindActiveSessionService.js +59 -0
- package/src/all/background_page/service/activeSession/getOrFindActiveSessionService.test.js +122 -0
- package/src/all/background_page/service/alarm/globalAlarmService.js +2 -0
- package/src/all/background_page/service/api/actionLog/actionLogApiService.js +2 -1
- package/src/all/background_page/service/api/folder/{folderService.js → folderApiService.js} +14 -8
- package/src/all/background_page/service/api/folder/folderApiService.test.js +144 -0
- package/src/all/background_page/service/api/group/groupApiService.test.js +79 -0
- package/src/all/background_page/service/api/metadata/metadataKeysApiService.js +2 -1
- package/src/all/background_page/service/api/move/moveService.js +1 -1
- package/src/all/background_page/service/api/offline/offlineSettingsApiService.js +82 -0
- package/src/all/background_page/service/api/offline/offlineSettingsApiService.test.js +152 -0
- package/src/all/background_page/service/api/offline/unmarkOfflineItemApiService.js +55 -0
- package/src/all/background_page/service/api/offline/unmarkOfflineItemApiService.test.js +77 -0
- package/src/all/background_page/service/api/offlineResource/markOfflineResourceApiService.js +57 -0
- package/src/all/background_page/service/api/offlineResource/markOfflineResourceApiService.test.js +82 -0
- package/src/all/background_page/service/api/resource/resourceService.js +1 -0
- package/src/all/background_page/service/api/resourceType/resourceTypeService.js +1 -1
- package/src/all/background_page/service/api/secretRevision/resourceSecretRevisionApiService.js +2 -1
- package/src/all/background_page/service/api/sessionKey/sessionKeysBundlesApiService.js +2 -1
- package/src/all/background_page/service/api/sso/ssoKitServerPartService.js +1 -1
- package/src/all/background_page/service/api/sso/ssoSettingsService.js +1 -1
- package/src/all/background_page/service/api/status/serverStatusApiService.js +53 -0
- package/src/all/background_page/service/api/status/serverStatusApiService.test.js +63 -0
- package/src/all/background_page/service/api/userKeyPolicies/userKeyPoliciesSettingsApiService.js +1 -1
- package/src/all/background_page/service/auth/offlineSessionExpiryAlarmService.js +112 -0
- package/src/all/background_page/service/auth/offlineSessionExpiryAlarmService.test.js +188 -0
- package/src/all/background_page/service/auth/postLoginOfflineService.js +56 -0
- package/src/all/background_page/service/auth/postLoginOfflineService.test.js +63 -0
- package/src/all/background_page/service/auth/postLoginService.js +10 -1
- package/src/all/background_page/service/auth/postLoginService.test.js +17 -4
- package/src/all/background_page/service/auth/sessionCookieFlushService.js +51 -0
- package/src/all/background_page/service/auth/sessionCookieFlushService.test.js +50 -0
- package/src/all/background_page/service/auth/startLoopAuthSessionCheckService.js +8 -4
- package/src/all/background_page/service/auth/startLoopAuthSessionCheckService.test.js +28 -8
- package/src/all/background_page/service/authenticationStatusService.js +4 -1
- package/src/all/background_page/service/authenticationStatusService.test.js +10 -0
- package/src/all/background_page/service/clipboard/clipboardProviderService.js +2 -2
- package/src/all/background_page/service/crypto/cryptoRandomValuesService.js +19 -0
- package/src/all/background_page/service/crypto/cryptoRandomValuesService.test.js +22 -0
- package/src/all/background_page/service/crypto/getGpgKeyCreationDateService.js +1 -1
- package/src/all/background_page/service/extension/onStartUpService.js +8 -0
- package/src/all/background_page/service/extension/onStartUpService.test.js +8 -1
- package/src/all/background_page/service/favorite/favoriteResourceService.js +9 -1
- package/src/all/background_page/service/favorite/favoriteResourceService.test.js +6 -0
- package/src/all/background_page/service/folder/deleteFolderService.js +70 -0
- package/src/all/background_page/service/folder/deleteFolderService.test.js +119 -0
- package/src/all/background_page/service/folder/findAndUpdateFoldersLocalStorageService.test.js +10 -10
- package/src/all/background_page/service/folder/findFoldersService.js +7 -6
- package/src/all/background_page/service/folder/findFoldersService.test.js +7 -7
- package/src/all/background_page/service/folder/getOrFindFoldersService.js +1 -1
- package/src/all/background_page/service/folder/getOrFindFoldersService.test.js +9 -9
- package/src/all/background_page/service/folder/updateFolderService.js +47 -0
- package/src/all/background_page/service/folder/updateFolderService.test.js +77 -0
- package/src/all/background_page/service/group/deleteGroupService.js +97 -0
- package/src/all/background_page/service/group/deleteGroupService.test.js +159 -0
- package/src/all/background_page/service/group/findAndUpdateGroupsLocalStorageService.js +1 -1
- package/src/all/background_page/service/group/findGroupsService.js +2 -1
- package/src/all/background_page/service/localStorage/localStorageService.js +90 -21
- package/src/all/background_page/service/localStorage/localStorageService.test.js +145 -39
- package/src/all/background_page/service/local_storage/abstractLocalStorage.js +19 -0
- package/src/all/background_page/service/local_storage/abstractLocalStorage.test.js +36 -0
- package/src/all/background_page/service/local_storage/activeSessionLocalStorage.js +16 -4
- package/src/all/background_page/service/local_storage/activeSessionLocalStorage.test.js +12 -12
- package/src/all/background_page/service/local_storage/folderLocalStorage.js +2 -1
- package/src/all/background_page/service/local_storage/offlineSettingsLocalStorage.js +37 -0
- package/src/all/background_page/service/local_storage/offlineSettingsLocalStorage.test.js +112 -0
- package/src/all/background_page/service/local_storage/resourceLocalStorage.js +14 -2
- package/src/all/background_page/service/local_storage/resourceLocalStorage.test.js +34 -0
- package/src/all/background_page/service/metadata/deleteMetadataKeyService.js +1 -1
- package/src/all/background_page/service/metadata/expireMetadataKeyService.js +1 -1
- package/src/all/background_page/service/metadata/findAndUpdateMetadataKeysSessionStorageFromOPFSService.js +65 -0
- package/src/all/background_page/service/metadata/findAndUpdateMetadataKeysSessionStorageFromOPFSService.test.js +192 -0
- package/src/all/background_page/service/metadata/findAndUpdateMetadataKeysSessionStorageService.js +12 -0
- package/src/all/background_page/service/metadata/findAndUpdateMetadataKeysSessionStorageService.test.js +64 -0
- package/src/all/background_page/service/metadata/findAndUpdateMetadataSettingsLocalStorageService.js +1 -1
- package/src/all/background_page/service/metadata/getOrFindMetadataKeysService.test.js +3 -0
- package/src/all/background_page/service/metadata/rotateMetadata/rotateMetadataKeyService.js +2 -1
- package/src/all/background_page/service/metadata/shareMetadataKeyPrivateService.js +2 -1
- package/src/all/background_page/service/metadata/verifyOrTrustMetadataKeyService.js +1 -1
- package/src/all/background_page/service/metadata/verifyOrTrustMetadataKeyService.test.js +2 -0
- package/src/all/background_page/service/move/moveOneFolderService.js +2 -1
- package/src/all/background_page/service/move/moveResourcesService.js +2 -1
- package/src/all/background_page/service/offline/canUseOfflineStorageService.js +144 -0
- package/src/all/background_page/service/offline/canUseOfflineStorageService.test.js +253 -0
- package/src/all/background_page/service/offline/disableOfflineSettingsService.js +43 -0
- package/src/all/background_page/service/offline/disableOfflineSettingsService.test.js +84 -0
- package/src/all/background_page/service/offline/findAndUpdateOfflineSettingsLocalStorageService.js +76 -0
- package/src/all/background_page/service/offline/findAndUpdateOfflineSettingsLocalStorageService.test.js +136 -0
- package/src/all/background_page/service/offline/findOfflineSettingsService.js +40 -0
- package/src/all/background_page/service/offline/findOfflineSettingsService.test.js +76 -0
- package/src/all/background_page/service/offline/getOrFindOfflineSettingsService.js +58 -0
- package/src/all/background_page/service/offline/getOrFindOfflineSettingsService.test.js +209 -0
- package/src/all/background_page/service/offline/offlineRetentionDataFlushService.js +76 -0
- package/src/all/background_page/service/offline/offlineRetentionDataFlushService.test.js +161 -0
- package/src/all/background_page/service/offline/saveOfflineSettingsService.js +45 -0
- package/src/all/background_page/service/offline/saveOfflineSettingsService.test.js +82 -0
- package/src/all/background_page/service/offline/unmarkOfflineItemService.js +56 -0
- package/src/all/background_page/service/offline/unmarkOfflineItemService.test.js +114 -0
- package/src/all/background_page/service/offlineResource/markOfflineResourceService.js +96 -0
- package/src/all/background_page/service/offlineResource/markOfflineResourceService.test.js +185 -0
- package/src/all/background_page/service/opfsStorage/metadataKeyOPFSStorage.js +259 -0
- package/src/all/background_page/service/opfsStorage/metadataKeyOPFSStorage.test.js +343 -0
- package/src/all/background_page/service/opfsStorage/offlineResourcesOPFSStorage.js +454 -0
- package/src/all/background_page/service/opfsStorage/offlineResourcesOPFSStorage.test.js +1007 -0
- package/src/all/background_page/service/opfsStorage/offlineSecretsOPFSStorage.js +266 -0
- package/src/all/background_page/service/opfsStorage/offlineSecretsOPFSStorage.test.js +536 -0
- package/src/all/background_page/service/permission/findPermissionsService.js +1 -1
- package/src/all/background_page/service/rbac/getOrFindRbacService.js +14 -3
- package/src/all/background_page/service/resource/create/resourceCreateService.test.js +12 -1
- package/src/all/background_page/service/resource/delete/deleteResourceService.js +8 -1
- package/src/all/background_page/service/resource/delete/deleteResourceService.test.js +3 -0
- package/src/all/background_page/service/resource/export/exportResourcesService.test.js +6 -0
- package/src/all/background_page/service/resource/findAndUpdateResourcesLocalStorageFromOPFSService.js +90 -0
- package/src/all/background_page/service/resource/findAndUpdateResourcesLocalStorageFromOPFSService.test.js +214 -0
- package/src/all/background_page/service/resource/findAndUpdateResourcesLocalStorageService.js +124 -8
- package/src/all/background_page/service/resource/findAndUpdateResourcesLocalStorageService.test.js +415 -0
- package/src/all/background_page/service/resource/findResourcesService.js +36 -10
- package/src/all/background_page/service/resource/findResourcesService.test.js +104 -57
- package/src/all/background_page/service/resource/getOrFindOfflineResourcesService.js +89 -0
- package/src/all/background_page/service/resource/getOrFindOfflineResourcesService.test.js +325 -0
- package/src/all/background_page/service/resource/getOrFindResourcesService.js +6 -4
- package/src/all/background_page/service/resource/getOrFindResourcesService.test.js +42 -0
- package/src/all/background_page/service/resource/import/ImportResourcesService.js +2 -2
- package/src/all/background_page/service/resource/import/ImportResourcesService.test.js +8 -2
- package/src/all/background_page/service/resource/update/resourceUpdateLocalStorageService.js +1 -1
- package/src/all/background_page/service/resource/update/resourceUpdateService.js +74 -30
- package/src/all/background_page/service/resource/update/resourceUpdateService.test.js +256 -10
- package/src/all/background_page/service/resourceType/getOrFindResourceTypesService.js +14 -3
- package/src/all/background_page/service/resourceType/getOrFindResourceTypesService.test.js +75 -0
- package/src/all/background_page/service/resourceType/getSecretSchemaResourceTypeService.js +1 -1
- package/src/all/background_page/service/resourceType/updateResourceTypesService.js +2 -1
- package/src/all/background_page/service/scimSettings/disableScimSettingsService.js +1 -1
- package/src/all/background_page/service/scimSettings/updateScimSettingsService.js +2 -1
- package/src/all/background_page/service/secret/findSecretOPFSService.js +71 -0
- package/src/all/background_page/service/secret/findSecretOPFSService.test.js +150 -0
- package/src/all/background_page/service/secret/findSecretService.js +1 -1
- package/src/all/background_page/service/secretRevisions/findAndDecryptSecretRevisionsService.js +2 -1
- package/src/all/background_page/service/secretRevisions/findSecretRevisionsService.js +2 -1
- package/src/all/background_page/service/sessionKey/getOrFindSessionKeysService.js +2 -1
- package/src/all/background_page/service/share/shareFoldersService.js +2 -1
- package/src/all/background_page/service/share/shareResourceService.js +2 -1
- package/src/all/background_page/service/siteSettings/findAndUpdateSiteSettingsLocalStorageService.js +6 -6
- package/src/all/background_page/service/siteSettings/findAndUpdateSiteSettingsLocalStorageService.test.js +51 -11
- package/src/all/background_page/service/siteSettings/getOrFindSiteSettingsService.js +64 -39
- package/src/all/background_page/service/siteSettings/getOrFindSiteSettingsService.test.js +158 -65
- package/src/all/background_page/service/sso/popupHandlerService.js +1 -1
- package/src/all/background_page/service/status/findServerStatusService.js +41 -0
- package/src/all/background_page/service/status/findServerStatusService.test.js +48 -0
- package/src/all/background_page/service/tag/deleteTagService.js +8 -2
- package/src/all/background_page/service/tag/deleteTagService.test.js +17 -1
- package/src/all/background_page/service/tag/updateResourceTagsService.js +14 -3
- package/src/all/background_page/service/tag/updateResourceTagsService.test.js +56 -1
- package/src/all/background_page/service/tag/updateTagService.js +9 -2
- package/src/all/background_page/service/tag/updateTagService.test.js +17 -1
- package/src/all/background_page/service/toolbar/toolbarService.js +20 -35
- package/src/all/background_page/service/toolbar/toolbarService.test.js +22 -16
- package/src/all/background_page/service/user/deleteUserService.js +2 -1
- package/src/all/background_page/service/user/findAndUpdateUsersLocalStorageService.js +1 -1
- package/src/all/background_page/service/user/getOrFindMeService.js +16 -5
- package/src/all/background_page/service/user/getOrFindMeService.test.js +69 -0
- package/src/all/background_page/service/user/getOrFindUsersService.js +1 -1
- package/src/all/background_page/service/userKeyPolicies/findUserKeyPoliciesSettingsService.js +2 -2
- package/src/all/background_page/utils/assertions.js +0 -29
- package/src/all/background_page/utils/assertions.test.js +2 -52
- package/src/all/locales/cs-CZ/common.json +2 -0
- package/src/all/locales/de-DE/common.json +2 -0
- package/src/all/locales/en-UK/common.json +2 -0
- package/src/all/locales/es-ES/common.json +2 -0
- package/src/all/locales/fr-FR/common.json +2 -0
- package/src/all/locales/it-IT/common.json +2 -0
- package/src/all/locales/ja-JP/common.json +2 -0
- package/src/all/locales/ko-KR/common.json +2 -0
- package/src/all/locales/lt-LT/common.json +2 -0
- package/src/all/locales/nl-NL/common.json +2 -0
- package/src/all/locales/pl-PL/common.json +2 -0
- package/src/all/locales/pt-BR/common.json +2 -0
- package/src/all/locales/ro-RO/common.json +2 -0
- package/src/all/locales/ru-RU/common.json +2 -0
- package/src/all/locales/sl-SI/common.json +2 -0
- package/src/all/locales/sv-SE/common.json +2 -0
- package/src/all/locales/uk-UA/common.json +2 -0
- package/src/chrome/manifest.json +1 -1
- package/src/chrome-mv3/manifest.json +1 -1
- package/src/chrome-mv3/offscreens/service/offscreen/handleOffscreenRequestService.js +1 -1
- package/src/chrome-mv3/serviceWorker/service/offscreen/handleOffscreenResponseService.js +1 -1
- package/src/firefox/manifest.json +1 -1
- package/src/safari/background_page/service/clipboard/clipboardService.js +32 -0
- package/src/safari/background_page/service/clipboard/clipboardService.test.js +58 -0
- package/src/{all/background_page/controller/auth/authCheckStatus.test.data.js → safari/common/polyfill/clipboardPolyfill.js} +5 -14
- package/src/safari/manifest.json +1 -1
- package/test/jest.setup.js +12 -1
- package/test/mocks/mockDirectoryHandle.js +145 -0
- package/test/mocks/mockWebExtensionPolyfill.js +1 -0
- package/webpack/passboltEnvPlugin.js +9 -10
- package/webpack.safari-background-page.config.js +1 -0
- package/src/all/background_page/controller/auth/authCheckStatusController.test.js +0 -126
- package/src/all/background_page/model/entity/siteSettings/siteSettingsEntity.js +0 -243
- package/src/all/background_page/model/entity/siteSettings/siteSettingsEntity.test.data.js +0 -279
- package/src/all/background_page/model/entity/siteSettings/siteSettingsEntity.test.js +0 -109
- package/src/all/background_page/service/auth/checkAuthStatusService.js +0 -65
- package/src/all/background_page/service/auth/checkAuthStatusService.test.js +0 -143
|
@@ -0,0 +1,776 @@
|
|
|
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 FindAndUpdateActiveSessionLocalStorageService from "./findAndUpdateActiveSessionLocalStorageService";
|
|
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
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
jest.clearAllMocks();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("FindAndUpdateActiveSessionLocalStorageService", () => {
|
|
30
|
+
let findAndUpdateActiveSessionLocalStorageService, account, apiClientOptions;
|
|
31
|
+
|
|
32
|
+
beforeEach(async () => {
|
|
33
|
+
account = new AccountEntity(defaultAccountDto());
|
|
34
|
+
apiClientOptions = defaultApiClientOptions();
|
|
35
|
+
findAndUpdateActiveSessionLocalStorageService = new FindAndUpdateActiveSessionLocalStorageService(
|
|
36
|
+
account,
|
|
37
|
+
apiClientOptions,
|
|
38
|
+
);
|
|
39
|
+
// flush account related storage before each.
|
|
40
|
+
await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.flush();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("::findAndUpdateAuthenticationStatus", () => {
|
|
44
|
+
it("If no active session create a new one and store it into the local storage.", async () => {
|
|
45
|
+
expect.assertions(3);
|
|
46
|
+
const userActiveSession = {
|
|
47
|
+
is_authenticated: false,
|
|
48
|
+
is_mfa_required: false,
|
|
49
|
+
is_server_reachable: true,
|
|
50
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
51
|
+
};
|
|
52
|
+
jest
|
|
53
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
54
|
+
.mockImplementation(() => true);
|
|
55
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
56
|
+
|
|
57
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
58
|
+
|
|
59
|
+
expect(entity.toDto()).toEqual(userActiveSession);
|
|
60
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
61
|
+
expect(storageValue).toEqual(userActiveSession);
|
|
62
|
+
expect(
|
|
63
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
64
|
+
).not.toHaveBeenCalled();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
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 () => {
|
|
68
|
+
expect.assertions(4);
|
|
69
|
+
const userActiveSession = {
|
|
70
|
+
is_authenticated: true,
|
|
71
|
+
is_mfa_required: false,
|
|
72
|
+
is_server_reachable: true,
|
|
73
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
74
|
+
};
|
|
75
|
+
jest
|
|
76
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
77
|
+
.mockImplementation(() => false);
|
|
78
|
+
jest
|
|
79
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
80
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
81
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
82
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
83
|
+
|
|
84
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
85
|
+
|
|
86
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
87
|
+
expectedEntity.isServerReachable = false;
|
|
88
|
+
expect(entity).toEqual(expectedEntity);
|
|
89
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
90
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
91
|
+
expect(
|
|
92
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
93
|
+
).not.toHaveBeenCalled();
|
|
94
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
95
|
+
expectedEntity,
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("User having online authenticated active session, update is mfa authenticated to true and store it into the local storage.", async () => {
|
|
100
|
+
expect.assertions(4);
|
|
101
|
+
const userActiveSession = {
|
|
102
|
+
is_authenticated: true,
|
|
103
|
+
is_mfa_required: false,
|
|
104
|
+
is_server_reachable: true,
|
|
105
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
106
|
+
};
|
|
107
|
+
jest
|
|
108
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
109
|
+
.mockImplementation(() => true);
|
|
110
|
+
jest
|
|
111
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
112
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
113
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
114
|
+
jest
|
|
115
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated")
|
|
116
|
+
.mockImplementationOnce(() => true);
|
|
117
|
+
|
|
118
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
119
|
+
|
|
120
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
121
|
+
expectedEntity.isMfaRequired = false;
|
|
122
|
+
expect(entity).toEqual(expectedEntity);
|
|
123
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
124
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
125
|
+
expect(
|
|
126
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
127
|
+
).toHaveBeenCalledTimes(1);
|
|
128
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
129
|
+
expectedEntity,
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("User having online authenticated active session, update is authenticated to false and store it into the local storage.", async () => {
|
|
134
|
+
expect.assertions(4);
|
|
135
|
+
const userActiveSession = {
|
|
136
|
+
is_authenticated: true,
|
|
137
|
+
is_mfa_required: false,
|
|
138
|
+
is_server_reachable: true,
|
|
139
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
140
|
+
};
|
|
141
|
+
jest
|
|
142
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
143
|
+
.mockImplementation(() => true);
|
|
144
|
+
jest
|
|
145
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
146
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
147
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
148
|
+
jest
|
|
149
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated")
|
|
150
|
+
.mockImplementationOnce(() => false);
|
|
151
|
+
|
|
152
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
153
|
+
|
|
154
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
155
|
+
expectedEntity.isAuthenticated = false;
|
|
156
|
+
expect(entity).toEqual(expectedEntity);
|
|
157
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
158
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
159
|
+
expect(
|
|
160
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
161
|
+
).toHaveBeenCalledTimes(1);
|
|
162
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
163
|
+
expectedEntity,
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("User having online authenticated active session, update is mfa authenticated to false and store it into the local storage.", async () => {
|
|
168
|
+
expect.assertions(4);
|
|
169
|
+
const userActiveSession = {
|
|
170
|
+
is_authenticated: true,
|
|
171
|
+
is_mfa_required: false,
|
|
172
|
+
is_server_reachable: true,
|
|
173
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
174
|
+
};
|
|
175
|
+
jest
|
|
176
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
177
|
+
.mockImplementation(() => true);
|
|
178
|
+
jest
|
|
179
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
180
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
181
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
182
|
+
jest
|
|
183
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated")
|
|
184
|
+
.mockImplementationOnce(() => {
|
|
185
|
+
throw new MfaAuthenticationRequiredError();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
189
|
+
|
|
190
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
191
|
+
expectedEntity.isMfaRequired = true;
|
|
192
|
+
expect(entity).toEqual(expectedEntity);
|
|
193
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
194
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
195
|
+
expect(
|
|
196
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
197
|
+
).toHaveBeenCalledTimes(1);
|
|
198
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
199
|
+
expectedEntity,
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
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 () => {
|
|
204
|
+
expect.assertions(4);
|
|
205
|
+
const userActiveSession = {
|
|
206
|
+
is_authenticated: true,
|
|
207
|
+
is_mfa_required: false,
|
|
208
|
+
is_server_reachable: false,
|
|
209
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
210
|
+
};
|
|
211
|
+
jest
|
|
212
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
213
|
+
.mockImplementation(() => true);
|
|
214
|
+
jest
|
|
215
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
216
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
217
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
218
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
219
|
+
|
|
220
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
221
|
+
|
|
222
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
223
|
+
expectedEntity.isServerReachable = true;
|
|
224
|
+
expect(entity).toEqual(expectedEntity);
|
|
225
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
226
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
227
|
+
expect(
|
|
228
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
229
|
+
).not.toHaveBeenCalled();
|
|
230
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
231
|
+
expectedEntity,
|
|
232
|
+
);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("User having offline authenticated active session and server is still not reachable, update the local storage with same values.", async () => {
|
|
236
|
+
expect.assertions(4);
|
|
237
|
+
const userActiveSession = {
|
|
238
|
+
is_authenticated: true,
|
|
239
|
+
is_mfa_required: false,
|
|
240
|
+
is_server_reachable: false,
|
|
241
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
242
|
+
};
|
|
243
|
+
jest
|
|
244
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
245
|
+
.mockImplementation(() => false);
|
|
246
|
+
jest
|
|
247
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
248
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
249
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
250
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
251
|
+
|
|
252
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
253
|
+
|
|
254
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
255
|
+
expect(entity).toEqual(expectedEntity);
|
|
256
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
257
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
258
|
+
expect(
|
|
259
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
260
|
+
).not.toHaveBeenCalled();
|
|
261
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
262
|
+
expectedEntity,
|
|
263
|
+
);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
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 () => {
|
|
267
|
+
expect.assertions(4);
|
|
268
|
+
const userActiveSession = {
|
|
269
|
+
is_authenticated: false,
|
|
270
|
+
is_mfa_required: false,
|
|
271
|
+
is_server_reachable: true,
|
|
272
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
273
|
+
};
|
|
274
|
+
jest
|
|
275
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
276
|
+
.mockImplementation(() => false);
|
|
277
|
+
jest
|
|
278
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
279
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
280
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
281
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
282
|
+
|
|
283
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
284
|
+
|
|
285
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
286
|
+
expectedEntity.isServerReachable = false;
|
|
287
|
+
expectedEntity.type = USER_ACTIVE_SESSION_OFFLINE;
|
|
288
|
+
expect(entity).toEqual(expectedEntity);
|
|
289
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
290
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
291
|
+
expect(
|
|
292
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
293
|
+
).not.toHaveBeenCalled();
|
|
294
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
295
|
+
expectedEntity,
|
|
296
|
+
);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("User having online not authenticated active session and server is still reachable, update the local storage with same values.", async () => {
|
|
300
|
+
expect.assertions(4);
|
|
301
|
+
const userActiveSession = {
|
|
302
|
+
is_authenticated: false,
|
|
303
|
+
is_mfa_required: false,
|
|
304
|
+
is_server_reachable: true,
|
|
305
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
306
|
+
};
|
|
307
|
+
jest
|
|
308
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
309
|
+
.mockImplementation(() => true);
|
|
310
|
+
jest
|
|
311
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
312
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
313
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
314
|
+
jest
|
|
315
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated")
|
|
316
|
+
.mockImplementationOnce(() => false);
|
|
317
|
+
|
|
318
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
319
|
+
|
|
320
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
321
|
+
expect(entity).toEqual(expectedEntity);
|
|
322
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
323
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
324
|
+
expect(
|
|
325
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
326
|
+
).toHaveBeenCalledTimes(1);
|
|
327
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
328
|
+
expectedEntity,
|
|
329
|
+
);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
describe("::resetAuthentication", () => {
|
|
334
|
+
it("resets authentication in place, preserving durable fields", async () => {
|
|
335
|
+
expect.assertions(5);
|
|
336
|
+
const existing = {
|
|
337
|
+
is_authenticated: true,
|
|
338
|
+
is_mfa_required: true,
|
|
339
|
+
is_server_reachable: false,
|
|
340
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
341
|
+
last_seen_online: "2025-08-06T10:05:46+00:00",
|
|
342
|
+
last_logged_in: "2025-08-06T09:00:00+00:00",
|
|
343
|
+
};
|
|
344
|
+
jest
|
|
345
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
346
|
+
.mockImplementationOnce(() => existing);
|
|
347
|
+
|
|
348
|
+
await findAndUpdateActiveSessionLocalStorageService.resetAuthentication();
|
|
349
|
+
|
|
350
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
351
|
+
expect(storageValue.is_authenticated).toBe(false);
|
|
352
|
+
expect(storageValue.is_mfa_required).toBe(false);
|
|
353
|
+
expect(storageValue.last_seen_online).toBe("2025-08-06T10:05:46+00:00");
|
|
354
|
+
expect(storageValue.last_logged_in).toBe("2025-08-06T09:00:00+00:00");
|
|
355
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_OFFLINE);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("does nothing when there is no active session", async () => {
|
|
359
|
+
expect.assertions(2);
|
|
360
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
361
|
+
|
|
362
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.resetAuthentication();
|
|
363
|
+
|
|
364
|
+
expect(entity).toBeNull();
|
|
365
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).not.toHaveBeenCalled();
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("fails safe to an unauthenticated session when the reset errors", async () => {
|
|
369
|
+
expect.assertions(2);
|
|
370
|
+
const corrupt = { is_authenticated: "not-a-boolean", type: USER_ACTIVE_SESSION_ONLINE };
|
|
371
|
+
jest
|
|
372
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
373
|
+
.mockImplementationOnce(() => corrupt);
|
|
374
|
+
jest
|
|
375
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
376
|
+
.mockImplementation(() => false);
|
|
377
|
+
|
|
378
|
+
await findAndUpdateActiveSessionLocalStorageService.resetAuthentication();
|
|
379
|
+
|
|
380
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
381
|
+
expect(storageValue.is_authenticated).toBe(false);
|
|
382
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_OFFLINE);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe("::authenticateOnline", () => {
|
|
387
|
+
it("creates an online authenticated session stamped with the login date when none exists", async () => {
|
|
388
|
+
expect.assertions(5);
|
|
389
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find");
|
|
390
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
391
|
+
|
|
392
|
+
await findAndUpdateActiveSessionLocalStorageService.authenticateOnline();
|
|
393
|
+
|
|
394
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
395
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
396
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_ONLINE);
|
|
397
|
+
expect(typeof storageValue.last_logged_in).toBe("string");
|
|
398
|
+
expect(typeof storageValue.last_seen_online).toBe("string");
|
|
399
|
+
expect(findAndUpdateActiveSessionLocalStorageService.findServerStatusService.find).not.toHaveBeenCalled();
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it("asserts online authenticated and refreshes the login date while preserving other durable fields", async () => {
|
|
403
|
+
expect.assertions(7);
|
|
404
|
+
const existing = {
|
|
405
|
+
is_authenticated: false,
|
|
406
|
+
is_mfa_required: false,
|
|
407
|
+
is_server_reachable: false,
|
|
408
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
409
|
+
last_seen_online: "2025-08-06T10:05:46+00:00",
|
|
410
|
+
last_logged_in: "2025-08-06T09:00:00+00:00",
|
|
411
|
+
};
|
|
412
|
+
jest
|
|
413
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
414
|
+
.mockImplementationOnce(() => existing);
|
|
415
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
416
|
+
|
|
417
|
+
await findAndUpdateActiveSessionLocalStorageService.authenticateOnline();
|
|
418
|
+
|
|
419
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
420
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
421
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_ONLINE);
|
|
422
|
+
// The login date and last seen online date are refreshed to the current date, not kept from the previous session.
|
|
423
|
+
expect(storageValue.last_logged_in).not.toBe("2025-08-06T09:00:00+00:00");
|
|
424
|
+
expect(typeof storageValue.last_logged_in).toBe("string");
|
|
425
|
+
expect(storageValue.last_seen_online).not.toBe("2025-08-06T09:00:00+00:00");
|
|
426
|
+
expect(typeof storageValue.last_seen_online).toBe("string");
|
|
427
|
+
expect(
|
|
428
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
429
|
+
).not.toHaveBeenCalled();
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it("fails safe to a minimal authenticated online session when the write errors, so the user stays signed in", async () => {
|
|
433
|
+
expect.assertions(3);
|
|
434
|
+
const corrupt = {
|
|
435
|
+
is_authenticated: false,
|
|
436
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
437
|
+
is_server_reachable: "not-a-boolean",
|
|
438
|
+
};
|
|
439
|
+
jest
|
|
440
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
441
|
+
.mockImplementationOnce(() => corrupt);
|
|
442
|
+
|
|
443
|
+
await findAndUpdateActiveSessionLocalStorageService.authenticateOnline();
|
|
444
|
+
|
|
445
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
446
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
447
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_ONLINE);
|
|
448
|
+
expect(typeof storageValue.last_logged_in).toBe("string");
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
describe("::authenticateOffline", () => {
|
|
453
|
+
it("creates an offline authenticated session stamped with the login date when none exists", async () => {
|
|
454
|
+
expect.assertions(4);
|
|
455
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find");
|
|
456
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
457
|
+
|
|
458
|
+
await findAndUpdateActiveSessionLocalStorageService.authenticateOffline();
|
|
459
|
+
|
|
460
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
461
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
462
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_OFFLINE);
|
|
463
|
+
expect(typeof storageValue.last_logged_in).toBe("string");
|
|
464
|
+
expect(findAndUpdateActiveSessionLocalStorageService.findServerStatusService.find).not.toHaveBeenCalled();
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it("asserts offline authenticated and refreshes the login date while preserving other durable fields", async () => {
|
|
468
|
+
expect.assertions(7);
|
|
469
|
+
const existing = {
|
|
470
|
+
is_authenticated: false,
|
|
471
|
+
is_mfa_required: false,
|
|
472
|
+
is_server_reachable: false,
|
|
473
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
474
|
+
last_seen_online: "2025-08-06T10:05:46+00:00",
|
|
475
|
+
last_logged_in: "2025-08-06T09:00:00+00:00",
|
|
476
|
+
};
|
|
477
|
+
jest
|
|
478
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
479
|
+
.mockImplementationOnce(() => existing);
|
|
480
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
481
|
+
|
|
482
|
+
await findAndUpdateActiveSessionLocalStorageService.authenticateOffline();
|
|
483
|
+
|
|
484
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
485
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
486
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_OFFLINE);
|
|
487
|
+
expect(storageValue.last_seen_online).toBe("2025-08-06T10:05:46+00:00");
|
|
488
|
+
expect(storageValue.is_server_reachable).toBe(false);
|
|
489
|
+
expect(storageValue.last_logged_in).not.toBe("2025-08-06T09:00:00+00:00");
|
|
490
|
+
expect(typeof storageValue.last_logged_in).toBe("string");
|
|
491
|
+
expect(
|
|
492
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
493
|
+
).not.toHaveBeenCalled();
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it("fails safe to a minimal authenticated offline session when the write errors, so the user stays signed in offline", async () => {
|
|
497
|
+
expect.assertions(3);
|
|
498
|
+
const corrupt = {
|
|
499
|
+
is_authenticated: false,
|
|
500
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
501
|
+
is_server_reachable: "not-a-boolean",
|
|
502
|
+
};
|
|
503
|
+
jest
|
|
504
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
505
|
+
.mockImplementationOnce(() => corrupt);
|
|
506
|
+
jest
|
|
507
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
508
|
+
.mockImplementation(() => false);
|
|
509
|
+
|
|
510
|
+
await findAndUpdateActiveSessionLocalStorageService.authenticateOffline();
|
|
511
|
+
|
|
512
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
513
|
+
expect(storageValue.is_authenticated).toBe(true);
|
|
514
|
+
expect(storageValue.type).toBe(USER_ACTIVE_SESSION_OFFLINE);
|
|
515
|
+
expect(typeof storageValue.last_logged_in).toBe("string");
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it("User having offline not authenticated active session and server become reachable, active session become online and store it into the local storage.", async () => {
|
|
520
|
+
expect.assertions(4);
|
|
521
|
+
const userActiveSession = {
|
|
522
|
+
is_authenticated: false,
|
|
523
|
+
is_mfa_required: false,
|
|
524
|
+
is_server_reachable: false,
|
|
525
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
526
|
+
};
|
|
527
|
+
jest
|
|
528
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
529
|
+
.mockImplementation(() => true);
|
|
530
|
+
jest
|
|
531
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
532
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
533
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
534
|
+
jest
|
|
535
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated")
|
|
536
|
+
.mockImplementationOnce(() => false);
|
|
537
|
+
|
|
538
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
539
|
+
|
|
540
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
541
|
+
expectedEntity.isServerReachable = true;
|
|
542
|
+
expectedEntity.type = USER_ACTIVE_SESSION_ONLINE;
|
|
543
|
+
expect(entity).toEqual(expectedEntity);
|
|
544
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
545
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
546
|
+
expect(
|
|
547
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
548
|
+
).toHaveBeenCalledTimes(1);
|
|
549
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
550
|
+
expectedEntity,
|
|
551
|
+
);
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
it("User having offline not authenticated active session and server is still not reachable, update the local storage with same values.", async () => {
|
|
555
|
+
expect.assertions(4);
|
|
556
|
+
const userActiveSession = {
|
|
557
|
+
is_authenticated: false,
|
|
558
|
+
is_mfa_required: false,
|
|
559
|
+
is_server_reachable: false,
|
|
560
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
561
|
+
};
|
|
562
|
+
jest
|
|
563
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
564
|
+
.mockImplementation(() => false);
|
|
565
|
+
jest
|
|
566
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
567
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
568
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
569
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
570
|
+
|
|
571
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
572
|
+
|
|
573
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
574
|
+
expect(entity).toEqual(expectedEntity);
|
|
575
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
576
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
577
|
+
expect(
|
|
578
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
579
|
+
).not.toHaveBeenCalled();
|
|
580
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
581
|
+
expectedEntity,
|
|
582
|
+
);
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
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 () => {
|
|
586
|
+
expect.assertions(4);
|
|
587
|
+
const userActiveSession = {
|
|
588
|
+
is_authenticated: "false",
|
|
589
|
+
is_server_reachable: true,
|
|
590
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
591
|
+
};
|
|
592
|
+
jest
|
|
593
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
594
|
+
.mockImplementation(() => false);
|
|
595
|
+
jest
|
|
596
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
597
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
598
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
599
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
600
|
+
|
|
601
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
602
|
+
|
|
603
|
+
const expectedEntity = new UserActiveSessionEntity({
|
|
604
|
+
is_authenticated: false,
|
|
605
|
+
is_mfa_required: false,
|
|
606
|
+
is_server_reachable: false,
|
|
607
|
+
type: USER_ACTIVE_SESSION_OFFLINE,
|
|
608
|
+
});
|
|
609
|
+
expect(entity).toEqual(expectedEntity);
|
|
610
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
611
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
612
|
+
expect(
|
|
613
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
614
|
+
).not.toHaveBeenCalled();
|
|
615
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
616
|
+
expectedEntity,
|
|
617
|
+
);
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
it("If active session is not valid and server is reachable, create online active session and store it into the local storage.", async () => {
|
|
621
|
+
expect.assertions(4);
|
|
622
|
+
const userActiveSession = {
|
|
623
|
+
is_authenticated: "false",
|
|
624
|
+
is_server_reachable: true,
|
|
625
|
+
is_mfa_required: false,
|
|
626
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
627
|
+
};
|
|
628
|
+
jest
|
|
629
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
630
|
+
.mockImplementation(() => true);
|
|
631
|
+
jest
|
|
632
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
633
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
634
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
635
|
+
jest
|
|
636
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated")
|
|
637
|
+
.mockImplementationOnce(() => true);
|
|
638
|
+
|
|
639
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
640
|
+
|
|
641
|
+
const expectedEntity = new UserActiveSessionEntity({
|
|
642
|
+
is_authenticated: true,
|
|
643
|
+
is_mfa_required: false,
|
|
644
|
+
is_server_reachable: true,
|
|
645
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
646
|
+
});
|
|
647
|
+
expect(entity).toEqual(expectedEntity);
|
|
648
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
649
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
650
|
+
expect(
|
|
651
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
652
|
+
).toHaveBeenCalledTimes(1);
|
|
653
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
654
|
+
expectedEntity,
|
|
655
|
+
);
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
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 () => {
|
|
659
|
+
expect.assertions(4);
|
|
660
|
+
const userActiveSession = {
|
|
661
|
+
is_authenticated: true,
|
|
662
|
+
is_mfa_required: false,
|
|
663
|
+
is_server_reachable: true,
|
|
664
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
665
|
+
};
|
|
666
|
+
jest
|
|
667
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
668
|
+
.mockImplementation(() => true);
|
|
669
|
+
jest
|
|
670
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
671
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
672
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "set");
|
|
673
|
+
jest
|
|
674
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated")
|
|
675
|
+
.mockImplementationOnce(() => {
|
|
676
|
+
throw new Error();
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
const entity = await findAndUpdateActiveSessionLocalStorageService.findAndUpdateAuthenticationStatus();
|
|
680
|
+
|
|
681
|
+
const expectedEntity = new UserActiveSessionEntity(userActiveSession);
|
|
682
|
+
expect(entity).toEqual(expectedEntity);
|
|
683
|
+
const storageValue = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
684
|
+
expect(storageValue).toEqual(expectedEntity.toDto());
|
|
685
|
+
expect(
|
|
686
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
687
|
+
).toHaveBeenCalledTimes(1);
|
|
688
|
+
expect(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.set).toHaveBeenCalledWith(
|
|
689
|
+
expectedEntity,
|
|
690
|
+
);
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
describe("::updateLastSeenOnline", () => {
|
|
694
|
+
it("Update the last seen online property when no user active session is stored in local storage", async () => {
|
|
695
|
+
expect.assertions(5);
|
|
696
|
+
jest
|
|
697
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
698
|
+
.mockImplementationOnce(() => true);
|
|
699
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
700
|
+
|
|
701
|
+
const date = new Date();
|
|
702
|
+
await findAndUpdateActiveSessionLocalStorageService.updateLastSeenOnline(date);
|
|
703
|
+
|
|
704
|
+
const userActiveSessionDto = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
705
|
+
expect(userActiveSessionDto.is_authenticated).toBeFalsy();
|
|
706
|
+
expect(userActiveSessionDto.type).toBe(USER_ACTIVE_SESSION_ONLINE);
|
|
707
|
+
expect(userActiveSessionDto.last_seen_online).toBe(date.toISOString());
|
|
708
|
+
expect(findAndUpdateActiveSessionLocalStorageService.findServerStatusService.find).toHaveBeenCalledTimes(1);
|
|
709
|
+
expect(
|
|
710
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
711
|
+
).not.toHaveBeenCalled();
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
it("Update the last seen online property when user active session is stored in local storage", async () => {
|
|
715
|
+
expect.assertions(5);
|
|
716
|
+
const userActiveSession = {
|
|
717
|
+
is_authenticated: true,
|
|
718
|
+
is_server_reachable: true,
|
|
719
|
+
is_mfa_required: false,
|
|
720
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
721
|
+
};
|
|
722
|
+
jest
|
|
723
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
724
|
+
.mockImplementationOnce(() => userActiveSession);
|
|
725
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find");
|
|
726
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
727
|
+
|
|
728
|
+
const date = new Date();
|
|
729
|
+
await findAndUpdateActiveSessionLocalStorageService.updateLastSeenOnline(date);
|
|
730
|
+
|
|
731
|
+
const userActiveSessionDto = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
732
|
+
expect(userActiveSessionDto.is_authenticated).toBeTruthy();
|
|
733
|
+
expect(userActiveSessionDto.type).toBe(USER_ACTIVE_SESSION_ONLINE);
|
|
734
|
+
expect(userActiveSessionDto.last_seen_online).toBe(date.toISOString());
|
|
735
|
+
expect(findAndUpdateActiveSessionLocalStorageService.findServerStatusService.find).not.toHaveBeenCalled();
|
|
736
|
+
expect(
|
|
737
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
738
|
+
).not.toHaveBeenCalled();
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
it("assert parameter last seen online property is a date", async () => {
|
|
742
|
+
expect.assertions(1);
|
|
743
|
+
expect(findAndUpdateActiveSessionLocalStorageService.updateLastSeenOnline({})).rejects.toThrow(
|
|
744
|
+
"The given data is not of the expected type",
|
|
745
|
+
);
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
it("fails safe to a minimal user active session and update last seen online property", async () => {
|
|
749
|
+
expect.assertions(5);
|
|
750
|
+
const corrupt = {
|
|
751
|
+
is_authenticated: false,
|
|
752
|
+
type: USER_ACTIVE_SESSION_ONLINE,
|
|
753
|
+
is_server_reachable: "not-a-boolean",
|
|
754
|
+
};
|
|
755
|
+
jest
|
|
756
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage, "get")
|
|
757
|
+
.mockImplementationOnce(() => corrupt);
|
|
758
|
+
jest
|
|
759
|
+
.spyOn(findAndUpdateActiveSessionLocalStorageService.findServerStatusService, "find")
|
|
760
|
+
.mockImplementation(() => true);
|
|
761
|
+
jest.spyOn(findAndUpdateActiveSessionLocalStorageService.authenticationStatusService, "isAuthenticated");
|
|
762
|
+
|
|
763
|
+
const date = new Date();
|
|
764
|
+
await findAndUpdateActiveSessionLocalStorageService.updateLastSeenOnline(date);
|
|
765
|
+
|
|
766
|
+
const userActiveSessionDto = await findAndUpdateActiveSessionLocalStorageService.activeSessionLocalStorage.get();
|
|
767
|
+
expect(userActiveSessionDto.is_authenticated).toBeFalsy();
|
|
768
|
+
expect(userActiveSessionDto.type).toBe(USER_ACTIVE_SESSION_ONLINE);
|
|
769
|
+
expect(userActiveSessionDto.last_seen_online).toBe(date.toISOString());
|
|
770
|
+
expect(findAndUpdateActiveSessionLocalStorageService.findServerStatusService.find).toHaveBeenCalledTimes(1);
|
|
771
|
+
expect(
|
|
772
|
+
findAndUpdateActiveSessionLocalStorageService.authenticationStatusService.isAuthenticated,
|
|
773
|
+
).not.toHaveBeenCalled();
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
});
|