NSURLConnection reports invalid cert for SSL requests running iOS unit tests

Originator:bchoate
Number:rdar://8385355 Date Originated:9/1/2010
Status:Open Resolved:
Product:iPhone SDK Product Version:4.0.2
Classification:Serious Bug Reproducible:Always
 
Summary:

When attempting to create unit tests to fetch requests via the 'https' URL scheme, I found that NSURLConnection was always returning an error that the domain had an invalid certificate, even when it did not. This only happens when running the unit tests under the testing harness of the iOS SDK.

Steps to Reproduce:

1. Create a new iPhone OS XCode project
2. Create a new Cocoa Touch Unit Test Bundle target
3. Switch target to Unit Test Bundle
4. Create a new Cocoa Touch Objective C Unit Test Case file, with the code found here (interface and implementation are both provided):
        https://gist.github.com/1e2e1adffd539bed5465
5. Invoke the Build command

Expected Results:

All tests pass.

Actual Results:

All tests fail.

Regression:

The NSError returned looks like this:

Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.google.com” which could put your confidential information at risk." UserInfo=0xd122a0 {NSErrorFailingURLStringKey=https://www.google.com/, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSErrorFailingURLKey=https://www.google.com/, NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.google.com” which could put your confidential information at risk., NSUnderlyingError=0xd135e0 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.google.com” which could put your confidential information at risk.", NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x20d0bc0>}

Notes:

I have consistently received this error, for any URL with a "https" scheme when running this test under the conditions given. The test passes when running as a normal executable code on the iOS SDK or on the MacOS SDK. The test even passes when running as a unit test for a MacOS project (versus a Cocoa Touch project and test suite).

I am running XCode 3.2.3, with component versions:
    Xcode IDE: 1688.0
    Xcode Core: 1691.0
    ToolSupport: 1591.0
and the iOS 4.0.2 SDK

Comments

I'm running into the very same issue. Did you find a way to workaround this issue?


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!