Skip to content

Commit

Permalink
tests: bypass the proxy if testing DNS override
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schopin-pro committed Jul 3, 2024
1 parent c4ebb07 commit 6a70a3b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 6a70a3b

Please sign in to comment.