Skip to content

Commit

Permalink
OpenSSH docs state %C should also work in IdentityFile and Match exec
Browse files Browse the repository at this point in the history
(at least, of what we presently ourselves support - it's also allowed in others)
  • Loading branch information
bitprophet committed Mar 11, 2022
1 parent 1bf3dce commit 5fcb8da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions paramiko/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ class SSHConfig(object):
TOKENS_BY_CONFIG_KEY = {
"controlpath": ["%C", "%h", "%l", "%L", "%n", "%p", "%r", "%u"],
"hostname": ["%h"],
"identityfile": ["~", "%d", "%h", "%l", "%u", "%r"],
"identityfile": ["%C", "~", "%d", "%h", "%l", "%u", "%r"],
"proxycommand": ["~", "%h", "%p", "%r"],
# Doesn't seem worth making this 'special' for now, it will fit well
# enough (no actual match-exec config key to be confused with).
"match-exec": ["%d", "%h", "%L", "%l", "%n", "%p", "%r", "%u"],
"match-exec": ["%C", "%d", "%h", "%L", "%l", "%n", "%p", "%r", "%u"],
}

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/configs/match-exec
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Host target
User intermediate
HostName configured

Match exec "%d %h %L %l %n %p %r %u"
Match exec "%C %d %h %L %l %n %p %r %u"
Port 1337
23 changes: 19 additions & 4 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ def test_controlpath_token_expansion(self, getpass):
Host explicit_host
HostName ohai
ControlPath remoteuser %r host %h orighost %n
Host hashbrowns
ControlPath %C
"""
)
result = config.lookup("explicit_user")["controlpath"]
Expand All @@ -226,6 +229,9 @@ def test_controlpath_token_expansion(self, getpass):
result = config.lookup("explicit_host")["controlpath"]
# Remote user falls back to local user; host and orighost may differ
assert result == "remoteuser gandalf host ohai orighost explicit_host"
# Supports %C
result = config.lookup("hashbrowns")["controlpath"]
assert result == "fc995d9f41ca1bcec7bc1d7f1ca87b9ff568a6d4"

def test_negation(self):
config = SSHConfig.from_text(
Expand Down Expand Up @@ -280,7 +286,6 @@ def test_proxycommand(self):
def test_identityfile(self):
config = SSHConfig.from_text(
"""
IdentityFile id_dsa0
Host *
Expand All @@ -291,6 +296,9 @@ def test_identityfile(self):
Host dsa2*
IdentityFile id_dsa22
Host hashbrowns
IdentityFile %C
"""
)
for host, values in {
Expand All @@ -303,8 +311,15 @@ def test_identityfile(self):
"hostname": "dsa22",
"identityfile": ["id_dsa0", "id_dsa1", "id_dsa22"],
},
"hashbrowns": {
"hostname": "hashbrowns",
"identityfile": [
"id_dsa0",
"id_dsa1",
"d5c0115d09912e39ff27844ea9d6052fc6048f99",
],
},
}.items():

assert config.lookup(host) == values

def test_config_addressfamily_and_lazy_fqdn(self):
Expand Down Expand Up @@ -740,10 +755,10 @@ def test_does_not_match_nonzero_exit_codes(self, run):
@patch("paramiko.config.getpass")
@patch("paramiko.config.invoke.run")
def test_tokenizes_argument(self, run, getpass, socket):
socket.gethostname.return_value = "local.fqdn"
getpass.getuser.return_value = "gandalf"
# Actual exec value is "%d %h %L %l %n %p %r %u"
# Actual exec value is "%C %d %h %L %l %n %p %r %u"
parts = (
"bf5ba06778434a9384ee4217e462f64888bd0cd2",
expanduser("~"),
"configured",
"local",
Expand Down

0 comments on commit 5fcb8da

Please sign in to comment.