From d13c7ff61bc68095989de1dac612b8fc9767c68e Mon Sep 17 00:00:00 2001 From: "B. Blechschmidt" Date: Thu, 23 Mar 2023 14:51:56 +0100 Subject: [PATCH] Add DNS tests --- tests/proxy.rs | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/tests/proxy.rs b/tests/proxy.rs index be05578..1462307 100644 --- a/tests/proxy.rs +++ b/tests/proxy.rs @@ -116,9 +116,18 @@ mod tests { } } - fn run_test(filter: F) + fn request_ip_host_http() { + reqwest::blocking::get("http://1.1.1.1").expect("failed to issue HTTP request"); + } + + fn request_example_https() { + reqwest::blocking::get("https://example.org").expect("failed to issue HTTPs request"); + } + + fn run_test(filter: F, test_function: T) where F: Fn(&Test) -> bool, + T: Fn(), { for potential_test in tests() { match potential_test { @@ -129,8 +138,7 @@ mod tests { match fork::fork() { Ok(Fork::Parent(child)) => { - reqwest::blocking::get("https://1.1.1.1") - .expect("failed to issue HTTP request"); + test_function(); signal::kill(Pid::from_raw(child), signal::SIGKILL) .expect("failed to kill child"); nix::sys::wait::waitpid(Pid::from_raw(child), None) @@ -158,13 +166,39 @@ mod tests { #[test] fn test_socks5() { require_var("SOCKS5_SERVER"); - run_test(|test| test.proxy.proxy_type == ProxyType::Socks5) + run_test( + |test| test.proxy.proxy_type == ProxyType::Socks5, + request_ip_host_http, + ) } #[serial] #[test] fn test_http() { require_var("HTTP_SERVER"); - run_test(|test| test.proxy.proxy_type == ProxyType::Http) + run_test( + |test| test.proxy.proxy_type == ProxyType::Http, + request_ip_host_http, + ) + } + + #[serial] + #[test] + fn test_socks5_dns() { + require_var("SOCKS5_SERVER"); + run_test( + |test| test.proxy.proxy_type == ProxyType::Socks5, + request_example_https, + ) + } + + #[serial] + #[test] + fn test_http_dns() { + require_var("HTTP_SERVER"); + run_test( + |test| test.proxy.proxy_type == ProxyType::Http, + request_example_https, + ) } }