diff --git a/libs/client/src/lib.rs b/libs/client/src/lib.rs index fbe7805cf..b89ece5e0 100644 --- a/libs/client/src/lib.rs +++ b/libs/client/src/lib.rs @@ -633,7 +633,16 @@ impl KanidmClient { return; } - let ver = response + if response.status() == StatusCode::BAD_GATEWAY + || response.status() == StatusCode::GATEWAY_TIMEOUT + { + // don't need to check versions when there's an intermediary reporting connectivity + debug!("Gateway error in response - we're going through a proxy so the version check is skipped."); + *guard = false; + return; + } + + let ver: &str = response .headers() .get(KVERSION) .and_then(|hv| hv.to_str().ok()) @@ -2028,3 +2037,32 @@ impl KanidmClient { .await } } + +#[tokio::test] +async fn test_no_client_version_check_on_502() { + let res = reqwest::Response::from( + hyper::Response::builder() + .status(StatusCode::GATEWAY_TIMEOUT) + .body(hyper::Body::empty()) + .unwrap(), + ); + let client = KanidmClientBuilder::new() + .address("http://localhost:8080".to_string()) + .build() + .expect("Failed to build client"); + eprintln!("This should pass because we are returning 504 and shouldn't check version..."); + client.expect_version(&res).await; + + let res = reqwest::Response::from( + hyper::Response::builder() + .status(StatusCode::BAD_GATEWAY) + .body(hyper::Body::empty()) + .unwrap(), + ); + let client = KanidmClientBuilder::new() + .address("http://localhost:8080".to_string()) + .build() + .expect("Failed to build client"); + eprintln!("This should pass because we are returning 502 and shouldn't check version..."); + client.expect_version(&res).await; +}