Skip to content

Commit 5addedc

Browse files
committed
bad certificate can lead to errSSLHandshakeFail or errSSLBadCert
1 parent 364d106 commit 5addedc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Diff for: Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class HTTPClientNIOTSTests: XCTestCase {
6363
_ = try httpClient.get(url: "https://localhost:\(httpBin.port)/get").wait()
6464
XCTFail("This should have failed")
6565
} catch let error as HTTPClient.NWTLSError {
66-
XCTAssertEqual(error.status, errSSLHandshakeFail)
66+
XCTAssert(error.status == errSSLHandshakeFail || error.status == errSSLBadCert,
67+
"unexpected NWTLSError with status \(error.status)")
6768
} catch {
6869
XCTFail("Error should have been NWTLSError not \(type(of: error))")
6970
}

Diff for: Tests/AsyncHTTPClientTests/HTTPClientTests.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,12 @@ class HTTPClientTests: XCTestCase {
901901
XCTFail("Unexpected error: \(error)")
902902
continue
903903
}
904-
XCTAssertEqual(clientError.status, errSSLHandshakeFail)
904+
// We're speaking TLS to a plain text server. This will cause the handshake to fail but given
905+
// that the bytes "HTTP/1.1" aren't the start of a valid TLS packet, we can also get
906+
// errSSLPeerProtocolVersion because the first bytes contain the version.
907+
XCTAssert(clientError.status == errSSLHandshakeFail ||
908+
clientError.status == errSSLPeerProtocolVersion,
909+
"unexpected NWTLSError with status \(clientError.status)")
905910
#endif
906911
} else {
907912
guard let clientError = error as? NIOSSLError, case NIOSSLError.handshakeFailed = clientError else {

0 commit comments

Comments
 (0)