summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Brauer <jan@jimdo.com>2012-07-12 17:12:26 +0200
committerJeff Forcier <jeff@bitprophet.org>2012-09-23 16:45:49 -0700
commitd18b8cf1e9aab43abc9f6750fd9fb15f356435e4 (patch)
treeb2e2196fefe6b1b7380140678955f5c8c81cf77e
parentd3dc9fcb19af0e2660cd36028fb226bb2c11f527 (diff)
downloadparamiko-d18b8cf1e9aab43abc9f6750fd9fb15f356435e4.tar.gz
Fix #33 - parse config as described by manpage
(cherry picked from commit 011805eae07ee7be6140b95f6d8669763c55b3d9)
-rw-r--r--paramiko/config.py11
-rw-r--r--tests/test_util.py18
2 files changed, 26 insertions, 3 deletions
diff --git a/paramiko/config.py b/paramiko/config.py
index 75c54b4a..1c9816d3 100644
--- a/paramiko/config.py
+++ b/paramiko/config.py
@@ -104,11 +104,16 @@ class SSHConfig (object):
@type hostname: str
"""
matches = [x for x in self._config if fnmatch.fnmatch(hostname, x['host'])]
- # sort in order of shortest match (usually '*') to longest
- matches.sort(lambda x,y: cmp(len(x['host']), len(y['host'])))
+ # Move * to the end
+ _star = matches[0]
+ del matches[0]
+ matches.append(_star)
+ ret = {}
ret = {}
for m in matches:
- ret.update(m)
+ for k,v in m.iteritems():
+ if not k in ret:
+ ret[k] = v
ret = self._expand_variables(ret, hostname)
del ret['host']
return ret
diff --git a/tests/test_util.py b/tests/test_util.py
index e3c9dfeb..ed0607fa 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -159,3 +159,21 @@ class UtilTest (unittest.TestCase):
x = rng.read(32)
self.assertEquals(len(x), 32)
+ def test_7_host_config_expose_issue_33(self):
+ test_config_file = """
+Host www13.*
+ Port 22
+
+Host *.example.com
+ Port 2222
+
+Host *
+ Port 3333
+ """
+ f = cStringIO.StringIO(test_config_file)
+ config = ssh.util.parse_ssh_config(f)
+ host = 'www13.example.com'
+ self.assertEquals(
+ ssh.util.lookup_ssh_host_config(host, config),
+ {'hostname': host, 'port': '22'}
+ )