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

ssh: fix token expansion for ProxyCommand

refs: https://github.com/wez/wezterm/issues/3437
This commit is contained in:
Wez Furlong 2023-04-03 17:04:53 -07:00
parent 45db43aa95
commit c3472cc969
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
2 changed files with 42 additions and 0 deletions

View File

@ -81,6 +81,8 @@ As features stabilize some brief notes about them will accumulate here.
* `wezterm connect --workspace WS DOM` didn't use the provided workspace when * `wezterm connect --workspace WS DOM` didn't use the provided workspace when
starting up the mux server. #2734 starting up the mux server. #2734
* mux: `ClearScrollback` was not forwarded to remote server. #2624 * mux: `ClearScrollback` was not forwarded to remote server. #2624
* ssh: `%r` `%h` and `%p` tokens were implicitly supported by libssh but stopped
working in `ProxyCommand` when we took over running the proxy command. #3437
### 20230326-111934-3666303c ### 20230326-111934-3666303c

View File

@ -533,6 +533,15 @@ impl Config {
let mut token_map = self.tokens.clone(); let mut token_map = self.tokens.clone();
token_map.insert("%h".to_string(), host.to_string()); token_map.insert("%h".to_string(), host.to_string());
token_map.insert("%n".to_string(), host.to_string());
token_map.insert("%r".to_string(), target_user.to_string());
token_map.insert(
"%p".to_string(),
result
.get("port")
.map(|p| p.to_string())
.unwrap_or_else(|| "22".to_string()),
);
for (k, v) in &mut result { for (k, v) in &mut result {
if let Some(tokens) = self.should_expand_tokens(k) { if let Some(tokens) = self.should_expand_tokens(k) {
@ -736,6 +745,37 @@ mod test {
use super::*; use super::*;
use k9::snapshot; use k9::snapshot;
#[test]
fn parse_proxy_command_tokens() {
let mut config = Config::new();
config.add_config_string(
r#"
Host foo
ProxyCommand /usr/bin/corp-ssh-helper -dst_username=%r %h %p
Port 2222
"#,
);
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);
let opts = config.for_host("foo");
snapshot!(
opts,
r#"
{
"hostname": "foo",
"identityfile": "/home/me/.ssh/id_dsa /home/me/.ssh/id_ecdsa /home/me/.ssh/id_ed25519 /home/me/.ssh/id_rsa",
"port": "2222",
"proxycommand": "/usr/bin/corp-ssh-helper -dst_username=me foo 2222",
"user": "me",
"userknownhostsfile": "/home/me/.ssh/known_hosts /home/me/.ssh/known_hosts2",
}
"#
);
}
#[test] #[test]
fn parse_proxy_command() { fn parse_proxy_command() {
let mut config = Config::new(); let mut config = Config::new();