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

Prevent get_hostname() from crashing of "Match" is not followed by a … #2340

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
3 changes: 2 additions & 1 deletion paramiko/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ def get_hostnames(self):
"""
hosts = set()
for entry in self._config:
hosts.update(entry["host"])
if "host" in entry:
hosts.update(entry["host"])
return hosts

def _pattern_matches(self, patterns, target):
Expand Down
1 change: 1 addition & 0 deletions tests/configs/match-all
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Match all
User awesome

5 changes: 5 additions & 0 deletions tests/configs/match-include
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Host Foo
User bar

Match all
Include ~/.ssh/config.extra
4 changes: 4 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ def test_after_canonical_not_loaded_when_non_canonicalized(self, socket):
result = load_config("match-canonical-no").lookup("a-host")
assert "user" not in result

def test_match_include(self):
result = load_config("match-include").get_hostnames()
assert "Foo" in result


def _expect(success_on):
"""
Expand Down