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
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
* @link https://www.passbolt.com Passbolt(tm)
|
|
12
12
|
* @since 6.0.0
|
|
13
13
|
*/
|
|
14
|
-
import
|
|
14
|
+
import ActiveSessionSessionStorage from "../session_storage/activeSessionSessionStorage";
|
|
15
15
|
import UserActiveSessionEntity from "passbolt-styleguide/src/shared/models/entity/session/userActiveSessionEntity";
|
|
16
|
-
import
|
|
16
|
+
import FindAndUpdateActiveSessionSessionStorageService from "./findAndUpdateActiveSessionSessionStorageService";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* The service aims to find a user active session.
|
|
@@ -26,8 +26,8 @@ export default class GetOrFindActiveSessionService {
|
|
|
26
26
|
*/
|
|
27
27
|
constructor(account, apiClientOptions) {
|
|
28
28
|
this.account = account;
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
29
|
+
this.activeSessionSessionStorage = new ActiveSessionSessionStorage(account);
|
|
30
|
+
this.findAndUpdateActiveSessionSessionStorageService = new FindAndUpdateActiveSessionSessionStorageService(
|
|
31
31
|
account,
|
|
32
32
|
apiClientOptions,
|
|
33
33
|
);
|
|
@@ -39,8 +39,8 @@ export default class GetOrFindActiveSessionService {
|
|
|
39
39
|
* @returns {Promise<UserActiveSessionEntity>}
|
|
40
40
|
*/
|
|
41
41
|
async getOrFind() {
|
|
42
|
-
const hasRuntimeCache = this.
|
|
43
|
-
const userActiveSessionDto = await this.
|
|
42
|
+
const hasRuntimeCache = this.activeSessionSessionStorage.hasCachedData();
|
|
43
|
+
const userActiveSessionDto = await this.activeSessionSessionStorage.get();
|
|
44
44
|
// Return local storage data if the storage was initialized.
|
|
45
45
|
if (userActiveSessionDto) {
|
|
46
46
|
try {
|
|
@@ -49,11 +49,11 @@ export default class GetOrFindActiveSessionService {
|
|
|
49
49
|
} catch (error) {
|
|
50
50
|
console.error(error);
|
|
51
51
|
// If any validation error, retrieve or create a default user active session and update the local storage.
|
|
52
|
-
return await this.
|
|
52
|
+
return await this.findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// Otherwise retrieve the user active session and update the local storage.
|
|
57
|
-
return await this.
|
|
57
|
+
return await this.findAndUpdateActiveSessionSessionStorageService.findAndUpdateAuthenticationStatus();
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -15,12 +15,12 @@ import AccountEntity from "../../model/entity/account/accountEntity";
|
|
|
15
15
|
import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
|
|
16
16
|
import { defaultApiClientOptions } from "passbolt-styleguide/src/shared/lib/apiClient/apiClientOptions.test.data";
|
|
17
17
|
import GetOrFindActiveSessionService from "./getOrFindActiveSessionService";
|
|
18
|
-
import
|
|
18
|
+
import FindAndUpdateActiveSessionSessionStorageService from "./findAndUpdateActiveSessionSessionStorageService";
|
|
19
19
|
import FindServerStatusService from "../status/findServerStatusService";
|
|
20
20
|
import UserActiveSessionEntity, {
|
|
21
21
|
USER_ACTIVE_SESSION_ONLINE,
|
|
22
22
|
} from "passbolt-styleguide/src/shared/models/entity/session/userActiveSessionEntity";
|
|
23
|
-
import
|
|
23
|
+
import ActiveSessionSessionStorage from "../session_storage/activeSessionSessionStorage";
|
|
24
24
|
|
|
25
25
|
describe("GetOrFindActiveSessionService", () => {
|
|
26
26
|
let service, account;
|
|
@@ -30,37 +30,37 @@ describe("GetOrFindActiveSessionService", () => {
|
|
|
30
30
|
account = new AccountEntity(defaultAccountDto());
|
|
31
31
|
service = new GetOrFindActiveSessionService(account, defaultApiClientOptions());
|
|
32
32
|
// flush account related storage before each.
|
|
33
|
-
await service.
|
|
33
|
+
await service.activeSessionSessionStorage.flush();
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
describe("::getOrFindAll", () => {
|
|
37
37
|
it("fetches from the API the server status and initializes the local storage with a user active session.", async () => {
|
|
38
38
|
expect.assertions(3);
|
|
39
39
|
jest.spyOn(FindServerStatusService.prototype, "find").mockImplementation(() => true);
|
|
40
|
-
jest.spyOn(
|
|
40
|
+
jest.spyOn(FindAndUpdateActiveSessionSessionStorageService.prototype, "findAndUpdateAuthenticationStatus");
|
|
41
41
|
|
|
42
42
|
const userActiveSessionEntity = await service.getOrFind();
|
|
43
43
|
|
|
44
44
|
expect(
|
|
45
|
-
|
|
45
|
+
FindAndUpdateActiveSessionSessionStorageService.prototype.findAndUpdateAuthenticationStatus,
|
|
46
46
|
).toHaveBeenCalledTimes(1);
|
|
47
47
|
expect(userActiveSessionEntity).toBeInstanceOf(UserActiveSessionEntity);
|
|
48
|
-
expect(await service.
|
|
48
|
+
expect(await service.activeSessionSessionStorage.get()).toEqual(userActiveSessionEntity.toDto());
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
it("If any validation error happen, fetches from the API the server status and set the local storage with a user active session.", async () => {
|
|
52
52
|
expect.assertions(3);
|
|
53
53
|
jest.spyOn(FindServerStatusService.prototype, "find").mockImplementation(() => true);
|
|
54
|
-
jest.spyOn(service.
|
|
55
|
-
jest.spyOn(
|
|
54
|
+
jest.spyOn(service.activeSessionSessionStorage, "get").mockImplementationOnce(() => {});
|
|
55
|
+
jest.spyOn(FindAndUpdateActiveSessionSessionStorageService.prototype, "findAndUpdateAuthenticationStatus");
|
|
56
56
|
|
|
57
57
|
const userActiveSessionEntity = await service.getOrFind();
|
|
58
58
|
|
|
59
59
|
expect(
|
|
60
|
-
|
|
60
|
+
FindAndUpdateActiveSessionSessionStorageService.prototype.findAndUpdateAuthenticationStatus,
|
|
61
61
|
).toHaveBeenCalledTimes(1);
|
|
62
62
|
expect(userActiveSessionEntity).toBeInstanceOf(UserActiveSessionEntity);
|
|
63
|
-
expect(await service.
|
|
63
|
+
expect(await service.activeSessionSessionStorage.get()).toEqual(userActiveSessionEntity.toDto());
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
it("retrieves user active session from the local storage when the local storage is initialized.", async () => {
|
|
@@ -71,15 +71,15 @@ describe("GetOrFindActiveSessionService", () => {
|
|
|
71
71
|
type: USER_ACTIVE_SESSION_ONLINE,
|
|
72
72
|
};
|
|
73
73
|
jest.spyOn(FindServerStatusService.prototype, "find");
|
|
74
|
-
await service.
|
|
74
|
+
await service.activeSessionSessionStorage.set(new UserActiveSessionEntity(userActiveSession));
|
|
75
75
|
|
|
76
|
-
expect(service.
|
|
76
|
+
expect(service.activeSessionSessionStorage.hasCachedData()).toBeTruthy();
|
|
77
77
|
|
|
78
78
|
const userActiveSessionEntity = await service.getOrFind();
|
|
79
79
|
|
|
80
80
|
expect(FindServerStatusService.prototype.find).not.toHaveBeenCalled();
|
|
81
81
|
expect(userActiveSessionEntity.toDto()).toEqual(userActiveSession);
|
|
82
|
-
expect(await service.
|
|
82
|
+
expect(await service.activeSessionSessionStorage.get()).toEqual(userActiveSessionEntity.toDto());
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
it("does not validate the user active session if the information is retrieved from the runtime cache.", async () => {
|
|
@@ -90,7 +90,7 @@ describe("GetOrFindActiveSessionService", () => {
|
|
|
90
90
|
type: USER_ACTIVE_SESSION_ONLINE,
|
|
91
91
|
};
|
|
92
92
|
jest.spyOn(FindServerStatusService.prototype, "find");
|
|
93
|
-
await service.
|
|
93
|
+
await service.activeSessionSessionStorage.set(new UserActiveSessionEntity(userActiveSession));
|
|
94
94
|
jest.spyOn(UserActiveSessionEntity.prototype, "validateSchema");
|
|
95
95
|
|
|
96
96
|
await service.getOrFind();
|
|
@@ -108,8 +108,8 @@ describe("GetOrFindActiveSessionService", () => {
|
|
|
108
108
|
type: USER_ACTIVE_SESSION_ONLINE,
|
|
109
109
|
};
|
|
110
110
|
jest.spyOn(FindServerStatusService.prototype, "find");
|
|
111
|
-
await service.
|
|
112
|
-
|
|
111
|
+
await service.activeSessionSessionStorage.set(new UserActiveSessionEntity(userActiveSession));
|
|
112
|
+
ActiveSessionSessionStorage._runtimeCachedData = {};
|
|
113
113
|
jest.spyOn(UserActiveSessionEntity.prototype, "validateSchema");
|
|
114
114
|
|
|
115
115
|
await service.getOrFind();
|
|
@@ -35,35 +35,6 @@ class AccountSettingsService extends AbstractService {
|
|
|
35
35
|
return RESOURCE_SERVICE_RESOURCE_NAME;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* Find all themes
|
|
40
|
-
*
|
|
41
|
-
* @returns {Promise<*>} response body
|
|
42
|
-
* @throws {Error} if options are invalid or API error
|
|
43
|
-
* @public
|
|
44
|
-
*/
|
|
45
|
-
async findAllThemes() {
|
|
46
|
-
const url = this.apiClient.buildUrl(`${this.apiClient.baseUrl}/themes`);
|
|
47
|
-
const response = await this.apiClient.fetchAndHandleResponse("GET", url);
|
|
48
|
-
return response.body;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Update the current user theme
|
|
53
|
-
*
|
|
54
|
-
* @param {string} name The theme name to switch on
|
|
55
|
-
* @returns {Promise<*>} response body
|
|
56
|
-
* @throws {Error} if options are invalid or API error
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
async updateTheme(name) {
|
|
60
|
-
const data = { value: name };
|
|
61
|
-
const bodyString = this.apiClient.buildBody(data);
|
|
62
|
-
const url = this.apiClient.buildUrl(`${this.apiClient.baseUrl}/themes`);
|
|
63
|
-
const response = await this.apiClient.fetchAndHandleResponse("POST", url, bodyString);
|
|
64
|
-
return response.body;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
38
|
/**
|
|
68
39
|
* Update the current user locale language
|
|
69
40
|
*
|
package/src/all/background_page/service/api/accountSettings/accountSettingsService.test.data.js
CHANGED
|
@@ -21,12 +21,6 @@ export const accountSettingsService_midgarThemeDto = (data = {}) => ({
|
|
|
21
21
|
...data,
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
export const accountSettingsService_themesDto = () => [
|
|
25
|
-
accountSettingsService_midgarThemeDto({ value: "default" }),
|
|
26
|
-
accountSettingsService_midgarThemeDto({ value: "midgar" }),
|
|
27
|
-
accountSettingsService_midgarThemeDto({ value: "solarized_light" }),
|
|
28
|
-
];
|
|
29
|
-
|
|
30
24
|
export const accountSettingsService_localeDto = (data = {}) => ({
|
|
31
25
|
id: uuidv4(),
|
|
32
26
|
value: "en-UK",
|
|
@@ -16,11 +16,7 @@ import { defaultApiClientOptions } from "passbolt-styleguide/src/shared/lib/apiC
|
|
|
16
16
|
import AccountSettingsService from "./accountSettingsService";
|
|
17
17
|
import { enableFetchMocks } from "jest-fetch-mock";
|
|
18
18
|
import { mockApiResponse } from "../../../../../../test/mocks/mockApiResponse";
|
|
19
|
-
import {
|
|
20
|
-
accountSettingsService_midgarThemeDto,
|
|
21
|
-
accountSettingsService_themesDto,
|
|
22
|
-
accountSettingsService_localeDto,
|
|
23
|
-
} from "./accountSettingsService.test.data";
|
|
19
|
+
import { accountSettingsService_localeDto } from "./accountSettingsService.test.data";
|
|
24
20
|
|
|
25
21
|
describe("accountSettingsService", () => {
|
|
26
22
|
let service;
|
|
@@ -31,33 +27,6 @@ describe("accountSettingsService", () => {
|
|
|
31
27
|
service = new AccountSettingsService(apiClientOptions);
|
|
32
28
|
});
|
|
33
29
|
|
|
34
|
-
describe("::updateTheme", () => {
|
|
35
|
-
it("should update the theme value to $expectedUpdateThemeName", async () => {
|
|
36
|
-
expect.assertions(1);
|
|
37
|
-
|
|
38
|
-
const expectedUpdateThemeName = "midgar";
|
|
39
|
-
fetch.doMockOnceIf(
|
|
40
|
-
new RegExp("/settings/themes"),
|
|
41
|
-
async () => await mockApiResponse(accountSettingsService_midgarThemeDto()),
|
|
42
|
-
);
|
|
43
|
-
const receivedUpdateThemeName = await service.updateTheme(expectedUpdateThemeName);
|
|
44
|
-
|
|
45
|
-
expect(receivedUpdateThemeName.value).toBe(expectedUpdateThemeName);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe("::findAllThemes", () => {
|
|
50
|
-
it("should return all available themes", async () => {
|
|
51
|
-
expect.assertions(1);
|
|
52
|
-
|
|
53
|
-
const expectedThemes = accountSettingsService_themesDto();
|
|
54
|
-
fetch.doMockOnceIf(new RegExp("/settings/themes"), async () => await mockApiResponse(expectedThemes));
|
|
55
|
-
const result = await service.findAllThemes();
|
|
56
|
-
|
|
57
|
-
expect(result).toEqual(expectedThemes);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
30
|
describe("::updateLocale", () => {
|
|
62
31
|
it("should update the locale value", async () => {
|
|
63
32
|
expect.assertions(1);
|
|
@@ -40,7 +40,7 @@ describe("ActionLogService", () => {
|
|
|
40
40
|
const service = new ActionLogApiService(apiClientOptions, account);
|
|
41
41
|
const result = await service.findAllFor("Resource", uuidv4(), 1, 5);
|
|
42
42
|
|
|
43
|
-
expect(result).
|
|
43
|
+
expect(Array.isArray(result)).toBe(true);
|
|
44
44
|
expect(result).toHaveLength(apiResponse.length);
|
|
45
45
|
});
|
|
46
46
|
|
|
@@ -43,7 +43,7 @@ describe("ActionLogService", () => {
|
|
|
43
43
|
const service = new CommentApiService(apiClientOptions, account);
|
|
44
44
|
const resultDto = await service.findAll("Resource", uuidv4(), { creator: true });
|
|
45
45
|
|
|
46
|
-
expect(resultDto).
|
|
46
|
+
expect(Array.isArray(resultDto)).toBe(true);
|
|
47
47
|
expect(resultDto).toHaveLength(commentsCollection.length);
|
|
48
48
|
});
|
|
49
49
|
|
|
@@ -47,7 +47,7 @@ describe("MetadataKeysApiService", () => {
|
|
|
47
47
|
const service = new MetadataKeysApiService(apiClientOptions, account);
|
|
48
48
|
const resultDto = await service.findAll();
|
|
49
49
|
|
|
50
|
-
expect(resultDto).
|
|
50
|
+
expect(Array.isArray(resultDto)).toBe(true);
|
|
51
51
|
expect(resultDto).toHaveLength(apiMetadataKeysCollection.length);
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -48,7 +48,7 @@ describe("SessionKeysBundlesApiService", () => {
|
|
|
48
48
|
const service = new SessionKeysBundlesApiService(apiClientOptions);
|
|
49
49
|
const resultDto = await service.findAll();
|
|
50
50
|
|
|
51
|
-
expect(resultDto).
|
|
51
|
+
expect(Array.isArray(resultDto)).toBe(true);
|
|
52
52
|
expect(resultDto).toHaveLength(apiSessionKeysBundlesCollection.length);
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passbolt ~ Open source password manager for teams
|
|
3
|
+
* Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
4
|
+
*
|
|
5
|
+
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
|
6
|
+
* For full copyright and license information, please see the LICENSE.txt
|
|
7
|
+
* Redistributions of files must retain the above copyright notice.
|
|
8
|
+
*
|
|
9
|
+
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
10
|
+
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
|
11
|
+
* @link https://www.passbolt.com Passbolt(tm)
|
|
12
|
+
* @since 5.18.0
|
|
13
|
+
*/
|
|
14
|
+
import AbstractService from "passbolt-styleguide/src/shared/services/api/abstract/abstractService";
|
|
15
|
+
import ChangeThemeEntity from "../../../model/entity/theme/change/ChangeThemeEntity";
|
|
16
|
+
import { assertType } from "../../../utils/assertions";
|
|
17
|
+
|
|
18
|
+
const THEMES_RESOURCE_NAME = "account/settings/themes";
|
|
19
|
+
|
|
20
|
+
export default class ThemesApiService extends AbstractService {
|
|
21
|
+
/**
|
|
22
|
+
* Constructor
|
|
23
|
+
* @param {ApiClientOptions} apiClientOptions
|
|
24
|
+
*/
|
|
25
|
+
constructor(apiClientOptions) {
|
|
26
|
+
super(apiClientOptions, ThemesApiService.RESOURCE_NAME);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* API themes resource name
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
static get RESOURCE_NAME() {
|
|
34
|
+
return THEMES_RESOURCE_NAME;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Find all the themes.
|
|
39
|
+
* @returns {Promise<Array<object>>} the themes dtos
|
|
40
|
+
*/
|
|
41
|
+
async findAll() {
|
|
42
|
+
const response = await this.apiClient.findAll();
|
|
43
|
+
return response.body;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Update the current user theme.
|
|
48
|
+
* @param {ChangeThemeEntity} changeThemeEntity the theme to apply
|
|
49
|
+
* @returns {Promise<object>} the account setting dto
|
|
50
|
+
* @throws {TypeError} if changeThemeEntity is not a ChangeThemeEntity
|
|
51
|
+
*/
|
|
52
|
+
async update(changeThemeEntity) {
|
|
53
|
+
assertType(changeThemeEntity, ChangeThemeEntity, "The given parameter is not a valid ChangeThemeEntity");
|
|
54
|
+
const response = await this.apiClient.create({ value: changeThemeEntity.name });
|
|
55
|
+
return response.body;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passbolt ~ Open source password manager for teams
|
|
3
|
+
* Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
4
|
+
*
|
|
5
|
+
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
|
6
|
+
* For full copyright and license information, please see the LICENSE.txt
|
|
7
|
+
* Redistributions of files must retain the above copyright notice.
|
|
8
|
+
*
|
|
9
|
+
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
10
|
+
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
|
11
|
+
* @link https://www.passbolt.com Passbolt(tm)
|
|
12
|
+
* @since 5.18.0
|
|
13
|
+
*/
|
|
14
|
+
import { enableFetchMocks } from "jest-fetch-mock";
|
|
15
|
+
import { mockApiResponse, mockApiResponseError } from "../../../../../../test/mocks/mockApiResponse";
|
|
16
|
+
import { defaultApiClientOptions } from "passbolt-styleguide/src/shared/lib/apiClient/apiClientOptions.test.data";
|
|
17
|
+
import PassboltApiFetchError from "passbolt-styleguide/src/shared/lib/Error/PassboltApiFetchError";
|
|
18
|
+
import ThemesApiService from "./themesApiService";
|
|
19
|
+
import ChangeThemeEntity from "../../../model/entity/theme/change/ChangeThemeEntity";
|
|
20
|
+
import { defaultThemeCollectionDtos } from "../../../model/entity/theme/themesCollection.test.data";
|
|
21
|
+
import { accountSettingsService_midgarThemeDto } from "../accountSettings/accountSettingsService.test.data";
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
enableFetchMocks();
|
|
25
|
+
jest.clearAllMocks();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("ThemesApiService", () => {
|
|
29
|
+
let service;
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
service = new ThemesApiService(defaultApiClientOptions());
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("has the correct resource name", () => {
|
|
36
|
+
expect.assertions(1);
|
|
37
|
+
expect(ThemesApiService.RESOURCE_NAME).toEqual("account/settings/themes");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("ThemesApiService::findAll", () => {
|
|
41
|
+
it("gets the themes and returns the body", async () => {
|
|
42
|
+
expect.assertions(2);
|
|
43
|
+
const dtos = defaultThemeCollectionDtos();
|
|
44
|
+
fetch.doMockOnceIf(/account\/settings\/themes\.json/, async (req) => {
|
|
45
|
+
expect(req.method).toEqual("GET");
|
|
46
|
+
return mockApiResponse(dtos);
|
|
47
|
+
});
|
|
48
|
+
const body = await service.findAll();
|
|
49
|
+
expect(body).toEqual(dtos);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("throws on API error", async () => {
|
|
53
|
+
expect.assertions(1);
|
|
54
|
+
fetch.doMockOnceIf(/account\/settings\/themes\.json/, () => mockApiResponseError(500, "Something went wrong"));
|
|
55
|
+
await expect(service.findAll()).rejects.toThrow(PassboltApiFetchError);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("ThemesApiService::update", () => {
|
|
60
|
+
it("posts the theme name and returns the body", async () => {
|
|
61
|
+
expect.assertions(3);
|
|
62
|
+
const dto = accountSettingsService_midgarThemeDto();
|
|
63
|
+
fetch.doMockOnceIf(/account\/settings\/themes\.json/, async (req) => {
|
|
64
|
+
expect(req.method).toEqual("POST");
|
|
65
|
+
expect(await req.json()).toEqual({ value: "midgar" });
|
|
66
|
+
return mockApiResponse(dto);
|
|
67
|
+
});
|
|
68
|
+
const body = await service.update(new ChangeThemeEntity({ name: "midgar" }));
|
|
69
|
+
expect(body).toEqual(dto);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("throws if the parameter is not a ChangeThemeEntity", async () => {
|
|
73
|
+
expect.assertions(1);
|
|
74
|
+
await expect(service.update({ name: "midgar" })).rejects.toThrow(TypeError);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("throws on API error", async () => {
|
|
78
|
+
expect.assertions(1);
|
|
79
|
+
fetch.doMockOnceIf(/account\/settings\/themes\.json/, () => mockApiResponseError(500, "Something went wrong"));
|
|
80
|
+
await expect(service.update(new ChangeThemeEntity({ name: "midgar" }))).rejects.toThrow(PassboltApiFetchError);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { assertString, assertType } from "../../utils/assertions";
|
|
2
|
+
import AccountEntity from "../../model/entity/account/accountEntity";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Passbolt ~ Open source password manager for teams
|
|
3
6
|
* Copyright (c) 2022 Passbolt SA (https://www.passbolt.com)
|
|
@@ -11,27 +14,29 @@
|
|
|
11
14
|
* @link https://www.passbolt.com Passbolt(tm)
|
|
12
15
|
* @since 3.6.0
|
|
13
16
|
*/
|
|
14
|
-
import User from "../../model/user";
|
|
15
|
-
|
|
16
17
|
class ParseAppUrlService {
|
|
17
18
|
/**
|
|
18
19
|
* Get regex to check URI validity
|
|
20
|
+
* @param {AccountEntity} account The account
|
|
19
21
|
* @returns {string}
|
|
20
22
|
*/
|
|
21
|
-
static getRegex() {
|
|
22
|
-
|
|
23
|
-
const escapedDomain =
|
|
23
|
+
static getRegex(account) {
|
|
24
|
+
assertType(account, AccountEntity);
|
|
25
|
+
const escapedDomain = account.domain.replace(/\W/g, "\\$&");
|
|
24
26
|
return `^${escapedDomain}/?(/app.*)?(#.*)?$`;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* Parse url to match .
|
|
31
|
+
* @param {AccountEntity} account The account
|
|
29
32
|
* @param {string} url The url to parse.
|
|
30
33
|
* @returns {{domain: string}}
|
|
31
34
|
* @throw {Error} If the setup url cannot be parsed.
|
|
32
35
|
*/
|
|
33
|
-
static parse(url) {
|
|
34
|
-
|
|
36
|
+
static parse(account, url) {
|
|
37
|
+
assertType(account, AccountEntity);
|
|
38
|
+
assertString(url);
|
|
39
|
+
const regex = new RegExp(this.getRegex(account));
|
|
35
40
|
|
|
36
41
|
if (!regex.test(url)) {
|
|
37
42
|
throw new Error("Cannot parse application url. The url does not match the pattern.");
|
|
@@ -43,18 +48,21 @@ class ParseAppUrlService {
|
|
|
43
48
|
new URL(url);
|
|
44
49
|
} catch (error) {
|
|
45
50
|
console.error(error);
|
|
46
|
-
throw new Error("Cannot parse application url. The domain is not valid.");
|
|
51
|
+
throw new Error("Cannot parse application url. The domain is not valid.", { cause: error });
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
/**
|
|
51
56
|
* Test the url against the regex.
|
|
57
|
+
* @param {AccountEntity} account The account
|
|
52
58
|
* @param {string} url The url to test
|
|
53
59
|
* @returns {boolean}
|
|
54
60
|
*/
|
|
55
|
-
static test(url) {
|
|
61
|
+
static test(account, url) {
|
|
56
62
|
try {
|
|
57
|
-
|
|
63
|
+
assertType(account, AccountEntity);
|
|
64
|
+
assertString(url);
|
|
65
|
+
this.parse(account, url);
|
|
58
66
|
return true;
|
|
59
67
|
} catch {
|
|
60
68
|
return false;
|
|
@@ -12,29 +12,26 @@
|
|
|
12
12
|
* @since 3.6.0
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { Config } from "../../model/config";
|
|
16
15
|
import ParseAppUrlService from "./parseAppUrlService";
|
|
16
|
+
import AccountEntity from "../../model/entity/account/accountEntity";
|
|
17
|
+
import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
|
|
17
18
|
|
|
18
19
|
const errorMatchPattern = "Cannot parse application url. The url does not match the pattern.";
|
|
19
20
|
const errorDomainInvalid = "Cannot parse application url. The domain is not valid.";
|
|
20
21
|
|
|
21
|
-
const domain = "https://passbolt.
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
Config.write("user.settings.trustedDomain", "https://passbolt.dev");
|
|
25
|
-
});
|
|
22
|
+
const domain = "https://passbolt.local";
|
|
26
23
|
|
|
27
24
|
describe("ParseAppUrlService", () => {
|
|
28
25
|
describe("ParseAppUrlService:parse", () => {
|
|
29
26
|
describe.each([
|
|
30
27
|
{
|
|
31
28
|
scenario: "TLD",
|
|
32
|
-
url: "https://passbolt.
|
|
29
|
+
url: "https://passbolt.local/app/folders/view/5452ecb2-0625-50d1-b1ef-d2038f5830b6",
|
|
33
30
|
domain: domain,
|
|
34
31
|
},
|
|
35
32
|
{
|
|
36
33
|
scenario: "TLD with Port",
|
|
37
|
-
url: "https://passbolt.
|
|
34
|
+
url: "https://passbolt.local:4443/app/passwords",
|
|
38
35
|
domain: `${domain}:4443`,
|
|
39
36
|
},
|
|
40
37
|
{
|
|
@@ -64,7 +61,7 @@ describe("ParseAppUrlService", () => {
|
|
|
64
61
|
},
|
|
65
62
|
{
|
|
66
63
|
scenario: "Trailing /",
|
|
67
|
-
url: "https://passbolt.
|
|
64
|
+
url: "https://passbolt.local/app/administration/account-recovery//",
|
|
68
65
|
domain: `${domain}/app/administration/account-recovery/`,
|
|
69
66
|
},
|
|
70
67
|
{
|
|
@@ -78,13 +75,14 @@ describe("ParseAppUrlService", () => {
|
|
|
78
75
|
domain: `https://demo.passbolt.com`,
|
|
79
76
|
},
|
|
80
77
|
])("should parse", (_props) => {
|
|
78
|
+
let account;
|
|
81
79
|
beforeEach(() => {
|
|
82
|
-
|
|
80
|
+
account = new AccountEntity(defaultAccountDto({ domain: _props.domain }));
|
|
83
81
|
});
|
|
84
82
|
it(`should parse: ${_props.scenario}`, () => {
|
|
85
83
|
expect.assertions(2);
|
|
86
|
-
expect(() => ParseAppUrlService.parse(_props.url)).not.toThrow(errorMatchPattern);
|
|
87
|
-
expect(() => ParseAppUrlService.parse(_props.url)).not.toThrow(errorDomainInvalid);
|
|
84
|
+
expect(() => ParseAppUrlService.parse(account, _props.url)).not.toThrow(errorMatchPattern);
|
|
85
|
+
expect(() => ParseAppUrlService.parse(account, _props.url)).not.toThrow(errorDomainInvalid);
|
|
88
86
|
});
|
|
89
87
|
});
|
|
90
88
|
|
|
@@ -95,7 +93,7 @@ describe("ParseAppUrlService", () => {
|
|
|
95
93
|
},
|
|
96
94
|
{
|
|
97
95
|
scenario: "Wrong protocol",
|
|
98
|
-
url: "http://passbolt.
|
|
96
|
+
url: "http://passbolt.local",
|
|
99
97
|
},
|
|
100
98
|
{
|
|
101
99
|
scenario: "Not a domain allowed",
|
|
@@ -103,40 +101,42 @@ describe("ParseAppUrlService", () => {
|
|
|
103
101
|
},
|
|
104
102
|
{
|
|
105
103
|
scenario: "Original domain as subdomain attack",
|
|
106
|
-
url: "https://passbolt.
|
|
104
|
+
url: "https://passbolt.local.attacker.com",
|
|
107
105
|
},
|
|
108
106
|
{
|
|
109
107
|
scenario: "Subdomain attack",
|
|
110
|
-
url: "https://attack.passbolt.
|
|
108
|
+
url: "https://attack.passbolt.local",
|
|
111
109
|
},
|
|
112
110
|
{
|
|
113
111
|
scenario: "Regex wild mark attack",
|
|
114
|
-
url: "https://
|
|
112
|
+
url: "https://passboltxlocal",
|
|
115
113
|
},
|
|
116
114
|
{
|
|
117
115
|
scenario: "Non application entry point",
|
|
118
|
-
url: "https://passbolt.
|
|
116
|
+
url: "https://passbolt.local/auth/login",
|
|
119
117
|
},
|
|
120
118
|
{
|
|
121
119
|
scenario: "Domain look alike as hash attack",
|
|
122
120
|
url: `https://www.attacker.com#${domain}`,
|
|
123
121
|
},
|
|
124
122
|
])("should not parse", (_props) => {
|
|
123
|
+
const account = new AccountEntity(defaultAccountDto());
|
|
125
124
|
it(`should not parse: ${_props.scenario}`, () => {
|
|
126
125
|
expect.assertions(1);
|
|
127
|
-
expect(() => ParseAppUrlService.parse(_props.url)).toThrow(errorMatchPattern);
|
|
126
|
+
expect(() => ParseAppUrlService.parse(account, _props.url)).toThrow(errorMatchPattern);
|
|
128
127
|
});
|
|
129
128
|
});
|
|
130
129
|
});
|
|
131
130
|
describe("ParseAppUrlService:getContext", () => {
|
|
132
131
|
it(`should return regex based on trusted domain`, () => {
|
|
133
132
|
expect.assertions(1);
|
|
134
|
-
|
|
133
|
+
const account = new AccountEntity(defaultAccountDto());
|
|
134
|
+
expect(ParseAppUrlService.getRegex(account)).toBe("^https\\:\\/\\/passbolt\\.local/?(/app.*)?(#.*)?$");
|
|
135
135
|
});
|
|
136
136
|
it(`should escaped characters from domain`, () => {
|
|
137
|
-
|
|
137
|
+
const account = new AccountEntity(defaultAccountDto({ domain: "https://passbolt.local/#/" }));
|
|
138
138
|
expect.assertions(1);
|
|
139
|
-
expect(ParseAppUrlService.getRegex()).toBe("^https\\:\\/\\/passbolt\\.
|
|
139
|
+
expect(ParseAppUrlService.getRegex(account)).toBe("^https\\:\\/\\/passbolt\\.local\\/\\#\\//?(/app.*)?(#.*)?$");
|
|
140
140
|
});
|
|
141
141
|
});
|
|
142
142
|
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passbolt ~ Open source password manager for teams
|
|
3
|
+
* Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
4
|
+
*
|
|
5
|
+
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
|
6
|
+
* For full copyright and license information, please see the LICENSE.txt
|
|
7
|
+
* Redistributions of files must retain the above copyright notice.
|
|
8
|
+
*
|
|
9
|
+
* @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
|
|
10
|
+
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
|
11
|
+
* @link https://www.passbolt.com Passbolt(tm)
|
|
12
|
+
* @since 5.18.0
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import SessionCookieFlushService from "./sessionCookieFlushService";
|
|
16
|
+
import OfflineLogoutService from "./offlineLogoutService";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sign out a user authenticated online when the API is unavailable. The API is not called.
|
|
20
|
+
*/
|
|
21
|
+
class LocalLogoutService {
|
|
22
|
+
/**
|
|
23
|
+
* @constructor
|
|
24
|
+
* @param {AccountEntity} account The user account
|
|
25
|
+
* @param {ApiClientOptions} apiClientOptions The api client options
|
|
26
|
+
*/
|
|
27
|
+
constructor(account, apiClientOptions) {
|
|
28
|
+
this.sessionCookieFlushService = new SessionCookieFlushService(account);
|
|
29
|
+
this.offlineLogoutService = new OfflineLogoutService(account, apiClientOptions);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Remove the session cookies, then sign the user out as an offline logout does.
|
|
34
|
+
* @return {Promise<void>}
|
|
35
|
+
*/
|
|
36
|
+
async exec() {
|
|
37
|
+
await this.sessionCookieFlushService.flush();
|
|
38
|
+
await this.offlineLogoutService.exec();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default LocalLogoutService;
|