passbolt-browser-extension 5.16.1 → 5.17.0
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/CHANGELOG.md +105 -1
- package/RELEASE_NOTES.md +94 -4
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager/AppDelegate.swift +3 -3
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager/ViewController.swift +10 -10
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/SafariWebExtensionHandler.swift +5 -5
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/AbstractController.swift +5 -5
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/ErrorController.swift +2 -2
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/FetchController.swift +3 -3
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/OpenSafariSettingsController.swift +1 -1
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/SaveFileController.swift +2 -2
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/WriteClipboardController.swift +3 -3
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/services/fetch/SecureProfileSessionManager.swift +36 -30
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/services/fetch/fetchService.swift +24 -24
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/services/file/SaveFileService.swift +15 -15
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/utils/ErrorSerializer.swift +13 -13
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/utils/LocatedError.swift +3 -3
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/SafariWebExtensionHandlerTests.swift +3 -3
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/AbstractControllerTests.swift +2 -2
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/ErrorControllerTests.swift +1 -1
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/FetchControllerTests.swift +1 -1
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/OpenSafariSettingsControllerTests.swift +1 -1
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/SaveFileControllerTests.swift +1 -1
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/WriteClipboardControllerTests.swift +1 -1
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/services/fetch/FetchServiceTests.swift +1 -1
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/services/fetch/SecureProfileSessionManagerTests.swift +7 -7
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/utils/ErrorSerializerTests.swift +17 -17
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/utils/LocatedErrorTests.swift +12 -12
- package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager.xcodeproj/project.pbxproj +2 -4
- package/package.json +10 -7
- package/src/all/background_page/controller/accountRecovery/recoverAccountController.js +4 -0
- package/src/all/background_page/controller/accountRecovery/recoverAccountController.test.js +5 -1
- package/src/all/background_page/controller/informCallToActionController/informCallToActionController.js +4 -2
- package/src/all/background_page/controller/informCallToActionController/informCallToActionController.test.js +4 -2
- package/src/all/background_page/controller/mfaPolicy/mfaGetMfaSettingsController.test.js +13 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupAbortWebauthnCeremonyController.js +52 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupAbortWebauthnCeremonyController.test.js +54 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupBeginWebauthnCeremonyController.js +52 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupBeginWebauthnCeremonyController.test.js +54 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupDeleteWebauthnCredentialController.js +55 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupDeleteWebauthnCredentialController.test.js +55 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupFinishWebauthnCeremonyController.js +54 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupFinishWebauthnCeremonyController.test.js +54 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupGetWebauthnCredentialsController.js +54 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupGetWebauthnCredentialsController.test.js +61 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupGetWebauthnSettingsController.js +53 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupGetWebauthnSettingsController.test.js +57 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupHandleWebauthnCeremonyResultController.js +55 -0
- package/src/all/background_page/controller/mfaSetup/MfaSetupHandleWebauthnCeremonyResultController.test.js +52 -0
- package/src/all/background_page/controller/move/moveFolderController.js +12 -12
- package/src/all/background_page/controller/move/moveFolderController.test.js +31 -1
- package/src/all/background_page/controller/move/moveResourcesController.js +18 -5
- package/src/all/background_page/controller/move/moveResourcesController.test.js +68 -7
- package/src/all/background_page/controller/recover/completeRecoverController.js +4 -0
- package/src/all/background_page/controller/recover/completeRecoverController.test.js +5 -1
- package/src/all/background_page/controller/setup/completeSetupController.js +4 -0
- package/src/all/background_page/controller/setup/completeSetupController.test.js +5 -1
- package/src/all/background_page/error/webauthnAlreadyRunningCeremonyError.js +24 -0
- package/src/all/background_page/error/webauthnAuthenticatorAlreadyRegisteredError.js +26 -0
- package/src/all/background_page/error/webauthnCeremonyAbortedError.js +26 -0
- package/src/all/background_page/error/webauthnCeremonyCancelledError.js +26 -0
- package/src/all/background_page/error/webauthnCeremonyError.js +26 -0
- package/src/all/background_page/error/webauthnCeremonyNotFoundError.js +26 -0
- package/src/all/background_page/error/webauthnTLSCertificateError.js +24 -0
- package/src/all/background_page/event/appBootstrapEvents.js +32 -0
- package/src/all/background_page/event/appBootstrapEvents.test.js +31 -0
- package/src/all/background_page/event/folderEvents.js +5 -4
- package/src/all/background_page/event/informCallToActionEvents.js +3 -2
- package/src/all/background_page/event/mfaEvents.js +38 -1
- package/src/all/background_page/event/resourceEvents.js +9 -5
- package/src/all/background_page/index.js +16 -0
- package/src/all/background_page/model/entity/folder/foldersCollection.js +13 -9
- package/src/all/background_page/model/entity/folder/foldersCollection.test.data.js +35 -0
- package/src/all/background_page/model/entity/folder/foldersCollection.test.js +60 -0
- package/src/all/background_page/model/entity/mfa/mfaEnabledProviderEntity.js +11 -0
- package/src/all/background_page/model/entity/mfa/mfaEnabledProviderEntity.test.js +13 -0
- package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialEntity.js +126 -0
- package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialEntity.test.data.js +26 -0
- package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialEntity.test.js +105 -0
- package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialsCollection.js +52 -0
- package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialsCollection.test.data.js +22 -0
- package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialsCollection.test.js +60 -0
- package/src/all/background_page/model/entity/mfa/mfaWebauthnSettingsEntity.js +45 -0
- package/src/all/background_page/model/entity/mfa/mfaWebauthnSettingsEntity.test.data.js +17 -0
- package/src/all/background_page/model/entity/mfa/mfaWebauthnSettingsEntity.test.js +48 -0
- package/src/all/background_page/model/entity/mfa/webauthnCredentialCreationOptionsEntity.js +235 -0
- package/src/all/background_page/model/entity/mfa/webauthnCredentialCreationOptionsEntity.test.data.js +42 -0
- package/src/all/background_page/model/entity/mfa/webauthnCredentialCreationOptionsEntity.test.js +152 -0
- package/src/all/background_page/model/entity/mfa/webauthnRegistrationResponseEntity.js +72 -0
- package/src/all/background_page/model/entity/mfa/webauthnRegistrationResponseEntity.test.data.js +26 -0
- package/src/all/background_page/model/entity/mfa/webauthnRegistrationResponseEntity.test.js +83 -0
- package/src/all/background_page/model/entity/mfa/webauthnSetupCeremonyEntity.js +121 -0
- package/src/all/background_page/model/entity/mfa/webauthnSetupCeremonyEntity.test.data.js +36 -0
- package/src/all/background_page/model/entity/mfa/webauthnSetupCeremonyEntity.test.js +100 -0
- package/src/all/background_page/model/entity/permission/change/permissionChangesCollection.js +0 -59
- package/src/all/background_page/model/entity/permission/change/permissionChangesCollection.test.js +0 -333
- package/src/all/background_page/model/entity/userAndGroupSearchResultEntity/userAndGroupSearchResultEntity.js +1 -1
- package/src/all/background_page/model/entity/userAndGroupSearchResultEntity/userAndGroupSearchResultEntity.test.js +19 -1
- package/src/all/background_page/pagemod/accountRecoveryBootstrapPagemod.test.js +1 -1
- package/src/all/background_page/pagemod/appBootstrapPagemod.js +2 -1
- package/src/all/background_page/pagemod/appBootstrapPagemod.test.js +8 -8
- package/src/all/background_page/pagemod/authBootstrapPagemod.test.js +1 -1
- package/src/all/background_page/pagemod/pagemod.js +3 -1
- package/src/all/background_page/pagemod/pagemod.test.js +1 -1
- package/src/all/background_page/pagemod/publicWebsiteSignInPagemod.test.js +1 -1
- package/src/all/background_page/pagemod/recoverBootstrapPagemod.test.js +1 -1
- package/src/all/background_page/pagemod/setupBootstrapPagemod.test.js +1 -1
- package/src/all/background_page/pagemod/webIntegrationPagemod.test.js +1 -1
- package/src/all/background_page/sdk/port/portManager.js +13 -1
- package/src/all/background_page/sdk/port/portManager.test.js +98 -0
- package/src/all/background_page/service/api/mfa/webauthnApiService.js +76 -0
- package/src/all/background_page/service/api/mfa/webauthnApiService.test.js +119 -0
- package/src/all/background_page/service/api/mfa/webauthnSettingsApiService.js +44 -0
- package/src/all/background_page/service/api/mfa/webauthnSettingsApiService.test.js +56 -0
- package/src/all/background_page/service/auth/postLoginService.js +2 -1
- package/src/all/background_page/service/auth/postLoginService.test.js +1 -1
- package/src/all/background_page/service/auth/postLogoutService.js +2 -1
- package/src/all/background_page/service/auth/postLogoutService.test.js +24 -1
- package/src/all/background_page/service/extension/onExtensionUpdateAvailableService.test.js +2 -6
- package/src/all/background_page/service/group/groupUpdateSecretsCryptoService.js +1 -1
- package/src/all/background_page/service/group/groupUpdateService.js +1 -1
- package/src/all/background_page/service/group/groupUpdateService.test.js +3 -3
- package/src/all/background_page/service/localStorage/localStorageService.js +2 -0
- package/src/all/background_page/service/localStorage/localStorageService.test.js +3 -2
- package/src/all/background_page/service/mfa/validateWebauthnCreationOptionsService.js +41 -0
- package/src/all/background_page/service/mfa/validateWebauthnCreationOptionsService.test.js +52 -0
- package/src/all/background_page/service/mfa/webauthnSetupCeremonyService.js +266 -0
- package/src/all/background_page/service/mfa/webauthnSetupCeremonyService.test.js +437 -0
- package/src/all/background_page/service/move/deserializeConfirmedMovePermissions.js +41 -0
- package/src/all/background_page/service/move/deserializeConfirmedMovePermissions.test.js +80 -0
- package/src/all/background_page/service/move/moveOneFolderService.js +88 -135
- package/src/all/background_page/service/move/moveOneFolderService.test.js +774 -5237
- package/src/all/background_page/service/move/moveResourcesService.js +68 -40
- package/src/all/background_page/service/move/moveResourcesService.test.data.js +53 -0
- package/src/all/background_page/service/move/moveResourcesService.test.js +559 -2090
- package/src/all/background_page/service/offline/getOrFindOfflineSettingsService.js +2 -1
- package/src/all/background_page/service/offline/getOrFindOfflineSettingsService.test.js +23 -0
- package/src/all/background_page/service/permission/calculatePermissionsChangesService.js +172 -0
- package/src/all/background_page/service/permission/calculatePermissionsChangesService.test.js +370 -0
- package/src/all/background_page/service/rbac/getOrFindRbacService.js +2 -1
- package/src/all/background_page/service/resourceType/getOrFindResourceTypesService.js +2 -1
- package/src/all/background_page/service/resourceType/getOrFindResourceTypesService.test.js +19 -0
- package/src/all/background_page/service/sessionStorage/webauthnSetupCeremonySessionStorageService.js +62 -0
- package/src/all/background_page/service/sessionStorage/webauthnSetupCeremonySessionStorageService.test.js +60 -0
- package/src/all/background_page/service/sessionStorage/workersSessionStorage.js +30 -0
- package/src/all/background_page/service/sessionStorage/workersSessionStorage.test.js +55 -0
- package/src/all/background_page/service/share/shareFoldersService.js +20 -36
- package/src/all/background_page/service/share/shareFoldersService.test.js +236 -0
- package/src/all/background_page/service/tab/tabService.js +3 -2
- package/src/all/background_page/service/toolbar/toolbarService.js +13 -5
- package/src/all/background_page/service/ui/browserTab.service.js +6 -4
- package/src/all/background_page/service/ui/browserTab.service.test.js +19 -6
- package/src/all/background_page/service/user/getOrFindMeService.js +2 -1
- package/src/all/background_page/service/user/getOrFindMeService.test.js +17 -0
- package/src/all/background_page/service/worker/workerService.js +42 -11
- package/src/all/background_page/service/worker/workerService.test.js +70 -2
- package/src/all/contentScripts/js/app/App.js +2 -0
- package/src/all/contentScripts/js/controller/abortWebauthnSetupCeremonyContentScriptController.js +62 -0
- package/src/all/contentScripts/js/controller/abortWebauthnSetupCeremonyContentScriptController.test.js +44 -0
- package/src/all/contentScripts/js/controller/runWebauthnSetupCeremonyContentScriptController.js +65 -0
- package/src/all/contentScripts/js/controller/runWebauthnSetupCeremonyContentScriptController.test.js +70 -0
- package/src/all/contentScripts/js/event/webauthnSetupCeremonyEvents.js +33 -0
- package/src/all/contentScripts/js/service/webauthnSetupCeremonyContentScriptService.js +154 -0
- package/src/all/contentScripts/js/service/webauthnSetupCeremonyContentScriptService.test.js +252 -0
- package/src/all/locales/en-UK/common.json +0 -1
- package/src/all/webAccessibleResources/js/lib/port.js +106 -10
- package/src/all/webAccessibleResources/js/lib/port.test.js +174 -1
- package/src/chrome/manifest.json +2 -3
- package/src/chrome-mv3/index.js +6 -0
- package/src/chrome-mv3/manifest.json +3 -4
- package/src/firefox/manifest.json +2 -3
- package/src/safari/background_page/index.js +2 -1
- package/src/safari/background_page/service/cookies/cookiesService.js +9 -3
- package/src/safari/background_page/service/cookies/cookiesService.test.js +28 -1
- package/src/safari/manifest.json +2 -3
- package/test/mocks/mockWebExtensionPolyfill.js +2 -4
- package/src/all/background_page/service/move/calculatePermissionsChangesForMoveService.js +0 -113
- package/src/all/background_page/service/move/calculatePermissionsChangesForMoveService.test.js +0 -158
- package/src/all/background_page/service/move/confirmMoveStrategyService.js +0 -42
- package/src/all/background_page/service/move/confirmMoveStrategyService.test.js +0 -67
- /package/src/all/background_page/service/{move/calculatePermissionsChangesForMoveService.test.data.js → permission/calculatePermissionsChangesService.test.data.js} +0 -0
|
@@ -32,7 +32,7 @@ private extension Data {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
final class FetchService {
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
// Runs a fetch on the API with profile isolation.
|
|
37
37
|
// It expects a payload set from the extention with the possible property
|
|
38
38
|
// url: The URL to send to request to
|
|
@@ -45,10 +45,10 @@ final class FetchService {
|
|
|
45
45
|
let method = options["method"] as? String ?? "GET"
|
|
46
46
|
let headers = options["headers"] as? [String: String] ?? [:]
|
|
47
47
|
let cookies = options["cookies"] as? String
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
var httpRequest = URLRequest(url: url)
|
|
50
50
|
httpRequest.httpMethod = method
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
// Build the body: structured FormData array (may contain files) or plain string
|
|
53
53
|
if let formDataArray = options["body"] as? [[String: Any]] {
|
|
54
54
|
let boundary = UUID().uuidString
|
|
@@ -58,11 +58,11 @@ final class FetchService {
|
|
|
58
58
|
let body = options["body"] as? String ?? ""
|
|
59
59
|
httpRequest.httpBody = body.data(using: .utf8)
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
// SECURITY: Add cache-control headers to prevent response caching
|
|
63
63
|
httpRequest.setValue("no-cache, no-store, must-revalidate", forHTTPHeaderField: "Cache-Control")
|
|
64
64
|
httpRequest.setValue("no-cache", forHTTPHeaderField: "Pragma")
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
for header in headers {
|
|
67
67
|
// Skip Content-Type when we already set it for multipart
|
|
68
68
|
if header.key.lowercased() == "content-type" && httpRequest.value(forHTTPHeaderField: "Content-Type")?.contains("multipart") == true {
|
|
@@ -70,37 +70,37 @@ final class FetchService {
|
|
|
70
70
|
}
|
|
71
71
|
httpRequest.setValue(String(describing: header.value), forHTTPHeaderField: String(describing: header.key))
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
// Cookies from extension (already profile-isolated via browser.cookies)
|
|
75
75
|
if (cookies != nil) {
|
|
76
76
|
httpRequest.setValue(cookies, forHTTPHeaderField: "Cookie")
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
return try await doFetch(request: httpRequest, profileUUID: profileUUID)
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
/// Build a multipart/form-data body from the structured FormData array sent by JavaScript.
|
|
83
83
|
/// Each entry has: key, value, type ("SCALAR" or "FILE"), and optionally name (for files).
|
|
84
84
|
/// File values use the data URL format: "data:<mimeType>;base64,<base64Data>"
|
|
85
85
|
private static func buildMultipartBody(formDataArray: [[String: Any]], boundary: String) -> Data {
|
|
86
86
|
var body = Data()
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
for entry in formDataArray {
|
|
89
89
|
guard let key = entry["key"] as? String,
|
|
90
90
|
let value = entry["value"] as? String,
|
|
91
91
|
let type = entry["type"] as? String else {
|
|
92
92
|
continue
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
let sanitizedKey = sanitizeHeaderValue(key)
|
|
96
96
|
body.append("--\(boundary)\r\n")
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
if type == "FILE" {
|
|
99
99
|
let rawFilename = entry["name"] as? String ?? "file"
|
|
100
100
|
let sanitizedFilename = sanitizeFilename(rawFilename)
|
|
101
101
|
let (mimeType, fileData) = decodeDataURL(value)
|
|
102
102
|
let sanitizedMimeType = sanitizeHeaderValue(mimeType)
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
body.append("Content-Disposition: form-data; name=\"\(sanitizedKey)\"; filename=\"\(sanitizedFilename)\"\r\n")
|
|
105
105
|
body.append("Content-Type: \(sanitizedMimeType)\r\n\r\n")
|
|
106
106
|
body.append(fileData)
|
|
@@ -110,25 +110,25 @@ final class FetchService {
|
|
|
110
110
|
body.append("\(value)\r\n")
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
|
|
114
114
|
body.append("--\(boundary)--\r\n")
|
|
115
115
|
return body
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
/// Sanitize a filename for use in Content-Disposition headers.
|
|
119
119
|
/// Strips path traversal components, quotes, and CRLF characters.
|
|
120
120
|
private static func sanitizeFilename(_ raw: String) -> String {
|
|
121
121
|
let nameOnly = raw.components(separatedBy: CharacterSet(charactersIn: "/\\")).last ?? "file"
|
|
122
122
|
return sanitizeHeaderValue(nameOnly)
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
/// Sanitize a value interpolated into an HTTP header by removing quotes and CRLF.
|
|
126
126
|
private static func sanitizeHeaderValue(_ raw: String) -> String {
|
|
127
127
|
raw.replacingOccurrences(of: "\"", with: "")
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
.replacingOccurrences(of: "\r", with: "")
|
|
129
|
+
.replacingOccurrences(of: "\n", with: "")
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
|
|
132
132
|
/// Decode a data URL (e.g. "data:image/png;base64,iVBOR...") into its MIME type and binary data.
|
|
133
133
|
private static func decodeDataURL(_ dataURL: String) -> (mimeType: String, data: Data) {
|
|
134
134
|
let parts = dataURL.components(separatedBy: ",")
|
|
@@ -136,25 +136,25 @@ final class FetchService {
|
|
|
136
136
|
let base64Data = Data(base64Encoded: parts[1]) else {
|
|
137
137
|
return ("application/octet-stream", Data())
|
|
138
138
|
}
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
// Extract MIME type from "data:image/png;base64"
|
|
141
141
|
let header = parts[0]
|
|
142
142
|
let mimeType = header
|
|
143
143
|
.replacingOccurrences(of: "data:", with: "")
|
|
144
144
|
.components(separatedBy: ";")
|
|
145
145
|
.first ?? "application/octet-stream"
|
|
146
|
-
|
|
146
|
+
|
|
147
147
|
return (mimeType, base64Data)
|
|
148
148
|
}
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
// The actual fetch sent to the API using a profile-isolated session
|
|
151
151
|
private static func doFetch(request: URLRequest, profileUUID: String) async throws -> [String: Any] {
|
|
152
152
|
// SECURITY: Use profile-specific session, NEVER URLSession.shared
|
|
153
153
|
// This ensures cookies from one profile cannot leak to another
|
|
154
154
|
let session = SecureProfileSessionManager.session(forProfile: profileUUID)
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
let (data, response) = try await session.data(for: request)
|
|
157
|
-
|
|
157
|
+
|
|
158
158
|
guard let httpResponse = response as? HTTPURLResponse else {
|
|
159
159
|
throw NSError(domain: "FetchService", code: 500,
|
|
160
160
|
userInfo: [NSLocalizedDescriptionKey: "Response is not HTTP"])
|
|
@@ -172,7 +172,7 @@ final class FetchService {
|
|
|
172
172
|
|
|
173
173
|
let headers = httpResponse.allHeaderFields
|
|
174
174
|
let statusCode = httpResponse.statusCode
|
|
175
|
-
|
|
175
|
+
|
|
176
176
|
return [
|
|
177
177
|
"headers": headers,
|
|
178
178
|
"body": body,
|
|
@@ -28,7 +28,7 @@ enum SaveFileServiceError: LocalizedError {
|
|
|
28
28
|
case noBase64DataProvided
|
|
29
29
|
case invalidBase64Data
|
|
30
30
|
case destinationFolderIsNotAvailable
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
var errorDescription: String? {
|
|
33
33
|
switch self {
|
|
34
34
|
case .noBase64DataProvided:
|
|
@@ -39,7 +39,7 @@ enum SaveFileServiceError: LocalizedError {
|
|
|
39
39
|
return "The destination folder is not available or inaccessible"
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
var failureReason: String? {
|
|
44
44
|
switch self {
|
|
45
45
|
case .noBase64DataProvided:
|
|
@@ -50,7 +50,7 @@ enum SaveFileServiceError: LocalizedError {
|
|
|
50
50
|
return "Unable to access the Downloads directory"
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
var recoverySuggestion: String? {
|
|
55
55
|
switch self {
|
|
56
56
|
case .noBase64DataProvided:
|
|
@@ -67,53 +67,53 @@ final class SaveFileService {
|
|
|
67
67
|
|
|
68
68
|
public static func saveFile(_ payload: [String: Any]) throws -> String {
|
|
69
69
|
let filename = (payload["filename"] as? String) ?? "export.txt"
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
guard let base64Data = payload["base64Data"] as? String else {
|
|
72
72
|
throw locatedError(SaveFileServiceError.noBase64DataProvided)
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
guard let fileData = Data(base64Encoded: base64Data) else {
|
|
76
76
|
throw locatedError(SaveFileServiceError.invalidBase64Data)
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
guard let root = destinationRootURL() else {
|
|
80
80
|
throw locatedError(SaveFileServiceError.destinationFolderIsNotAvailable)
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
|
|
84
84
|
let dest = uniqueURL(in: root, suggestedName: filename)
|
|
85
85
|
try fileData.write(to: dest, options: .atomic)
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
// Open the finder to show the download file in it's location
|
|
88
88
|
NSWorkspace.shared.activateFileViewerSelecting([dest])
|
|
89
|
-
|
|
89
|
+
|
|
90
90
|
return dest.path
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
private static func destinationRootURL() -> URL? {
|
|
94
94
|
guard let downloads = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first else {
|
|
95
95
|
return nil
|
|
96
96
|
}
|
|
97
97
|
return downloads
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
private static func uniqueURL(in dir: URL, suggestedName: String) -> URL {
|
|
101
101
|
let baseURL = dir.appendingPathComponent(suggestedName)
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
if !FileManager.default.fileExists(atPath: baseURL.path) {
|
|
104
104
|
return baseURL
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
|
|
107
107
|
let ext = baseURL.pathExtension
|
|
108
108
|
let stem = baseURL.deletingPathExtension().lastPathComponent
|
|
109
|
-
|
|
109
|
+
|
|
110
110
|
for i in 1...99 {
|
|
111
111
|
let candidate = dir.appendingPathComponent("\(stem) (\(i))" + (ext.isEmpty ? "" : ".\(ext)"))
|
|
112
112
|
if !FileManager.default.fileExists(atPath: candidate.path) {
|
|
113
113
|
return candidate
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
// Fallback: UUID
|
|
118
118
|
return dir.appendingPathComponent("\(stem)-\(UUID().uuidString)" + (ext.isEmpty ? "" : ".\(ext)"))
|
|
119
119
|
}
|
|
@@ -25,38 +25,38 @@ import Foundation
|
|
|
25
25
|
|
|
26
26
|
/// Serializes Swift errors into dictionaries for JSON transmission to the JavaScript extension
|
|
27
27
|
struct ErrorSerializer {
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
/// Converts an Error to a dictionary with comprehensive debugging information
|
|
30
30
|
/// - Parameter error: The error to serialize
|
|
31
31
|
/// - Returns: A dictionary containing error details including message, type, domain, code, location, and cause chain
|
|
32
32
|
static func serialize(_ error: Error) -> [String: Any] {
|
|
33
33
|
// Check if this is a LocatedError wrapper and extract location + underlying error
|
|
34
34
|
let (actualError, locationInfo) = extractLocationInfo(from: error)
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
var errorDict: [String: Any] = [
|
|
37
37
|
"message": actualError.localizedDescription,
|
|
38
38
|
"type": String(describing: type(of: actualError))
|
|
39
39
|
]
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
// Add location info if available
|
|
42
42
|
if let location = locationInfo {
|
|
43
43
|
errorDict["file"] = location.file
|
|
44
44
|
errorDict["line"] = location.line
|
|
45
45
|
errorDict["function"] = location.function
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
// Extract NSError properties - Swift automatically bridges Error to NSError
|
|
49
49
|
let nsError = actualError as NSError
|
|
50
50
|
errorDict["domain"] = nsError.domain
|
|
51
51
|
errorDict["code"] = nsError.code
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
if let reason = nsError.localizedFailureReason {
|
|
54
54
|
errorDict["reason"] = reason
|
|
55
55
|
}
|
|
56
56
|
if let suggestion = nsError.localizedRecoverySuggestion {
|
|
57
57
|
errorDict["suggestion"] = suggestion
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
// Check for location info in NSError userInfo (for locatedNSError)
|
|
61
61
|
if locationInfo == nil {
|
|
62
62
|
if let file = nsError.userInfo["file"] as? String {
|
|
@@ -69,22 +69,22 @@ struct ErrorSerializer {
|
|
|
69
69
|
errorDict["function"] = function
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
// Recursively serialize the cause chain
|
|
74
74
|
if let underlying = nsError.userInfo[NSUnderlyingErrorKey] as? Error {
|
|
75
75
|
errorDict["cause"] = serialize(underlying)
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
// Include userInfo in debug builds for additional context
|
|
79
|
-
|
|
79
|
+
#if DEBUG
|
|
80
80
|
if !nsError.userInfo.isEmpty {
|
|
81
81
|
errorDict["userInfo"] = filterUserInfo(nsError.userInfo)
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
#endif
|
|
84
|
+
|
|
85
85
|
return errorDict
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
/// Extracts location information from a LocatedError wrapper
|
|
89
89
|
/// - Parameter error: The error to check
|
|
90
90
|
/// - Returns: A tuple of the actual error and optional location info
|
|
@@ -94,7 +94,7 @@ struct ErrorSerializer {
|
|
|
94
94
|
}
|
|
95
95
|
return (error, nil)
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
/// Filters userInfo dictionary to include only JSON-serializable types
|
|
99
99
|
/// - Parameter userInfo: The userInfo dictionary from an NSError
|
|
100
100
|
/// - Returns: A filtered dictionary containing only JSON-serializable values
|
|
@@ -29,15 +29,15 @@ struct LocatedError: LocalizedError {
|
|
|
29
29
|
let file: String
|
|
30
30
|
let line: Int
|
|
31
31
|
let function: String
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
var errorDescription: String? {
|
|
34
34
|
(underlyingError as? LocalizedError)?.errorDescription ?? underlyingError.localizedDescription
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
var failureReason: String? {
|
|
38
38
|
(underlyingError as? LocalizedError)?.failureReason
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
var recoverySuggestion: String? {
|
|
42
42
|
(underlyingError as? LocalizedError)?.recoverySuggestion
|
|
43
43
|
}
|
|
@@ -26,7 +26,7 @@ import Testing
|
|
|
26
26
|
|
|
27
27
|
@Suite("SafariWebExtensionHandler")
|
|
28
28
|
struct SafariWebExtensionHandlerTests {
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
@Test("SafariExtensionError raw values are stable")
|
|
31
31
|
func errorRawValues() {
|
|
32
32
|
#expect(SafariExtensionError.missingMessage.rawValue == 1)
|
|
@@ -35,7 +35,7 @@ struct SafariWebExtensionHandlerTests {
|
|
|
35
35
|
#expect(SafariExtensionError.controllerExecutionFailed.rawValue == 4)
|
|
36
36
|
#expect(SafariExtensionError.unknownError.rawValue == 999)
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
@Test("routes map each action to the correct controller")
|
|
40
40
|
func routesMappings() {
|
|
41
41
|
#expect(routes["save-file"] == SaveFileController.self)
|
|
@@ -44,7 +44,7 @@ struct SafariWebExtensionHandlerTests {
|
|
|
44
44
|
#expect(routes["write-clipboard"] == WriteClipboardController.self)
|
|
45
45
|
#expect(routes.count == 4)
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
@Test("routes returns nil for unknown action")
|
|
49
49
|
func routesUnknownAction() {
|
|
50
50
|
#expect(routes["nonexistent-action"] == nil)
|
|
@@ -26,12 +26,12 @@ import Testing
|
|
|
26
26
|
|
|
27
27
|
@Suite("AbstractController")
|
|
28
28
|
struct AbstractControllerTests {
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
struct StubController: AbstractController {
|
|
31
31
|
init() {}
|
|
32
32
|
func run(_ context: NSExtensionContext, _ payload: [String: Any], profileUUID: String) throws {}
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
@Test("a concrete type can conform to AbstractController and be instantiated")
|
|
36
36
|
func conformanceAndInstantiation() {
|
|
37
37
|
let _: any AbstractController = StubController()
|
|
@@ -26,7 +26,7 @@ import Testing
|
|
|
26
26
|
|
|
27
27
|
@Suite("OpenSafariSettingsController")
|
|
28
28
|
struct OpenSafariSettingsControllerTests {
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
@Test("OpenSafariSettingsController conforms to AbstractController")
|
|
31
31
|
func conformance() {
|
|
32
32
|
let _: any AbstractController = OpenSafariSettingsController()
|
|
@@ -26,11 +26,11 @@ import Testing
|
|
|
26
26
|
|
|
27
27
|
@Suite("SecureProfileSessionManager", .serialized)
|
|
28
28
|
struct SecureProfileSessionManagerTests {
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
init() {
|
|
31
31
|
SecureProfileSessionManager.invalidateAllSessions()
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
@Test("same profile returns same session, different profile returns different session")
|
|
35
35
|
func sessionCachingAndIsolation() {
|
|
36
36
|
let sessionA1 = SecureProfileSessionManager.session(forProfile: "profile-A")
|
|
@@ -39,7 +39,7 @@ struct SecureProfileSessionManagerTests {
|
|
|
39
39
|
#expect(sessionA1 === sessionA2)
|
|
40
40
|
#expect(sessionA1 !== sessionB)
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
@Test("session disables cookies, credentials, and caching for security")
|
|
44
44
|
func sessionSecurityConfiguration() {
|
|
45
45
|
let session = SecureProfileSessionManager.session(forProfile: "security-test")
|
|
@@ -50,7 +50,7 @@ struct SecureProfileSessionManagerTests {
|
|
|
50
50
|
#expect(config.urlCredentialStorage == nil)
|
|
51
51
|
#expect(config.requestCachePolicy == .reloadIgnoringLocalAndRemoteCacheData)
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
@Test("invalidateSession removes only that profile's session")
|
|
55
55
|
func invalidateSessionSelectiveRemoval() {
|
|
56
56
|
let sessionA = SecureProfileSessionManager.session(forProfile: "keep")
|
|
@@ -61,7 +61,7 @@ struct SecureProfileSessionManagerTests {
|
|
|
61
61
|
#expect(sessionA === sessionAAfter)
|
|
62
62
|
#expect(sessionB !== sessionBAfter)
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
@Test("invalidateAllSessions clears all cached sessions")
|
|
66
66
|
func invalidateAllSessions() {
|
|
67
67
|
let session1 = SecureProfileSessionManager.session(forProfile: "all-1")
|
|
@@ -72,13 +72,13 @@ struct SecureProfileSessionManagerTests {
|
|
|
72
72
|
#expect(session1 !== session1After)
|
|
73
73
|
#expect(session2 !== session2After)
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
@Test("session has a delegate set")
|
|
77
77
|
func sessionHasDelegate() {
|
|
78
78
|
let session = SecureProfileSessionManager.session(forProfile: "delegate-test")
|
|
79
79
|
#expect(session.delegate != nil)
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
@Test("concurrent session access and invalidation do not crash")
|
|
83
83
|
func concurrentAccess() async {
|
|
84
84
|
await withTaskGroup(of: Void.self) { group in
|
|
@@ -26,13 +26,13 @@ import Testing
|
|
|
26
26
|
|
|
27
27
|
@Suite("ErrorSerializer")
|
|
28
28
|
struct ErrorSerializerTests {
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
// MARK: - Test Helpers
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
enum MockLocalizedError: LocalizedError {
|
|
33
33
|
case withAllFields
|
|
34
34
|
case withMessageOnly
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
var errorDescription: String? {
|
|
37
37
|
switch self {
|
|
38
38
|
case .withAllFields: return "Full error description"
|
|
@@ -52,13 +52,13 @@ struct ErrorSerializerTests {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
enum MockPlainError: Error {
|
|
57
57
|
case generic
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
// MARK: - Tests
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
@Test("serialize includes message, type, domain, and code for a plain Error")
|
|
63
63
|
func serializePlainError() {
|
|
64
64
|
let dict = ErrorSerializer.serialize(MockPlainError.generic)
|
|
@@ -67,18 +67,18 @@ struct ErrorSerializerTests {
|
|
|
67
67
|
#expect(dict["domain"] is String)
|
|
68
68
|
#expect(dict["code"] is Int)
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
@Test("serialize includes reason and suggestion when present, omits them when nil")
|
|
72
72
|
func serializeLocalizedError() {
|
|
73
73
|
let full = ErrorSerializer.serialize(MockLocalizedError.withAllFields)
|
|
74
74
|
#expect(full["reason"] as? String == "Something went wrong")
|
|
75
75
|
#expect(full["suggestion"] as? String == "Try again")
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
let partial = ErrorSerializer.serialize(MockLocalizedError.withMessageOnly)
|
|
78
78
|
#expect(partial["reason"] == nil)
|
|
79
79
|
#expect(partial["suggestion"] == nil)
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
@Test("serialize extracts file, line, and function from a LocatedError")
|
|
83
83
|
func serializeLocatedError() {
|
|
84
84
|
let located = locatedError(MockLocalizedError.withAllFields, file: "Module/MyFile.swift", line: 42, function: "doStuff()")
|
|
@@ -89,7 +89,7 @@ struct ErrorSerializerTests {
|
|
|
89
89
|
#expect(dict["message"] as? String == "Full error description")
|
|
90
90
|
#expect(dict["type"] as? String == "MockLocalizedError")
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
@Test("LocatedError location takes precedence over NSError userInfo location")
|
|
94
94
|
func locatedErrorLocationTakesPrecedence() {
|
|
95
95
|
let innerNSError = NSError(domain: "Inner", code: 1, userInfo: [
|
|
@@ -104,7 +104,7 @@ struct ErrorSerializerTests {
|
|
|
104
104
|
#expect(dict["line"] as? Int == 1)
|
|
105
105
|
#expect(dict["function"] as? String == "locatedFunc()")
|
|
106
106
|
}
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
@Test("serialize recursively serializes the cause chain")
|
|
109
109
|
func serializeCauseChain() {
|
|
110
110
|
let rootCause = NSError(domain: "RootCause", code: 1, userInfo: [
|
|
@@ -114,22 +114,22 @@ struct ErrorSerializerTests {
|
|
|
114
114
|
NSLocalizedDescriptionKey: "top message",
|
|
115
115
|
NSUnderlyingErrorKey: rootCause
|
|
116
116
|
])
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
let dict = ErrorSerializer.serialize(topError)
|
|
119
119
|
#expect(dict["message"] as? String == "top message")
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
let cause = dict["cause"] as? [String: Any]
|
|
122
122
|
#expect(cause?["message"] as? String == "root cause message")
|
|
123
123
|
#expect(cause?["domain"] as? String == "RootCause")
|
|
124
124
|
}
|
|
125
|
-
|
|
125
|
+
|
|
126
126
|
@Test("serialize has no cause key when there is no underlying error")
|
|
127
127
|
func serializeNoCause() {
|
|
128
128
|
let dict = ErrorSerializer.serialize(MockPlainError.generic)
|
|
129
129
|
#expect(dict["cause"] == nil)
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
|
|
132
|
+
#if DEBUG
|
|
133
133
|
@Test("serialize includes filtered userInfo in DEBUG builds")
|
|
134
134
|
func serializeUserInfoInDebug() {
|
|
135
135
|
let nsError = NSError(domain: "Test", code: 1, userInfo: [
|
|
@@ -151,5 +151,5 @@ struct ErrorSerializerTests {
|
|
|
151
151
|
#expect(userInfo?["nullKey"] is NSNull)
|
|
152
152
|
#expect(userInfo?["arrayKey"] is [Any])
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
#endif
|
|
155
155
|
}
|