SSL Connections Issues when running Unit Tests from the command line SSL Connections Issues when running Unit Tests from the command line xcode xcode

SSL Connections Issues when running Unit Tests from the command line


Well, I ended up simply not checking certificates when we are testing under Jenkins.

As it is dangerous to have code which prevents such checking in your app — after all, it just might not get removed before you ship — you have to set both an environment variable and a compiler flag to activate it …

Post Scriptum:

Apple considers this a bug, rdar://problem/10406441


I'm having the SSL connection issues even within XCode (with XCode 4.5)

My solution was to switch of HTTPS Certificate Checking within the setUp of my Unit Tests:

- (void)setUp{    // Set-up code here.    [super setUp];    NSURL *URL = [NSURL URLWithString:<#Your SSL Address#>];    [NSURLRequest.class performSelector:NSSelectorFromString(@"setAllowsAnyHTTPSCertificate:forHost:")                             withObject:NSNull.null  // Just need to pass non-nil here to appear as a BOOL YES, using the NSNull.null singleton is pretty safe                             withObject:[URL host]];}

The esoteric format of the call I make is because this is a private method which refuses to compile with the latest toolchain. As this is only used in the Unit Test target it will not affect the production code and is therefore safe from attack, mistake and Apple AppStore approval. ymmv.