Skip to content

Commit

Permalink
tests: inline tls_config() helper
Browse files Browse the repository at this point in the history
And avoid unused code warnings for redundant verifier configs.
  • Loading branch information
djc committed Dec 20, 2024
1 parent 4d0a441 commit ae297aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
32 changes: 13 additions & 19 deletions src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MaybeHttpsStream<TokioIo<TcpStream>>, 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(),
Expand Down

0 comments on commit ae297aa

Please sign in to comment.