1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 05:12:40 +03:00

Fix SSH config %h using Host (#5163)

* Fix SSH config %h using Host

* Fix test and use workaround for 2nd pass parsing

* Better implementation from @wheatdog
This commit is contained in:
emc2314 2024-05-06 04:43:52 +08:00 committed by GitHub
parent 952af2e6e1
commit c2fb3cb760
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -533,6 +533,15 @@ impl Config {
let mut token_map = self.tokens.clone();
token_map.insert("%h".to_string(), host.to_string());
result
.entry("hostname".to_string())
.and_modify(|curr| {
if let Some(tokens) = self.should_expand_tokens("hostname") {
self.expand_tokens(curr, tokens, &token_map);
}
})
.or_insert_with(|| host.to_string());
token_map.insert("%h".to_string(), result["hostname"].to_string());
token_map.insert("%n".to_string(), host.to_string());
token_map.insert("%r".to_string(), target_user.to_string());
token_map.insert(
@ -553,10 +562,6 @@ impl Config {
}
}
result
.entry("hostname".to_string())
.or_insert_with(|| host.to_string());
result
.entry("port".to_string())
.or_insert_with(|| "22".to_string());
@ -960,6 +965,39 @@ Config {
);
}
#[test]
fn parse_proxy_command_hostname_expansion() {
let mut config = Config::new();
let mut fake_env = ConfigMap::new();
fake_env.insert("HOME".to_string(), "/home/me".to_string());
fake_env.insert("USER".to_string(), "me".to_string());
config.assign_environment(fake_env);
config.add_config_string(
r#"
Host foo
HostName server-%h
ProxyCommand nc -x localhost:1080 %h %p
"#,
);
let opts = config.for_host("foo");
snapshot!(
opts,
r#"
{
"hostname": "server-foo",
"identityfile": "/home/me/.ssh/id_dsa /home/me/.ssh/id_ecdsa /home/me/.ssh/id_ed25519 /home/me/.ssh/id_rsa",
"port": "22",
"proxycommand": "nc -x localhost:1080 server-foo 22",
"user": "me",
"userknownhostsfile": "/home/me/.ssh/known_hosts /home/me/.ssh/known_hosts2",
}
"#
);
}
#[test]
fn multiple_identityfile() {
let mut config = Config::new();