| 1 | package guestos |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "os/exec" |
| 6 | "path/filepath" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | |
| 12 | |
| 13 | func TestMacSettingsRoutesOpenSpecificPermissionPanes(t *testing.T) { |
| 14 | dir := t.TempDir() |
| 15 | harness := `import AppKit |
| 16 | struct Failure: Error { init(_ code: Int, _ reason: String) {} } |
| 17 | func consoleUser() throws -> String { throw Failure(1,"unused") } |
| 18 | func requireGuest() throws { throw Failure(1,"unused") } |
| 19 | enum MacSetupPassword { |
| 20 | static func runStream() -> Never { fatalError("unused") } |
| 21 | static func passwordFocused(_ app: NSRunningApplication, window: CGRect) -> Bool { false } |
| 22 | } |
| 23 | @main struct Check { |
| 24 | @MainActor static func main() { |
| 25 | for purpose in ["projects", "screen", "input"] { |
| 26 | guard let url = MacMaintenance.settingsURL(for: purpose) else { exit(1) } |
| 27 | print("\(purpose) \(url.absoluteString)") |
| 28 | } |
| 29 | guard MacMaintenance.settingsURL(for: "untrusted") == nil else { exit(2) } |
| 30 | } |
| 31 | } |
| 32 | ` |
| 33 | input := filepath.Join(dir, "check.swift") |
| 34 | if err := os.WriteFile(input, []byte(harness), 0600); err != nil { |
| 35 | t.Fatal(err) |
| 36 | } |
| 37 | program := filepath.Join(dir, "settings-check") |
| 38 | source := filepath.Join("..", "..", "scripts", "guest-os", "macos-maintenance.swift") |
| 39 | compile := exec.CommandContext(t.Context(), "xcrun", "swiftc", "-parse-as-library", source, input, "-o", program) |
| 40 | if output, err := compile.CombinedOutput(); err != nil { |
| 41 | t.Fatalf("compile settings router: %v\n%s", err, output) |
| 42 | } |
| 43 | output, err := exec.CommandContext(t.Context(), program).CombinedOutput() |
| 44 | if err != nil { |
| 45 | t.Fatalf("settings routes: %v\n%s", err, output) |
| 46 | } |
| 47 | want := []string{ |
| 48 | "projects x-apple.systempreferences:com.apple.ExtensionsPreferences?extensionPointIdentifier=com.apple.fskit.fsmodule", |
| 49 | "screen x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture", |
| 50 | "input x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility", |
| 51 | } |
| 52 | if strings.TrimSpace(string(output)) != strings.Join(want, "\n") { |
| 53 | t.Fatalf("permission routes lost the specific destination: %s", output) |
| 54 | } |
| 55 | } |