diff --git a/src/authenticator.rs b/src/authenticator.rs index 95f09e4..ed0ae7b 100644 --- a/src/authenticator.rs +++ b/src/authenticator.rs @@ -727,6 +727,10 @@ pub trait HyperClientBuilder { /// Create a hyper::Client fn build_hyper_client(self) -> hyper::Client; + + /// Create a `hyper::Client` for tests (HTTPS not required) + #[doc(hidden)] + fn build_test_hyper_client(self) -> hyper::Client; } #[cfg(feature = "hyper-rustls")] @@ -781,6 +785,22 @@ impl HyperClientBuilder for DefaultHyperClient { .pool_max_idle_per_host(0) .build::<_, hyper::Body>(connector) } + + fn build_test_hyper_client(self) -> hyper::Client { + #[cfg(feature = "hyper-rustls")] + let connector = hyper_rustls::HttpsConnectorBuilder::new() + .with_native_roots() + .https_or_http() + .enable_http1() + .enable_http2() + .build(); + #[cfg(all(not(feature = "hyper-rustls"), feature = "hyper-tls"))] + let connector = hyper_tls::HttpsConnector::new(); + + hyper::Client::builder() + .pool_max_idle_per_host(0) + .build::<_, hyper::Body>(connector) + } } impl HyperClientBuilder for hyper::Client @@ -792,6 +812,10 @@ where fn build_hyper_client(self) -> hyper::Client { self } + + fn build_test_hyper_client(self) -> hyper::Client { + self + } } /// How should the acquired tokens be stored? diff --git a/tests/tests.rs b/tests/tests.rs index 13b97a3..33e8f61 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -216,7 +216,7 @@ async fn create_installed_flow_auth( } let mut builder = InstalledFlowAuthenticator::builder(app_secret, method) - .flow_delegate(Box::new(FD(DefaultHyperClient.build_hyper_client()))); + .flow_delegate(Box::new(FD(DefaultHyperClient.build_test_hyper_client()))); builder = if let Some(filename) = filename { builder.persist_tokens_to_disk(filename)