Skip to content

Commit 6ff0842

Browse files
authored
Merge pull request #264 from J-ZhengLi/patch-no-proxy-env
[patch] fix no_proxy env var could be mistakenly replaced after installation
2 parents 2b55ab8 + 142c65a commit 6ff0842

7 files changed

Lines changed: 73 additions & 8 deletions

File tree

‎rim_dev/src/main.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::obfuscated_if_else)]
2+
13
mod common;
24
mod dist;
35
mod mocked;

‎rim_dev/src/mocked/server.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ fn calculate_sha256(file_path: &Path) -> Result<String> {
484484

485485
// Finalize and get the checksum as a hex string
486486
let result = hasher.finalize();
487-
Ok(format!("{:x}", result))
487+
Ok(format!("{result:x}"))
488488
}
489489

490490
pub(crate) fn generate_rim_server_files() -> Result<()> {

‎rim_test/rim-test-macro/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn rim_test(attr: TokenStream, item: TokenStream) -> TokenStream {
1010
"ignore" => {
1111
ignore = true;
1212
}
13-
_ => panic!("unknown rule: {:?}", rule),
13+
_ => panic!("unknown rule: {rule:?}"),
1414
}
1515
}
1616

‎rim_test/rim-test-support/src/lib.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ pub fn panic_error(what: &str, err: impl Into<anyhow::Error>) -> ! {
3030
pe(what, err);
3131
#[track_caller]
3232
fn pe(what: &str, err: anyhow::Error) -> ! {
33-
let mut result = format!("{}\nerror: {}", what, err);
33+
let mut result = format!("{what}\nerror: {err}");
3434
for cause in err.chain().skip(1) {
3535
let _ = writeln!(result, "\nCaused by:");
36-
let _ = write!(result, "{}", cause);
36+
let _ = write!(result, "{cause}");
3737
}
38-
panic!("\n{}", result);
38+
panic!("\n{result}");
3939
}
4040
}

‎rim_test/rim-test-support/src/paths.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn test_root() -> TempDir {
3535
let id = TEST_ID.with(|n| n.borrow().expect("Failed to get test thread id"));
3636

3737
let test_root_dir = global_root_dir();
38-
let prefix = format!("t{}", id);
38+
let prefix = format!("t{id}");
3939
TempDir::with_prefix_in(prefix, test_root_dir).expect("Failed to create temp test dir")
4040
}
4141

‎src/cli/common.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ where
123123
}
124124
// print extra info, such as a list of selectable options.
125125
if let Some(ex) = extra {
126-
writeln!(&mut stdout, "\n{}", ex)?;
126+
writeln!(&mut stdout, "\n{ex}")?;
127127
}
128128

129129
loop {

‎src/core/install.rs‎

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,18 @@ impl<'a> InstallConfiguration<'a> {
184184
env_vars.insert("https_proxy", url.to_string());
185185
}
186186
if let Some(s) = &proxy.no_proxy {
187-
env_vars.insert("no_proxy", s.to_string());
187+
// keep use's original no_proxy var.
188+
#[cfg(windows)]
189+
let prev_np = std::env::var("no_proxy").unwrap_or_default();
190+
#[cfg(unix)]
191+
let prev_np = "$no_proxy";
192+
193+
let no_proxy = if prev_np.is_empty() {
194+
s.to_string()
195+
} else {
196+
format!("{s},{prev_np}")
197+
};
198+
env_vars.insert("no_proxy", no_proxy);
188199
}
189200
}
190201

@@ -594,4 +605,56 @@ c = { version = "0.1.0", conflicts = ["d", "a"] }
594605
let error = conflicts.expect_err("has conflicts");
595606
println!("{error}");
596607
}
608+
609+
#[test]
610+
fn no_proxy_env_var() {
611+
let raw = r#"
612+
[rust]
613+
version = "1.0.0"
614+
615+
[proxy]
616+
no_proxy = "localhost,.example.com,.foo.com"
617+
"#;
618+
619+
let manifest = ToolkitManifest::from_str(raw).unwrap();
620+
let install_dir = tempfile::tempdir().unwrap();
621+
let install_cfg = InstallConfiguration::new(install_dir.path(), &manifest).unwrap();
622+
623+
// Temporarily modify no_proxy var to test inheritance.
624+
// FIXME (master): Later commits introduces mocked env tests, make sure to tesk this
625+
// with mocked env, that we don't need to set no_proxy var here and potentially
626+
// mess up other concurrent test cases.
627+
let no_proxy_backup = std::env::var("no_proxy");
628+
std::env::remove_var("no_proxy");
629+
630+
let env_vars = install_cfg.env_vars().unwrap();
631+
let new_no_proxy_var = env_vars.get("no_proxy").unwrap();
632+
633+
#[cfg(windows)]
634+
assert_eq!(new_no_proxy_var, "localhost,.example.com,.foo.com");
635+
#[cfg(unix)]
636+
assert_eq!(
637+
new_no_proxy_var,
638+
"localhost,.example.com,.foo.com,$no_proxy"
639+
);
640+
641+
std::env::set_var("no_proxy", ".bar.com,baz.com");
642+
let env_vars = install_cfg.env_vars().unwrap();
643+
let new_no_proxy_var = env_vars.get("no_proxy").unwrap();
644+
645+
#[cfg(windows)]
646+
assert_eq!(
647+
new_no_proxy_var,
648+
"localhost,.example.com,.foo.com,.bar.com,baz.com"
649+
);
650+
#[cfg(unix)]
651+
assert_eq!(
652+
new_no_proxy_var,
653+
"localhost,.example.com,.foo.com,$no_proxy"
654+
);
655+
656+
if let Ok(bck) = no_proxy_backup {
657+
std::env::set_var("no_proxy", bck);
658+
}
659+
}
597660
}

0 commit comments

Comments
 (0)