Skip to content

Commit

Permalink
Return a userdict class from paramiko config parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
offbyone committed May 16, 2018
1 parent 2bc6862 commit d25c3b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion paramiko/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def lookup(self, hostname):
if self._allowed(config['host'], hostname)
]

ret = {}
ret = SSHConfigDict()
for match in matches:
for key, value in match['config'].items():
if key not in ret:
Expand Down
31 changes: 30 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# repository

import pytest
from paramiko import config

from paramiko import config
from paramiko.util import parse_ssh_config
from paramiko.py3compat import StringIO

def test_SSHConfigDict_construct_empty():
assert not config.SSHConfigDict()
Expand Down Expand Up @@ -43,3 +45,30 @@ def test_SSHConfigDict_as_int_failures(non_int):

with pytest.raises(exception_type):
conf.as_int("key")


def test_SSHConfig_host_dicts_are_SSHConfigDict_instances():
test_config_file = """
Host *.example.com
Port 2222
Host *
Port 3333
"""
f = StringIO(test_config_file)
config = parse_ssh_config(f)
assert config.lookup("foo.example.com").as_int("port") == 2222


def test_SSHConfig_wildcard_host_dicts_are_SSHConfigDict_instances():
test_config_file = """\
Host *.example.com
Port 2222
Host *
Port 3333
"""
f = StringIO(test_config_file)
config = parse_ssh_config(f)
assert config.lookup("anything-else").as_int("port") == 3333

0 comments on commit d25c3b3

Please sign in to comment.