Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid KeyError when canonicaldomains is missing #2338

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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