From b791d7f61053ab7b4fdcb27837e7c19895856b70 Mon Sep 17 00:00:00 2001 From: "Adam H. Leventhal" Date: Sat, 14 Sep 2024 15:53:07 -0700 Subject: [PATCH] another client --- nexus/tests/integration_tests/authn_http.rs | 31 +++++++++++++-------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/nexus/tests/integration_tests/authn_http.rs b/nexus/tests/integration_tests/authn_http.rs index c8eb089c16..73066220c4 100644 --- a/nexus/tests/integration_tests/authn_http.rs +++ b/nexus/tests/integration_tests/authn_http.rs @@ -9,9 +9,9 @@ // such invalid requests. use async_trait::async_trait; +use bytes::Bytes; use chrono::{DateTime, Duration, Utc}; use dropshot::endpoint; -use dropshot::test_util::read_json; use dropshot::test_util::LogContext; use dropshot::test_util::TestContext; use dropshot::ApiDescription; @@ -229,6 +229,7 @@ async fn whoami_request( testctx: &TestContext, ) -> Result { let client_testctx = &testctx.client_testctx; + let mut builder = hyper::Request::builder() .method(http::method::Method::GET) .uri(client_testctx.url("/whoami")); @@ -243,21 +244,27 @@ async fn whoami_request( } let request = builder - .body(dropshot::Body::empty()) + .body(Bytes::new()) .expect("attempted to construct invalid request"); - let mut response = hyper::Client::new() - .request(request) + let response = reqwest::Client::new() + .execute(request.try_into().expect("request conversion failed")) .await .expect("failed to make request"); - if response.status() == http::StatusCode::OK { - let whoami: WhoamiResponse = read_json(&mut response).await; - info!(&testctx.log, "whoami response"; "whoami" => ?whoami); - Ok(whoami) - } else { - let error_body: HttpErrorResponseBody = read_json(&mut response).await; - info!(&testctx.log, "whoami error"; "error" => ?error_body); - Err((response.status(), error_body)) + + match response.status() { + reqwest::StatusCode::OK => { + let whoami = response.json().await.expect("deserialization failed"); + info!(&testctx.log, "whoami response"; "whoami" => ?whoami); + Ok(whoami) + } + + status => { + let error_body: HttpErrorResponseBody = + response.json().await.expect("deserialization failed"); + info!(&testctx.log, "whoami error"; "error" => ?error_body); + Err((status, error_body)) + } } }