From 31420c3ff912af2f8ac9fd186e8870b82e01018d Mon Sep 17 00:00:00 2001 From: Firstyear Date: Wed, 23 Oct 2024 12:39:40 +1000 Subject: [PATCH] ipinfo should be single value (#3137) --- server/core/src/https/v1.rs | 6 ++--- server/testkit/tests/https_extractors.rs | 32 ++++++++++++------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/server/core/src/https/v1.rs b/server/core/src/https/v1.rs index d4b0ad5e2..c410a4b5d 100644 --- a/server/core/src/https/v1.rs +++ b/server/core/src/https/v1.rs @@ -3038,7 +3038,7 @@ pub async fn auth_valid( get, path = "/v1/debug/ipinfo", responses( - (status = 200, description = "Ok", body=Vec, content_type="application/json"), + (status = 200, description = "Ok", body=String, content_type="application/json"), ), security(("token_jwt" = [])), tag = "v1/debug", @@ -3047,8 +3047,8 @@ pub async fn auth_valid( pub async fn debug_ipinfo( State(_state): State, TrustedClientIp(ip_addr): TrustedClientIp, -) -> Result>, ()> { - Ok(Json::from(vec![ip_addr])) +) -> Result, ()> { + Ok(Json::from(ip_addr)) } #[utoipa::path( diff --git a/server/testkit/tests/https_extractors.rs b/server/testkit/tests/https_extractors.rs index 335d617d2..15da716af 100644 --- a/server/testkit/tests/https_extractors.rs +++ b/server/testkit/tests/https_extractors.rs @@ -25,12 +25,12 @@ async fn dont_trust_xff_send_header(rsclient: KanidmClient) { .send() .await .unwrap(); - let ip_res: Vec = res + let ip_res: IpAddr = res .json() .await - .expect("Failed to parse response as Vec"); + .expect("Failed to parse response as IpAddr"); - assert_eq!(ip_res[0], DEFAULT_IP_ADDRESS); + assert_eq!(ip_res, DEFAULT_IP_ADDRESS); } #[kanidmd_testkit::test(trust_x_forward_for = false)] @@ -49,14 +49,14 @@ async fn dont_trust_xff_dont_send_header(rsclient: KanidmClient) { .await .unwrap(); let body = res.bytes().await.unwrap(); - let ip_res: Vec = serde_json::from_slice(&body).unwrap_or_else(|op| { + let ip_res: IpAddr = serde_json::from_slice(&body).unwrap_or_else(|op| { panic!( - "Failed to parse response as Vec: {:?} body: {:?}", + "Failed to parse response as IpAddr: {:?} body: {:?}", op, body, ) }); eprintln!("Body: {:?}", body); - assert_eq!(ip_res[0], DEFAULT_IP_ADDRESS); + assert_eq!(ip_res, DEFAULT_IP_ADDRESS); } // *test where we trust the x-forwarded-for header @@ -116,12 +116,12 @@ async fn trust_xff_send_valid_header_single_ipv4_address(rsclient: KanidmClient) .send() .await .unwrap(); - let ip_res: Vec = res + let ip_res: IpAddr = res .json() .await .expect("Failed to parse response as Vec"); - assert_eq!(ip_res[0], IpAddr::from_str(ip_addr).unwrap()); + assert_eq!(ip_res, IpAddr::from_str(ip_addr).unwrap()); } #[kanidmd_testkit::test(trust_x_forward_for = true)] @@ -138,12 +138,12 @@ async fn trust_xff_send_valid_header_single_ipv6_address(rsclient: KanidmClient) .send() .await .unwrap(); - let ip_res: Vec = res + let ip_res: IpAddr = res .json() .await .expect("Failed to parse response as Vec"); - assert_eq!(ip_res[0], IpAddr::from_str(ip_addr).unwrap()); + assert_eq!(ip_res, IpAddr::from_str(ip_addr).unwrap()); } #[kanidmd_testkit::test(trust_x_forward_for = true)] @@ -160,13 +160,13 @@ async fn trust_xff_send_valid_header_multiple_address(rsclient: KanidmClient) { .send() .await .unwrap(); - let ip_res: Vec = res + let ip_res: IpAddr = res .json() .await .expect("Failed to parse response as Vec"); assert_eq!( - ip_res[0], + ip_res, IpAddr::from_str(first_ip_addr.split(",").collect::>()[0]).unwrap() ); @@ -182,13 +182,13 @@ async fn trust_xff_send_valid_header_multiple_address(rsclient: KanidmClient) { .send() .await .unwrap(); - let ip_res: Vec = res + let ip_res: IpAddr = res .json() .await .expect("Failed to parse response as Vec"); assert_eq!( - ip_res[0], + ip_res, IpAddr::from_str(second_ip_addr.split(",").collect::>()[0]).unwrap() ); } @@ -204,10 +204,10 @@ async fn trust_xff_dont_send_header(rsclient: KanidmClient) { .send() .await .unwrap(); - let ip_res: Vec = res + let ip_res: IpAddr = res .json() .await .expect("Failed to parse response as Vec"); - assert_eq!(ip_res[0], DEFAULT_IP_ADDRESS); + assert_eq!(ip_res, DEFAULT_IP_ADDRESS); }