Так что я создал этот тестовый случай (в мишах затор существующего alamofire тестовых случаев):SecTrustPolicy неудача с собственной подписью сертификата
func testHTTPBasicAuthenticationWithValidCredentialsSelfSignedSuccess() {
// Given
let expectation = expectationWithDescription("\(URLString) 200")
var request: NSURLRequest?
var response: NSHTTPURLResponse?
var data: NSData?
var error: NSError?
setRootCertificateAsLoneAnchorCertificateForTrust(serverTrust)
let policies = [SecPolicyCreateBasicX509()]
SecTrustSetPolicies(serverTrust, policies)
// When
Alamofire.request(.GET, URLString)
.authenticate(user: user, password: password)
.response { responseRequest, responseResponse, responseData, responseError in
request = responseRequest
response = responseResponse
data = responseData
error = responseError
expectation.fulfill()
}
waitForExpectationsWithTimeout(defaultTimeout, handler: nil)
// Then
XCTAssertNotNil(request, "request should not be nil")
XCTAssertNotNil(response, "response should not be nil")
XCTAssertTrue(data?.length > 0, "Data not found.")
XCTAssertNil(error, "error should be nil")
}
корневого центр сертификации является самозаверяющим сертификатом для существующего вида, что работает.
Но я получаю эту ошибку обратно:
Test Suite 'Selected tests' started at 2015-08-12 12:46:37.512 Test Suite 'StageAuthentication' started at 2015-08-12 12:46:37.514 Test Case '-[Alamofire_iOS_Tests.StageAuthentication testHTTPBasicAuthenticationWithValidCredentialsSelfSignedSuccess]' started. 2015-08-12 12:46:37.663 xctest[3641:12220875] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) /Users/wynne_b/Alamofire/Tests/QuestAuthentication.swift:309: error: -[Alamofire_iOS_Tests.StageAuthentication testHTTPBasicAuthenticationWithValidCredentialsSelfSignedSuccess] : XCTAssertNotNil failed - response should not be nil /Users/wynne_b/Alamofire/Tests/QuestAuthentication.swift:310: error: -[Alamofire_iOS_Tests.StageAuthentication testHTTPBasicAuthenticationWithValidCredentialsSelfSignedSuccess] : XCTAssertTrue failed - Data not found. /Users/wynne_b/Alamofire/Tests/QuestAuthentication.swift:311: error: -[Alamofire_iOS_Tests.StageAuthentication testHTTPBasicAuthenticationWithValidCredentialsSelfSignedSuccess] : XCTAssertNil failed: "Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “portal.care180.com” which could put your confidential information at risk." UserInfo={NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “portal.care180.com” which could put your confidential information at risk., NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, NSUnderlyingError=0x7ae21c60 {Error Domain=kCFErrorDomainCFNetwork Code=-1202 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9813, _kCFStreamErrorCodeKey=-9813, _kCFStreamErrorDomainKey=3, kCFStreamPropertySSLPeerTrust=, kCFStreamPropertySSLPeerCertificates={type = immutable, count = 1, values = ( 0 : )}}}, _kCFStreamErrorCodeKey=-9813, NSErrorFailingURLStringKey= https://portal.care180.com/services/init.json , NSErrorPeerCertificateChainKey={type = immutable, count = 1, values = ( 0 : )}, NSErrorClientCertificateStateKey=0, NSURLErrorFailingURLPeerTrustErrorKey=, NSErrorFailingURLKey= https://portal.care180.com/services/init.json }" - error should be nil Test Case '-[Alamofire_iOS_Tests.StageAuthentication testHTTPBasicAuthenticationWithValidCredentialsSelfSignedSuccess]' failed (0.156 seconds). Test Suite 'StageAuthentication' failed at 2015-08-12 12:46:37.671. Executed 1 test, with 3 failures (0 unexpected) in 0.156 (0.157) seconds Test Suite 'Selected tests' failed at 2015-08-12 12:46:37.672. Executed 1 test, with 3 failures (0 unexpected) in 0.156 (0.160) seconds Program ended with exit code: 1
Извините за плотными: что я делаю не так? Или есть тест Alamofire, который делает это с другим сертификатом и хостом?