Skip to content

Commit

Permalink
Remove function that is not needed anymore
Browse files Browse the repository at this point in the history
Since the test and actual fn definition are equal and HTTP is allowed in every case, the test function is not needed anymore
  • Loading branch information
threema-donat committed Jul 3, 2024
1 parent ab22243 commit a519510
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 41 deletions.
32 changes: 0 additions & 32 deletions src/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,6 @@ pub trait HyperClientBuilder {

/// Create a hyper::Client
fn build_hyper_client(self) -> Result<HttpClient<Self::Connector>, Error>;

/// Create a `hyper_util::client::legacy::Client` for tests (HTTPS not required)
#[doc(hidden)]
fn build_test_hyper_client(self) -> HttpClient<Self::Connector>;
}

#[cfg(feature = "hyper-rustls")]
Expand Down Expand Up @@ -1035,10 +1031,6 @@ where
fn build_hyper_client(self) -> Result<HttpClient<Self::Connector>, Error> {
Ok(self.client)
}

fn build_test_hyper_client(self) -> HttpClient<Self::Connector> {
self.client
}
}

#[cfg(any(feature = "hyper-rustls", feature = "hyper-tls"))]
Expand Down Expand Up @@ -1085,26 +1077,6 @@ impl HyperClientBuilder for DefaultHyperClient {
self.timeout,
))
}

fn build_test_hyper_client(self) -> HttpClient<Self::Connector> {
#[cfg(feature = "hyper-rustls")]
let connector = hyper_rustls::HttpsConnectorBuilder::new()
.with_provider_and_native_roots(default_crypto_provider())
.unwrap()
.https_or_http()
.enable_http1()
.enable_http2()
.build();
#[cfg(all(not(feature = "hyper-rustls"), feature = "hyper-tls"))]
let connector = hyper_tls::HttpsConnector::new();

HttpClient::new(
hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new())
.pool_max_idle_per_host(0)
.build::<_, String>(connector),
self.timeout,
)
}
}

impl<C> HyperClientBuilder for HttpClient<C>
Expand All @@ -1121,10 +1093,6 @@ where
fn build_hyper_client(self) -> Result<HttpClient<Self::Connector>, Error> {
Ok(self)
}

fn build_test_hyper_client(self) -> HttpClient<Self::Connector> {
self
}
}

/// How should the acquired tokens be stored?
Expand Down
29 changes: 20 additions & 9 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ async fn create_device_flow_auth_with_timeout(
client = client.with_timeout(duration);
}

DeviceFlowAuthenticator::with_client(app_secret, client.build_test_hyper_client())
.flow_delegate(Box::new(FD))
.device_code_url(server.url_str("/code"))
.build()
.await
.unwrap()
DeviceFlowAuthenticator::with_client(
app_secret,
client
.build_hyper_client()
.expect("Hyper client to be built"),
)
.flow_delegate(Box::new(FD))
.device_code_url(server.url_str("/code"))
.build()
.await
.unwrap()
}

#[tokio::test]
Expand Down Expand Up @@ -270,7 +275,9 @@ async fn create_installed_flow_auth(
}
}

let client = DefaultHyperClient::default().build_test_hyper_client();
let client = DefaultHyperClient::default()
.build_hyper_client()
.expect("Hyper client to be built");
let mut builder = InstalledFlowAuthenticator::with_client(app_secret, method, client.clone())
.flow_delegate(Box::new(FD(client)));

Expand Down Expand Up @@ -390,7 +397,9 @@ async fn create_service_account_auth(server: &Server) -> DefaultAuthenticator {

ServiceAccountAuthenticator::with_client(
key,
DefaultHyperClient::default().build_test_hyper_client(),
DefaultHyperClient::default()
.build_hyper_client()
.expect("Hyper client to be built"),
)
.build()
.await
Expand Down Expand Up @@ -723,7 +732,9 @@ async fn test_default_application_credentials_from_metadata_server() {
};
let authenticator = match ApplicationDefaultCredentialsAuthenticator::with_client(
opts,
DefaultHyperClient::default().build_test_hyper_client(),
DefaultHyperClient::default()
.build_hyper_client()
.expect("Hyper client to be built"),
)
.await
{
Expand Down

0 comments on commit a519510

Please sign in to comment.