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 2119f9c commit ea7a0da
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,29 +245,29 @@ 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(
https_only: bool,
https: bool,
) -> Result<MaybeHttpsStream<TokioIo<TcpStream>>, BoxError> {
let builder = HttpsConnectorBuilder::new().with_tls_config(tls_config());
let config_builder = rustls::ClientConfig::builder();
#[cfg(feature = "rustls-platform-verifier")]
let config_builder = config_builder.with_platform_verifier();
#[cfg(all(
not(feature = "rustls-platform-verifier"),
feature = "rustls-native-certs"
))]
let config_builder = config_builder
.with_native_roots()
.unwrap();
#[cfg(all(
not(feature = "rustls-platform-verifier"),
not(feature = "rustls-native-certs"),
feature = "webpki-roots"
))]
let config_builder = config_builder.with_webpki_roots();

let builder =
HttpsConnectorBuilder::new().with_tls_config(config_builder.with_no_client_auth());
let mut service = match https_only {
true => builder.https_only(),
false => builder.https_or_http(),
Expand Down

0 comments on commit ea7a0da

Please sign in to comment.