From c62a91165d754f9631ba8401d1db73fb3e854652 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 20 Dec 2024 09:32:42 +0100 Subject: [PATCH] tests: inline tls_config() helper And avoid unused code warnings for redundant verifier configs. --- Cargo.toml | 1 + src/connector.rs | 32 +++++++++++++------------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a1829a3..c971434 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ webpki-roots = { version = "0.26", optional = true } futures-util = { version = "0.3", default-features = false } [dev-dependencies] +cfg-if = "1" http-body-util = "0.1" hyper-util = { version = "0.1", default-features = false, features = ["server-auto"] } rustls = { version = "0.23", default-features = false, features = ["tls12"] } diff --git a/src/connector.rs b/src/connector.rs index b6a7fb7..a0645ae 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -251,29 +251,23 @@ mod tests { assert_eq!(message, "unsupported scheme http"); } - fn tls_config() -> rustls::ClientConfig { - #[cfg(feature = "rustls-platform-verifier")] - return rustls::ClientConfig::builder() - .with_platform_verifier() - .with_no_client_auth(); - - #[cfg(feature = "rustls-native-certs")] - return rustls::ClientConfig::builder() - .with_native_roots() - .unwrap() - .with_no_client_auth(); - - #[cfg(feature = "webpki-roots")] - return rustls::ClientConfig::builder() - .with_webpki_roots() - .with_no_client_auth(); - } - async fn connect( allow: Allow, scheme: Scheme, ) -> Result>, BoxError> { - let builder = HttpsConnectorBuilder::new().with_tls_config(tls_config()); + let config_builder = rustls::ClientConfig::builder(); + cfg_if::cfg_if! { + if #[cfg(feature = "rustls-platform-verifier")] { + let config_builder = config_builder.with_platform_verifier(); + } else if #[cfg(feature = "rustls-native-certs")] { + let config_builder = config_builder.with_native_roots().unwrap(); + } else if #[cfg(feature = "webpki-roots")] { + let config_builder = config_builder.with_webpki_roots(); + } + } + let config = config_builder.with_no_client_auth(); + + let builder = HttpsConnectorBuilder::new().with_tls_config(config); let mut service = match allow { Allow::Https => builder.https_only(), Allow::Any => builder.https_or_http(),