Skip to content

Commit c62a911

Browse files
committed
tests: inline tls_config() helper
And avoid unused code warnings for redundant verifier configs.
1 parent 6b4102a commit c62a911

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ webpki-roots = { version = "0.26", optional = true }
3838
futures-util = { version = "0.3", default-features = false }
3939

4040
[dev-dependencies]
41+
cfg-if = "1"
4142
http-body-util = "0.1"
4243
hyper-util = { version = "0.1", default-features = false, features = ["server-auto"] }
4344
rustls = { version = "0.23", default-features = false, features = ["tls12"] }

src/connector.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -251,29 +251,23 @@ mod tests {
251251
assert_eq!(message, "unsupported scheme http");
252252
}
253253

254-
fn tls_config() -> rustls::ClientConfig {
255-
#[cfg(feature = "rustls-platform-verifier")]
256-
return rustls::ClientConfig::builder()
257-
.with_platform_verifier()
258-
.with_no_client_auth();
259-
260-
#[cfg(feature = "rustls-native-certs")]
261-
return rustls::ClientConfig::builder()
262-
.with_native_roots()
263-
.unwrap()
264-
.with_no_client_auth();
265-
266-
#[cfg(feature = "webpki-roots")]
267-
return rustls::ClientConfig::builder()
268-
.with_webpki_roots()
269-
.with_no_client_auth();
270-
}
271-
272254
async fn connect(
273255
allow: Allow,
274256
scheme: Scheme,
275257
) -> Result<MaybeHttpsStream<TokioIo<TcpStream>>, BoxError> {
276-
let builder = HttpsConnectorBuilder::new().with_tls_config(tls_config());
258+
let config_builder = rustls::ClientConfig::builder();
259+
cfg_if::cfg_if! {
260+
if #[cfg(feature = "rustls-platform-verifier")] {
261+
let config_builder = config_builder.with_platform_verifier();
262+
} else if #[cfg(feature = "rustls-native-certs")] {
263+
let config_builder = config_builder.with_native_roots().unwrap();
264+
} else if #[cfg(feature = "webpki-roots")] {
265+
let config_builder = config_builder.with_webpki_roots();
266+
}
267+
}
268+
let config = config_builder.with_no_client_auth();
269+
270+
let builder = HttpsConnectorBuilder::new().with_tls_config(config);
277271
let mut service = match allow {
278272
Allow::Https => builder.https_only(),
279273
Allow::Any => builder.https_or_http(),

0 commit comments

Comments
 (0)