@@ -103,52 +103,52 @@ struct HTTP2TransportTLSEnabledTests {
103
103
let clientTransportConfig = self . makeDefaultTLSClientConfig (
104
104
for: clientTransport,
105
105
certificateKeyPairs: certificateKeyPairs,
106
- authority: nil
106
+ authority: " wrong-hostname "
107
107
)
108
108
let serverTransportConfig = self . makeDefaultTLSServerConfig (
109
109
for: serverTransport,
110
110
certificateKeyPairs: certificateKeyPairs
111
111
)
112
112
113
- try await self . withClientAndServer (
114
- clientConfig : clientTransportConfig ,
115
- serverConfig : serverTransportConfig
116
- ) { control in
117
- await #expect {
113
+ await #expect {
114
+ try await self . withClientAndServer (
115
+ clientConfig : clientTransportConfig ,
116
+ serverConfig : serverTransportConfig
117
+ ) { control in
118
118
try await self . executeUnaryRPC ( control: control)
119
- } throws: { error in
120
- let rootError = try #require( error as? RPCError )
121
- #expect( rootError. code == . unavailable)
122
-
123
- switch clientTransport {
124
- case . posix:
125
- #expect(
126
- rootError. message
127
- == " The server accepted the TCP connection but closed the connection before completing the HTTP/2 connection preface. "
128
- )
129
- let sslError = try #require( rootError. cause as? NIOSSLExtraError )
130
- guard sslError == . failedToValidateHostname else {
131
- Issue . record (
132
- " Should be a NIOSSLExtraError.failedToValidateHostname error, but was: \( String ( describing: rootError. cause) ) "
133
- )
134
- return false
135
- }
119
+ }
120
+ } throws: { error in
121
+ let rootError = try #require( error as? RPCError )
122
+ #expect( rootError. code == . unavailable)
136
123
137
- #if canImport(Network)
138
- case . transportServices:
139
- #expect( rootError. message. starts ( with: " Could not establish a connection to " ) )
140
- let nwError = try #require( rootError. cause as? NWError )
141
- guard case . tls( Security . errSSLBadCert) = nwError else {
142
- Issue . record (
143
- " Should be a NWError.tls(-9808/errSSLBadCert) error, but was: \( String ( describing: rootError. cause) ) "
144
- )
145
- return false
146
- }
147
- #endif
124
+ switch clientTransport {
125
+ case . posix:
126
+ #expect(
127
+ rootError. message
128
+ == " The server accepted the TCP connection but closed the connection before completing the HTTP/2 connection preface. "
129
+ )
130
+ let sslError = try #require( rootError. cause as? NIOSSLExtraError )
131
+ guard sslError == . failedToValidateHostname else {
132
+ Issue . record (
133
+ " Should be a NIOSSLExtraError.failedToValidateHostname error, but was: \( String ( describing: rootError. cause) ) "
134
+ )
135
+ return false
148
136
}
149
137
150
- return true
138
+ #if canImport(Network)
139
+ case . transportServices:
140
+ #expect( rootError. message. starts ( with: " Could not establish a connection to " ) )
141
+ let nwError = try #require( rootError. cause as? NWError )
142
+ guard case . tls( Security . errSSLBadCert) = nwError else {
143
+ Issue . record (
144
+ " Should be a NWError.tls(-9808/errSSLBadCert) error, but was: \( String ( describing: rootError. cause) ) "
145
+ )
146
+ return false
147
+ }
148
+ #endif
151
149
}
150
+
151
+ return true
152
152
}
153
153
}
154
154
@@ -174,44 +174,53 @@ struct HTTP2TransportTLSEnabledTests {
174
174
includeClientCertificateInTrustRoots: true
175
175
)
176
176
177
- try await self . withClientAndServer (
178
- clientConfig : clientTransportConfig ,
179
- serverConfig : serverTransportConfig
180
- ) { control in
181
- await #expect {
177
+ await #expect {
178
+ try await self . withClientAndServer (
179
+ clientConfig : clientTransportConfig ,
180
+ serverConfig : serverTransportConfig
181
+ ) { control in
182
182
try await self . executeUnaryRPC ( control: control)
183
- } throws: { error in
184
- let rootError = try #require( error as? RPCError )
185
- #expect( rootError. code == . unavailable)
186
- #expect(
187
- rootError. message
188
- == " The server accepted the TCP connection but closed the connection before completing the HTTP/2 connection preface. "
189
- )
183
+ }
184
+ } throws: { error in
185
+ let rootError = try #require( error as? RPCError )
186
+ #expect( rootError. code == . unavailable)
187
+ #expect(
188
+ rootError. message
189
+ == " The server accepted the TCP connection but closed the connection before completing the HTTP/2 connection preface. "
190
+ )
190
191
191
- switch clientTransport {
192
- case . posix:
193
- let sslError = try #require( rootError. cause as? NIOSSL . BoringSSLError)
194
- guard case . sslError = sslError else {
195
- Issue . record (
196
- " Should be a NIOSSL.sslError error, but was: \( String ( describing: rootError. cause) ) "
197
- )
198
- return false
199
- }
192
+ switch clientTransport {
193
+ case . posix:
194
+ let sslError = try #require( rootError. cause as? NIOSSL . BoringSSLError)
195
+ guard case . sslError = sslError else {
196
+ Issue . record (
197
+ " Should be a NIOSSL.sslError error, but was: \( String ( describing: rootError. cause) ) "
198
+ )
199
+ return false
200
+ }
200
201
201
- #if canImport(Network)
202
- case . transportServices:
203
- let nwError = try #require( rootError. cause as? NWError )
204
- guard case . tls( Security . errSSLPeerCertUnknown) = nwError else {
205
- Issue . record (
206
- " Should be a NWError.tls(-9829/errSSLPeerCertUnknown) error, but was: \( String ( describing: rootError. cause) ) "
207
- )
208
- return false
202
+ #if canImport(Network)
203
+ case . transportServices:
204
+ let nwError = try #require( rootError. cause as? NWError )
205
+ guard case . tls( Security . errSSLPeerCertUnknown) = nwError else {
206
+ // When the TLS handshake fails, the connection will be closed from the client.
207
+ // Network.framework will generally surface the right SSL error (in this case, an "unknown
208
+ // certificate" from the server), but it will sometimes instead return the broken pipe
209
+ // error caused by the underlying TLS handshake handler closing the connection:
210
+ // we should tolerate this.
211
+ if case . posix( POSIXErrorCode . EPIPE) = nwError {
212
+ return true
209
213
}
210
- #endif
211
- }
212
214
213
- return true
215
+ Issue . record (
216
+ " Should be a NWError.tls(-9829/errSSLPeerCertUnknown) error, but was: \( String ( describing: rootError. cause) ) "
217
+ )
218
+ return false
219
+ }
220
+ #endif
214
221
}
222
+
223
+ return true
215
224
}
216
225
}
217
226
@@ -341,7 +350,11 @@ struct HTTP2TransportTLSEnabledTests {
341
350
privateKey: try NIOSSLPrivateKey ( bytes: privateKeyBytes, format: . der)
342
351
)
343
352
let pkcs12Bytes = try bundle. serialize ( passphrase: password. utf8)
344
- let options = [ kSecImportExportPassphrase as String : password]
353
+ let options =
354
+ [
355
+ kSecImportExportPassphrase as String : password,
356
+ kSecImportToMemoryOnly: kCFBooleanTrue!,
357
+ ] as [ AnyHashable : Any ]
345
358
var rawItems : CFArray ?
346
359
let status = SecPKCS12Import (
347
360
Data ( pkcs12Bytes) as CFData ,
0 commit comments