Tests/OrgCoreTests/SandboxTests.swift
33 lines · 1309 bytes
1import Foundation
2import Testing
3@testable import OrgCore
4
5struct SandboxTests {
6 /// Tests run unsandboxed, so every switch keeps the Developer ID build's behaviour.
7 @Test func inactiveInTests() {
8 #expect(!Sandbox.isActive)
9 #expect(Sandbox.bookmarkCreationOptions() == [])
10 #expect(Sandbox.bookmarkResolutionOptions() == [])
11 }
12
13 @Test func detectedFromTheContainerVariable() {
14 #expect(!Sandbox.isActive(environment: [:]))
15 #if os(macOS)
16 #expect(Sandbox.isActive(environment: ["APP_SANDBOX_CONTAINER_ID": "sh.krz.orgstar"]))
17 #else
18 #expect(!Sandbox.isActive(environment: ["APP_SANDBOX_CONTAINER_ID": "sh.krz.orgstar"]))
19 #endif
20 }
21
22 @Test func bookmarksAreSecurityScopedInTheMacSandbox() {
23 #if os(macOS)
24 #expect(Sandbox.bookmarkCreationOptions(sandboxed: true) == .withSecurityScope)
25 #expect(Sandbox.bookmarkResolutionOptions(sandboxed: true) == .withSecurityScope)
26 #else
27 #expect(Sandbox.bookmarkCreationOptions(sandboxed: true) == [])
28 #expect(Sandbox.bookmarkResolutionOptions(sandboxed: true) == [])
29 #endif
30 #expect(Sandbox.bookmarkCreationOptions(sandboxed: false) == [])
31 #expect(Sandbox.bookmarkResolutionOptions(sandboxed: false) == [])
32 }
33}