From 378dca11486e720e8fb2e371e2cd580e31f9658b Mon Sep 17 00:00:00 2001 From: Lewin Bormann Date: Mon, 18 Apr 2022 18:39:57 -0700 Subject: [PATCH] rustls upgrade: supply correct client in test cases --- Cargo.toml | 2 +- src/authenticator.rs | 4 ++-- tests/tests.rs | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 527bb25..640db83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ required-features = ["hyper-rustls", "service_account"] [features] default = ["hyper-rustls", "service_account"] -service_account = ["rustls", "rustls-pemfile"] +service_account = ["hyper-rustls", "rustls", "rustls-pemfile"] [dependencies] anyhow = "1.0.38" diff --git a/src/authenticator.rs b/src/authenticator.rs index ed0ae7b..23946b8 100644 --- a/src/authenticator.rs +++ b/src/authenticator.rs @@ -325,14 +325,14 @@ impl ApplicationDefaultCredentialsAuthenticator { pub async fn builder( opts: ApplicationDefaultCredentialsFlowOpts, ) -> ApplicationDefaultCredentialsTypes { - Self::with_client(DefaultHyperClient, opts).await + Self::with_client(opts, DefaultHyperClient).await } /// Use the builder pattern to deduce which model of authenticator should be used and allow providing a hyper client #[cfg(feature = "service_account")] pub async fn with_client( - client: C, opts: ApplicationDefaultCredentialsFlowOpts, + client: C, ) -> ApplicationDefaultCredentialsTypes where C: HyperClientBuilder, diff --git a/tests/tests.rs b/tests/tests.rs index 33e8f61..342cbdf 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -44,7 +44,7 @@ async fn create_device_flow_auth(server: &Server) -> DefaultAuthenticator { } } - DeviceFlowAuthenticator::builder(app_secret) + DeviceFlowAuthenticator::with_client(app_secret, DefaultHyperClient.build_test_hyper_client()) .flow_delegate(Box::new(FD)) .device_code_url(server.url_str("/code")) .build() @@ -215,8 +215,9 @@ async fn create_installed_flow_auth( } } - let mut builder = InstalledFlowAuthenticator::builder(app_secret, method) - .flow_delegate(Box::new(FD(DefaultHyperClient.build_test_hyper_client()))); + let client = DefaultHyperClient.build_test_hyper_client(); + let mut builder = InstalledFlowAuthenticator::with_client(app_secret, method, client.clone()) + .flow_delegate(Box::new(FD(client))); builder = if let Some(filename) = filename { builder.persist_tokens_to_disk(filename) @@ -326,7 +327,7 @@ async fn create_service_account_auth(server: &Server) -> DefaultAuthenticator { "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/yup-test-sa-1%40yup-test-243420.iam.gserviceaccount.com" }); - ServiceAccountAuthenticator::builder(key) + ServiceAccountAuthenticator::with_client(key, DefaultHyperClient.build_test_hyper_client()) .build() .await .unwrap() @@ -622,7 +623,7 @@ async fn test_default_application_credentials_from_metadata_server() { let opts = ApplicationDefaultCredentialsFlowOpts { metadata_url: Some(server.url("/token").to_string()), }; - let authenticator = match ApplicationDefaultCredentialsAuthenticator::builder(opts).await { + let authenticator = match ApplicationDefaultCredentialsAuthenticator::with_client(opts, DefaultHyperClient.build_test_hyper_client()).await { ApplicationDefaultCredentialsTypes::InstanceMetadata(auth) => auth.build().await.unwrap(), _ => panic!("We are not testing service account adc model"), };