From 98ae4e975dd8fd25af4b615bbbd034cc0831e1fa Mon Sep 17 00:00:00 2001 From: Olle Lundberg Date: Tue, 16 Oct 2012 13:52:21 +0200 Subject: Updated tests for new ssh config format. --- tests/test_util.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'tests/test_util.py') diff --git a/tests/test_util.py b/tests/test_util.py index 093a2157..348b796e 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -104,23 +104,32 @@ class UtilTest(ParamikoTest): f = cStringIO.StringIO(test_config_file) config = paramiko.util.parse_ssh_config(f) self.assertEquals(config._config, - [ {'identityfile': '~/.ssh/id_rsa', 'host': '*', 'user': 'robey', - 'crazy': 'something dumb '}, - {'host': '*.example.com', 'user': 'bjork', 'port': '3333'}, - {'host': 'spoo.example.com', 'crazy': 'something else'}]) + [{'host': ['*'], 'config': {}}, {'host': ['*'], 'config': {'identityfile': ['~/.ssh/id_rsa'], 'user': 'robey'}}, + {'host': ['*.example.com'], 'config': {'user': 'bjork', 'port': '3333'}}, + {'host': ['*'], 'config': {'crazy': 'something dumb '}}, + {'host': ['spoo.example.com'], 'config': {'crazy': 'something else'}}]) def test_3_host_config(self): global test_config_file f = cStringIO.StringIO(test_config_file) config = paramiko.util.parse_ssh_config(f) + for host, values in { - 'irc.danger.com': {'user': 'robey', 'crazy': 'something dumb '}, - 'irc.example.com': {'user': 'bjork', 'crazy': 'something dumb ', 'port': '3333'}, - 'spoo.example.com': {'user': 'bjork', 'crazy': 'something else', 'port': '3333'} + 'irc.danger.com': {'crazy': 'something dumb ', + 'hostname': 'irc.danger.com', + 'user': 'robey'}, + 'irc.example.com': {'crazy': 'something dumb ', + 'hostname': 'irc.example.com', + 'user': 'robey', + 'port': '3333'}, + 'spoo.example.com': {'crazy': 'something dumb ', + 'hostname': 'spoo.example.com', + 'user': 'robey', + 'port': '3333'} }.items(): values = dict(values, hostname=host, - identityfile=os.path.expanduser("~/.ssh/id_rsa") + identityfile=[os.path.expanduser("~/.ssh/id_rsa")] ) self.assertEquals( paramiko.util.lookup_ssh_host_config(host, config), @@ -151,8 +160,8 @@ class UtilTest(ParamikoTest): # just verify that we can pull out 32 bytes and not get an exception. x = rng.read(32) self.assertEquals(len(x), 32) - - def test_7_host_config_expose_ssh_issue_33(self): + + def test_7_host_config_expose_issue_33(self): test_config_file = """ Host www13.* Port 22 -- cgit v1.2.3 From 21689d964798fbbd037e7b995088cee883796225 Mon Sep 17 00:00:00 2001 From: Olle Lundberg Date: Tue, 16 Oct 2012 13:53:06 +0200 Subject: Add test for host negation. --- tests/test_util.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/test_util.py') diff --git a/tests/test_util.py b/tests/test_util.py index 348b796e..4bb34da5 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -249,3 +249,25 @@ Host portonly host_config(host, config)['proxycommand'], val ) + + def test_11_host_config_test_negation(self): + test_config_file = """ +Host www13.* !*.example.com + Port 22 + +Host *.example.com !www13.* + Port 2222 + +Host www13.* + Port 8080 + +Host * + Port 3333 + """ + f = cStringIO.StringIO(test_config_file) + config = paramiko.util.parse_ssh_config(f) + host = 'www13.example.com' + self.assertEquals( + paramiko.util.lookup_ssh_host_config(host, config), + {'hostname': host, 'port': '8080'} + ) -- cgit v1.2.3 From b3d5156019566c972a3dbbea851cffed3cf08514 Mon Sep 17 00:00:00 2001 From: Olle Lundberg Date: Tue, 16 Oct 2012 16:38:09 +0200 Subject: Add tests for proxycommand parsing. --- tests/test_util.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/test_util.py') diff --git a/tests/test_util.py b/tests/test_util.py index 4bb34da5..c97c1d58 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -271,3 +271,30 @@ Host * paramiko.util.lookup_ssh_host_config(host, config), {'hostname': host, 'port': '8080'} ) + def test_10_host_config_test_proxycommand(self): + test_config_file = """ +Host proxy-with-equal-divisor-and-space +ProxyCommand = foo=bar + +Host proxy-with-equal-divisor-and-no-space +ProxyCommand=foo=bar + +Host proxy-without-equal-divisor +ProxyCommand foo=bar:%h-%p + """ + for host, values in { + 'proxy-with-equal-divisor-and-space' :{'hostname': 'proxy-with-equal-divisor-and-space', + 'proxycommand': 'foo=bar'}, + 'proxy-with-equal-divisor-and-no-space':{'hostname': 'proxy-with-equal-divisor-and-no-space', + 'proxycommand': 'foo=bar'}, + 'proxy-without-equal-divisor' :{'hostname': 'proxy-without-equal-divisor', + 'proxycommand': + 'foo=bar:proxy-without-equal-divisor-22'} + }.items(): + + f = cStringIO.StringIO(test_config_file) + config = paramiko.util.parse_ssh_config(f) + self.assertEquals( + paramiko.util.lookup_ssh_host_config(host, config), + values + ) -- cgit v1.2.3 From c79e6a3f92938af07915c23ea1d7cbb75dac6d89 Mon Sep 17 00:00:00 2001 From: Olle Lundberg Date: Tue, 16 Oct 2012 17:02:04 +0200 Subject: Whitespace fixes. --- paramiko/config.py | 16 ---------------- tests/test_util.py | 4 +++- 2 files changed, 3 insertions(+), 17 deletions(-) (limited to 'tests/test_util.py') diff --git a/paramiko/config.py b/paramiko/config.py index 91b691ac..143223d9 100644 --- a/paramiko/config.py +++ b/paramiko/config.py @@ -82,7 +82,6 @@ class SSHConfig (object): """ Create a new OpenSSH config object. """ - self._proxyregex = re.compile(r"^(proxycommand)\s*=*\s*(.*)", re.I) self._config = [] def parse(self, file_obj): @@ -98,7 +97,6 @@ class SSHConfig (object): if (line == '') or (line[0] == '#'): continue if '=' in line: -<<<<<<< HEAD # Ensure ProxyCommand gets properly split if line.lower().strip().startswith('proxycommand'): match = proxy_re.match(line) @@ -106,20 +104,6 @@ class SSHConfig (object): else: key, value = line.split('=', 1) key = key.strip().lower() -||||||| merged common ancestors - key, value = line.split('=', 1) - key = key.strip().lower() -======= - if not line.lower().startswith('proxycommand'): - key, value = line.split('=', 1) - key = key.strip().lower() - else: - #ProxyCommand have been specified with an equal - # sign. Eat that and split in two groups. - match = self._proxyregex.match(line) - key = match.group(1).lower() - value = match.group(2) ->>>>>>> Implement support for parsing proxycommand. else: # find first whitespace, and split there i = 0 diff --git a/tests/test_util.py b/tests/test_util.py index c97c1d58..e6f417d4 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -205,6 +205,7 @@ Host * self.assertRaises(AssertionError, lambda: paramiko.util.retry_on_signal(raises_other_exception)) +<<<<<<< HEAD def test_9_proxycommand_config_equals_parsing(self): """ ProxyCommand should not split on equals signs within the value. @@ -271,7 +272,8 @@ Host * paramiko.util.lookup_ssh_host_config(host, config), {'hostname': host, 'port': '8080'} ) - def test_10_host_config_test_proxycommand(self): + + def test_12_host_config_test_proxycommand(self): test_config_file = """ Host proxy-with-equal-divisor-and-space ProxyCommand = foo=bar -- cgit v1.2.3 From 109d2b200a1e419f139166380fd0d136f4d57321 Mon Sep 17 00:00:00 2001 From: Olle Lundberg Date: Tue, 20 Nov 2012 12:42:29 +0100 Subject: Add tests for identityfile parsing. --- tests/test_util.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'tests/test_util.py') diff --git a/tests/test_util.py b/tests/test_util.py index e6f417d4..c4ad9d8a 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -205,7 +205,6 @@ Host * self.assertRaises(AssertionError, lambda: paramiko.util.retry_on_signal(raises_other_exception)) -<<<<<<< HEAD def test_9_proxycommand_config_equals_parsing(self): """ ProxyCommand should not split on equals signs within the value. @@ -300,3 +299,33 @@ ProxyCommand foo=bar:%h-%p paramiko.util.lookup_ssh_host_config(host, config), values ) + + def test_11_host_config_test_identityfile(self): + test_config_file = """ + +IdentityFile id_dsa0 + +Host * +IdentityFile id_dsa1 + +Host dsa2 +IdentityFile id_dsa2 + +Host dsa2* +IdentityFile id_dsa22 + """ + for host, values in { + 'foo' :{'hostname': 'foo', + 'identityfile': ['id_dsa0', 'id_dsa1']}, + 'dsa2' :{'hostname': 'dsa2', + 'identityfile': ['id_dsa0', 'id_dsa1', 'id_dsa2', 'id_dsa22']}, + 'dsa22' :{'hostname': 'dsa22', + 'identityfile': ['id_dsa0', 'id_dsa1', 'id_dsa22']} + }.items(): + + f = cStringIO.StringIO(test_config_file) + config = paramiko.util.parse_ssh_config(f) + self.assertEquals( + paramiko.util.lookup_ssh_host_config(host, config), + values + ) -- cgit v1.2.3 From 38767982cd1a5181536a5f24f830e71933f7fb10 Mon Sep 17 00:00:00 2001 From: Olle Lundberg Date: Thu, 28 Feb 2013 12:36:03 +0100 Subject: Fix broken test. --- tests/test_util.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/test_util.py') diff --git a/tests/test_util.py b/tests/test_util.py index c4ad9d8a..efda9b2f 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -229,16 +229,16 @@ Host equals-delimited ProxyCommand should perform interpolation on the value """ config = paramiko.util.parse_ssh_config(cStringIO.StringIO(""" -Host * - Port 25 - ProxyCommand host %h port %p - Host specific Port 37 ProxyCommand host %h port %p lol Host portonly Port 155 + +Host * + Port 25 + ProxyCommand host %h port %p """)) for host, val in ( ('foo.com', "host foo.com port 25"), -- cgit v1.2.3