iOS13 beta, Xcode11 b2 App Transport Security Exceptions

We have a test app that performs http requests (using NSURLSession) to a local server on localhost. Since Xcode11b2 (it is working on b1) we are receiving the following error when we are running our UI tests (ui test runner):

Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection."

On the plist of this test app we have defined the following:

NSAppTransportSecurity

NSAllowsArbitraryLoads

NSExceptionDomains

localhost

NSTemporaryExceptionAllowsInsecureHTTPLoads

Is there anything new we need to modify for iOS13?
Thanks!

Replies

I've submitted a feedback for this issue FB6553376 - It's affecting the UI test runner app

On further investigation it seems that App Transport Security is now enforced for the UI test runner application in the latest beta.


To my knowledge there isn't an official mechanism to update the Info.plist of the test runner application, the Info.plist within the test target is for the UI test bundle which is embedded within the test runner application.


I did find a workaround:


Adding the following script as a Test Pre-Action in the scheme (which inherits build settings from the UI test target):


TEST_RUNNER="$TARGET_BUILD_DIR/.."
INFO_PLIST="$TEST_RUNNER/Info.plist"

# Add NSAppTransportSecurity setting to allow localhost http connections
plutil -replace NSAppTransportSecurity -json '{"NSAllowsLocalNetworking": true}' $INFO_PLIST

# Code Sign
xcrun codesign --force --sign - --timestamp=none $TEST_RUNNER


We have to manually patch the Info.plist of the test runner application after test target is built.


I understand the importance of consistency of the simulator behaviour regarding App Transport Security for all applications including the UI test runner. However it would be a real shame to lose out on the ability to make requests to local servers from within the test runner to aid and enhance the testing possibilities in Xcode.


Some suggestions on how this could be officially supported:


- Respect the settings in the UI test bundle's Info.plist
- Replicate the App Transport Security settings of the main application being tested

This has been resolved!


Xcode 11 beta 4 allows arbitrary network requests from the UI test runner again (no need for the workaround).