From 6a70a3bae4ddd8808d527d3c4458c54d479afb6b Mon Sep 17 00:00:00 2001 From: Simon Chopin Date: Wed, 3 Jul 2024 14:07:55 +0200 Subject: [PATCH] tests: bypass the proxy if testing DNS override If an explicit proxy is configured in the environment, then the request will go through it rather than actually resolving the domain. Either we're hitting the target domain on a weird port which will likely fail, or the proxy straight up denies that weird request. To work around this, we actually modify the environment variables to make sure that our target domain is in the exception list for the proxy. We're hitting this issue in the Ubuntu CI. Amazingly enough, the tests actually passed *once* there, although the exact circumstances that allowed this are still a bit of a mystery. --- tests/client.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/client.rs b/tests/client.rs index ce97456bf..6da05c133 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -235,12 +235,31 @@ async fn body_pipe_response() { assert_eq!(res2.status(), reqwest::StatusCode::OK); } +fn set_proxy_exception(domain: &str) { + let mut exception_set = false; + // We add it to *all* potential lists. + for name in ["NO_PROXY", "no_proxy"] { + if let Ok(v) = std::env::var(name) { + // Add the domain if not already present + if ! v.split(',').any(|dmn| {dmn == domain}) { + std::env::set_var(name, format!("{v},{domain}")); + } + exception_set = true; + } + } + // If nothing was set, we create the defaut list, just in case + if !exception_set { + std::env::set_var("NO_PROXY", domain); + } +} + #[tokio::test] async fn overridden_dns_resolution_with_gai() { let _ = env_logger::builder().is_test(true).try_init(); let server = server::http(move |_req| async { http::Response::new("Hello".into()) }); let overridden_domain = "rust-lang.org"; + set_proxy_exception(overridden_domain); let url = format!( "http://{overridden_domain}:{}/domain_override", server.addr().port() @@ -263,6 +282,7 @@ async fn overridden_dns_resolution_with_gai_multiple() { let server = server::http(move |_req| async { http::Response::new("Hello".into()) }); let overridden_domain = "rust-lang.org"; + set_proxy_exception(overridden_domain); let url = format!( "http://{overridden_domain}:{}/domain_override", server.addr().port() @@ -297,6 +317,7 @@ async fn overridden_dns_resolution_with_hickory_dns() { let server = server::http(move |_req| async { http::Response::new("Hello".into()) }); let overridden_domain = "rust-lang.org"; + set_proxy_exception(overridden_domain); let url = format!( "http://{overridden_domain}:{}/domain_override", server.addr().port() @@ -321,6 +342,7 @@ async fn overridden_dns_resolution_with_hickory_dns_multiple() { let server = server::http(move |_req| async { http::Response::new("Hello".into()) }); let overridden_domain = "rust-lang.org"; + set_proxy_exception(overridden_domain); let url = format!( "http://{overridden_domain}:{}/domain_override", server.addr().port()