3 Replies
      Latest reply on Nov 15, 2019 12:56 PM by Uncommon
      Uncommon Level 1 Level 1 (0 points)

        Is there a way to turn off the sandbox for my UI test target?

         

        My app works with git repositories, so in my tests I want to call out to command-line git to verify the results. But when I try, I get an error that git can't be run from within an app sandbox. Since I never explicitly enabled sandboxing for the app or the tests, I'm having trouble finding how to turn it off. Is it possible? Or will I have to copy git into the test bundle so I can run it from there?

        • Re: Turning off sandbox for UI test target
          Uncommon Level 1 Level 1 (0 points)

          I tried copying git to the test bundle, but still got the same error.

           

          How I did it:

          • Created a copy files phase to copy /usr/bin/git into the bundle's executable folder, with "code sign on copy" checked
          • Used Bundle(identifier: ···)!.url(forAuxiliaryExecutable("git") to find it at runtime
          • Set it as the launchPath of a Process object (rather than /usr/bin/git like I was before)
          • Re: Turning off sandbox for UI test target
            Uncommon Level 1 Level 1 (0 points)

            I tried adding CODE_SiGNING_ALLOWED=NO to the build settings for my test target, and it built successfully, but the tests wouldn't run since the test runner is still signed so it couldn't run an unsigned test bundle.

             

            Is there a way to un-codesign an application? Maybe I can do that to the test runner before it runs.

            • Re: Turning off sandbox for UI test target
              Uncommon Level 1 Level 1 (0 points)

              It turns out the fix was to copy git out of Xcode.app, rather than using the one in /usr/bin which is just a little placeholder that forwards to xcrun, and that breaks the sandbox.