Skip to content

Commit 8add6b8

Browse files
authored
bad certificate can lead to errSSLHandshakeFail or errSSLBadCert (#236)
1 parent 86db162 commit 8add6b8

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
@@ -915,7 +915,12 @@ class HTTPClientTests: XCTestCase {
915915
XCTFail("Unexpected error: \(error)")
916916
continue
917917
}
918-
XCTAssertEqual(clientError.status, errSSLHandshakeFail)
918+
// We're speaking TLS to a plain text server. This will cause the handshake to fail but given
919+
// that the bytes "HTTP/1.1" aren't the start of a valid TLS packet, we can also get
920+
// errSSLPeerProtocolVersion because the first bytes contain the version.
921+
XCTAssert(clientError.status == errSSLHandshakeFail ||
922+
clientError.status == errSSLPeerProtocolVersion,
923+
"unexpected NWTLSError with status \(clientError.status)")
919924
#endif
920925
} else {
921926
guard let clientError = error as? NIOSSLError, case NIOSSLError.handshakeFailed = clientError else {

0 commit comments

Comments
 (0)