summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChris Rose <offline@offby1.net>2018-05-16 10:35:09 -0400
committerChris Rose <offline@offby1.net>2018-05-16 17:18:50 -0400
commitd25c3b36977fbe6d281efe7cbc9faa39db50498d (patch)
treedf14d95dff4b4b0de70fcf748fc29ca5c94baf38
parent2bc68629f386e1eb4771cc363d64665e51eebea0 (diff)
Return a userdict class from paramiko config parsing
-rw-r--r--paramiko/config.py2
-rw-r--r--tests/test_config.py31
2 files changed, 31 insertions, 2 deletions
diff --git a/paramiko/config.py b/paramiko/config.py
index 22e2e2b3..cd5aae90 100644
--- a/paramiko/config.py
+++ b/paramiko/config.py
@@ -122,7 +122,7 @@ class SSHConfig (object):
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:
diff --git a/tests/test_config.py b/tests/test_config.py
index 9edab3d9..20f051fc 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -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()
@@ -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
+