Skip to content

Commit b791d7f

Browse files
committed
another client
1 parent 355b03f commit b791d7f

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

nexus/tests/integration_tests/authn_http.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// such invalid requests.
1010

1111
use async_trait::async_trait;
12+
use bytes::Bytes;
1213
use chrono::{DateTime, Duration, Utc};
1314
use dropshot::endpoint;
14-
use dropshot::test_util::read_json;
1515
use dropshot::test_util::LogContext;
1616
use dropshot::test_util::TestContext;
1717
use dropshot::ApiDescription;
@@ -229,6 +229,7 @@ async fn whoami_request(
229229
testctx: &TestContext<WhoamiServerState>,
230230
) -> Result<WhoamiResponse, (http::StatusCode, HttpErrorResponseBody)> {
231231
let client_testctx = &testctx.client_testctx;
232+
232233
let mut builder = hyper::Request::builder()
233234
.method(http::method::Method::GET)
234235
.uri(client_testctx.url("/whoami"));
@@ -243,21 +244,27 @@ async fn whoami_request(
243244
}
244245

245246
let request = builder
246-
.body(dropshot::Body::empty())
247+
.body(Bytes::new())
247248
.expect("attempted to construct invalid request");
248249

249-
let mut response = hyper::Client::new()
250-
.request(request)
250+
let response = reqwest::Client::new()
251+
.execute(request.try_into().expect("request conversion failed"))
251252
.await
252253
.expect("failed to make request");
253-
if response.status() == http::StatusCode::OK {
254-
let whoami: WhoamiResponse = read_json(&mut response).await;
255-
info!(&testctx.log, "whoami response"; "whoami" => ?whoami);
256-
Ok(whoami)
257-
} else {
258-
let error_body: HttpErrorResponseBody = read_json(&mut response).await;
259-
info!(&testctx.log, "whoami error"; "error" => ?error_body);
260-
Err((response.status(), error_body))
254+
255+
match response.status() {
256+
reqwest::StatusCode::OK => {
257+
let whoami = response.json().await.expect("deserialization failed");
258+
info!(&testctx.log, "whoami response"; "whoami" => ?whoami);
259+
Ok(whoami)
260+
}
261+
262+
status => {
263+
let error_body: HttpErrorResponseBody =
264+
response.json().await.expect("deserialization failed");
265+
info!(&testctx.log, "whoami error"; "error" => ?error_body);
266+
Err((status, error_body))
267+
}
261268
}
262269
}
263270

0 commit comments

Comments
 (0)