Don't need to check versions when there's an intermediary reporting connectivity issues (#2758)

* don't need to check versions when there's an intermediary reporting connectivity, skip it on 502 and 504
This commit is contained in:
James Hodgkinson 2024-05-14 12:47:39 +10:00 committed by GitHub
parent f86c2c4f8c
commit ff02ec2417
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
}