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