Reputation: 3393
For my macOS desktop application's UI test target, I need to be able to run command line tools (specifically git) to verify some application actions, but I get an error that it cannot be run in the app sandbox.
I never explicitly enabled sandboxing for either my app or for the test target, so I'm having trouble figuring out how to turn it off. There is no entitlements file, and I can't find any target settings that seem to relate to sandboxing.
So is it possible to disable sandboxing for a UI test target? I know workarounds could include copying git into the bundle, or having the user explicitly select the tool, but neither of those seems really desirable.
Update: I tried copying git into the test bundle to run from there, but still got the same error.
Update 2: You can turn off sandboxing for the test bundle, but the test runner which Xcode builds automatically is still sandboxed (and unable to load an unsigned bundle), and AFAICT there is no way to change how the runner is built. Am I wrong?
Upvotes: 3
Views: 3475
Reputation: 71
Create .entitlements file with
<key>com.apple.security.app-sandbox</key>
<false/>
and specify CODE_SIGN_ENTITLEMENTS for your UI Tests bundle(via xcconfig or Build Settings -> Signing). Xcode will use value for this entitlement for test runner application.
Upvotes: 7
Reputation: 3393
The fix that worked for me was to copy git into the bundle, making sure that it's code signed during the build. Then it can be run from the sandboxed test runner.
The catch is that the binary at /usr/bin/git
is not the real git tool, it's a placeholder that forwards to xcrun
which finds your active Xcode installation and runs the copy of git inside that app bundle, and you can't do any of that inside the sandbox. So you have to copy it directly out of Xcode.
Like this:
Bundle(identifier: YourTestBundleID).url(forAuxiliaryExecutable: "git")
Upvotes: 1