Skip to content

Commit

Permalink
#3868 avoid KeyError when canonicaldomains is missing
Browse files Browse the repository at this point in the history
paramiko assumes that `canonicaldomains` is always present when `CanonicalizeHostname` is set, and it errors out when it is not, preventing the whole host config from being parsed.

Xpra-org/xpra#3868 (comment)
  • Loading branch information
totaam committed Jan 24, 2024
1 parent 43980e7 commit 4b81597
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion paramiko/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def lookup(self, hostname):
if canon and hostname.count(".") <= maxdots:
# NOTE: OpenSSH manpage does not explicitly state this, but its
# implementation for CanonicalDomains is 'split on any whitespace'.
domains = options["canonicaldomains"].split()
domains = options.get("canonicaldomains", "").split()
hostname = self.canonicalize(hostname, options, domains)
# Overwrite HostName again here (this is also what OpenSSH does)
options["hostname"] = hostname
Expand Down
14 changes: 14 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,20 @@ def test_hostname_tokenization(self):
result = load_config("hostname-tokenized").lookup("whatever")
assert result["hostname"] == "prefix.whatever"

def test_with_canonicaldomains_missing(self):
# this config is valid,
# don't assume that `CanonicalizeHostname` implies that
# `canonicaldomains` is specified.
SSHConfig.from_text(
"""
CanonicalizeHostname always
Host foo
Port 22
"""
).lookup("foo")



class TestSSHConfigDict:
def test_SSHConfigDict_construct_empty(self):
Expand Down

0 comments on commit 4b81597

Please sign in to comment.