Mercurial > core / rust/lib/dl/tests/read-proxy-env.rs
changeset 698: |
96958d3eb5b0 |
parent: |
966f92770ddf
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 #![cfg(feature = "reqwest-backend")] 4 env::{remove_var, set_var}, 8 atomic::{AtomicUsize, Ordering}, 15 use env_proxy::for_url; 16 use reqwest::{blocking::Client, Proxy}; 19 static SERIALISE_TESTS: Mutex<()> = Mutex::new(()); 22 remove_var("http_proxy"); 23 remove_var("https_proxy"); 24 remove_var("HTTPS_PROXY"); 25 remove_var("ftp_proxy"); 26 remove_var("FTP_PROXY"); 27 remove_var("all_proxy"); 28 remove_var("ALL_PROXY"); 29 remove_var("no_proxy"); 30 remove_var("NO_PROXY"); 33 // Tests for correctly retrieving the proxy (host, port) tuple from $https_proxy 35 fn read_basic_proxy_params() { 36 let _guard = SERIALISE_TESTS 38 .expect("Unable to lock the test guard"); 40 set_var("https_proxy", "http://proxy.example.com:8080"); 41 let u = Url::parse("https://www.example.org").ok().unwrap(); 43 for_url(&u).host_port(), 44 Some(("proxy.example.com".to_string(), 8080)) 48 // Tests to verify if socks feature is available and being used 50 fn socks_proxy_request() { 51 static CALL_COUNT: AtomicUsize = AtomicUsize::new(0); 52 let _guard = SERIALISE_TESTS 54 .expect("Unable to lock the test guard"); 57 set_var("all_proxy", "socks5://127.0.0.1:1080"); 59 thread::spawn(move || { 60 let listener = TcpListener::bind("127.0.0.1:1080").unwrap(); 61 let incoming = listener.incoming(); 63 CALL_COUNT.fetch_add(1, Ordering::SeqCst); 67 let env_proxy = |url: &Url| for_url(url).to_url(); 68 let url = Url::parse("http://192.168.0.1/").unwrap(); 70 let client = Client::builder() 71 .proxy(Proxy::custom(env_proxy)) 72 .timeout(Duration::from_secs(1)) 75 let res = client.get(url.as_str()).send(); 78 let s = e.source().unwrap(); 80 s.to_string().contains("socks connect error"), 81 "Expected socks connect error, got: {s}", 83 assert_eq!(CALL_COUNT.load(Ordering::SeqCst), 1); 85 panic!("Socks proxy was ignored")