@@ -219,22 +219,35 @@ mod tests {
219219 use super :: HttpsConnector ;
220220 use crate :: { ConfigBuilderExt , HttpsConnectorBuilder } ;
221221
222- fn tls_config ( ) -> rustls:: ClientConfig {
223- #[ cfg( feature = "rustls-platform-verifier" ) ]
224- return rustls:: ClientConfig :: builder ( )
225- . with_platform_verifier ( )
226- . with_no_client_auth ( ) ;
222+ #[ tokio:: test]
223+ async fn connects_https ( ) {
224+ oneshot ( https_or_http_connector ( ) , https_uri ( ) )
225+ . await
226+ . unwrap ( ) ;
227+ }
227228
228- #[ cfg( feature = "rustls-native-certs" ) ]
229- return rustls:: ClientConfig :: builder ( )
230- . with_native_roots ( )
231- . unwrap ( )
232- . with_no_client_auth ( ) ;
229+ #[ tokio:: test]
230+ async fn connects_http ( ) {
231+ oneshot ( https_or_http_connector ( ) , http_uri ( ) )
232+ . await
233+ . unwrap ( ) ;
234+ }
233235
234- #[ cfg( feature = "webpki-roots" ) ]
235- return rustls:: ClientConfig :: builder ( )
236- . with_webpki_roots ( )
237- . with_no_client_auth ( ) ;
236+ #[ tokio:: test]
237+ async fn connects_https_only ( ) {
238+ oneshot ( https_only_connector ( ) , https_uri ( ) )
239+ . await
240+ . unwrap ( ) ;
241+ }
242+
243+ #[ tokio:: test]
244+ async fn enforces_https_only ( ) {
245+ let message = oneshot ( https_only_connector ( ) , http_uri ( ) )
246+ . await
247+ . unwrap_err ( )
248+ . to_string ( ) ;
249+
250+ assert_eq ! ( message, "unsupported scheme http" ) ;
238251 }
239252
240253 fn https_or_http_connector ( ) -> HttpsConnector < HttpConnector > {
@@ -253,6 +266,24 @@ mod tests {
253266 . build ( )
254267 }
255268
269+ fn tls_config ( ) -> rustls:: ClientConfig {
270+ #[ cfg( feature = "rustls-platform-verifier" ) ]
271+ return rustls:: ClientConfig :: builder ( )
272+ . with_platform_verifier ( )
273+ . with_no_client_auth ( ) ;
274+
275+ #[ cfg( feature = "rustls-native-certs" ) ]
276+ return rustls:: ClientConfig :: builder ( )
277+ . with_native_roots ( )
278+ . unwrap ( )
279+ . with_no_client_auth ( ) ;
280+
281+ #[ cfg( feature = "webpki-roots" ) ]
282+ return rustls:: ClientConfig :: builder ( )
283+ . with_webpki_roots ( )
284+ . with_no_client_auth ( ) ;
285+ }
286+
256287 async fn oneshot < S , Req > ( mut service : S , req : Req ) -> Result < S :: Response , S :: Error >
257288 where
258289 S : Service < Req > ,
@@ -268,35 +299,4 @@ mod tests {
268299 fn http_uri ( ) -> Uri {
269300 Uri :: from_static ( "http://google.com" )
270301 }
271-
272- #[ tokio:: test]
273- async fn connects_https ( ) {
274- oneshot ( https_or_http_connector ( ) , https_uri ( ) )
275- . await
276- . unwrap ( ) ;
277- }
278-
279- #[ tokio:: test]
280- async fn connects_http ( ) {
281- oneshot ( https_or_http_connector ( ) , http_uri ( ) )
282- . await
283- . unwrap ( ) ;
284- }
285-
286- #[ tokio:: test]
287- async fn connects_https_only ( ) {
288- oneshot ( https_only_connector ( ) , https_uri ( ) )
289- . await
290- . unwrap ( ) ;
291- }
292-
293- #[ tokio:: test]
294- async fn enforces_https_only ( ) {
295- let message = oneshot ( https_only_connector ( ) , http_uri ( ) )
296- . await
297- . unwrap_err ( )
298- . to_string ( ) ;
299-
300- assert_eq ! ( message, "unsupported scheme http" ) ;
301- }
302302}
0 commit comments