File tree 2 files changed +20
-2
lines changed
Sources/AsyncHTTPClient/NIOTransportServices
Tests/AsyncHTTPClientTests
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 116
116
secTrustRoots = try certificates. compactMap { certificate in
117
117
try SecCertificateCreateWithData ( nil , Data ( certificate. toDERBytes ( ) ) as CFData )
118
118
}
119
- case . some( . file) :
120
- preconditionFailure ( " TLSConfiguration.trustRoots.file is not supported " )
119
+ case . some( . file( let file) ) :
120
+ let certificates = try NIOSSLCertificate . fromPEMFile ( file)
121
+ secTrustRoots = try certificates. compactMap { certificate in
122
+ try SecCertificateCreateWithData ( nil , Data ( certificate. toDERBytes ( ) ) as CFData )
123
+ }
121
124
122
125
case . some( . default) , . none:
123
126
break
Original file line number Diff line number Diff line change @@ -108,4 +108,19 @@ class HTTPClientNIOTSTests: XCTestCase {
108
108
}
109
109
#endif
110
110
}
111
+
112
+ func testTrustRootCertificateLoadFail( ) {
113
+ guard isTestingNIOTS ( ) else { return }
114
+ #if canImport(Network)
115
+ let tlsConfig = TLSConfiguration . forClient ( trustRoots: . file( " not/a/certificate " ) )
116
+ XCTAssertThrowsError ( try tlsConfig. getNWProtocolTLSOptions ( ) ) { error in
117
+ switch error {
118
+ case let error as NIOSSL . NIOSSLError where error == . failedToLoadCertificate:
119
+ break
120
+ default :
121
+ XCTFail ( " \( error) " )
122
+ }
123
+ }
124
+ #endif
125
+ }
111
126
}
You can’t perform that action at this time.
0 commit comments