-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure event data is sandboxed per app for all platforms (#113)
* fix: ensure event data is sandboxed per app for all platforms * chore: add SandboxHelper tests * chore: add Persistent storage test for macOS * chore: revert back to previous storage locations until we have a migration * chore: code clean up, efficiency improvements
- Loading branch information
1 parent
2aab265
commit 72da9f8
Showing
7 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Amplitude-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// SandboxHelper.swift | ||
// Amplitude-Swift | ||
// | ||
// Created by Justin Fiedler on 2/1/24. | ||
// | ||
|
||
import Foundation | ||
|
||
public class SandboxHelper { | ||
internal func getEnvironment() -> [String: String] { | ||
return ProcessInfo.processInfo.environment | ||
} | ||
|
||
public func isSandboxEnabled() -> Bool { | ||
#if os(macOS) | ||
// Check if macOS app has "App Sandbox" enabled | ||
let environment = getEnvironment() | ||
return environment["APP_SANDBOX_CONTAINER_ID"] != nil | ||
#else | ||
// Other platforms (iOS, tvOS, watchOs) are sandboxed by default | ||
return true | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// SandboxHelperTests.swift | ||
// Amplitude-SwiftTests | ||
// | ||
// Created by Justin Fiedler on 2/1/24. | ||
// | ||
|
||
import XCTest | ||
|
||
@testable import AmplitudeSwift | ||
|
||
final class SandboxHelperTests: XCTestCase { | ||
|
||
func testIsSandboxEnabled() { | ||
let sandboxHelper = SandboxHelper() | ||
let isSandboxed = sandboxHelper.isSandboxEnabled() | ||
|
||
#if os(macOS) | ||
XCTAssertEqual(isSandboxed, false) | ||
#else | ||
XCTAssertEqual(isSandboxed, true) | ||
#endif | ||
} | ||
|
||
#if os(macOS) | ||
func testIsSandboxEnabledWithMacOSAppSandbox() { | ||
let sandboxHelper = FakeSandboxHelperWithAppSandboxContainer() | ||
|
||
let isSandboxed = sandboxHelper.isSandboxEnabled() | ||
|
||
XCTAssertEqual(isSandboxed, true) | ||
} | ||
#endif | ||
} |