From 928c06274816669a94753b80f493a2e4e1b9357a Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Mon, 5 Nov 2012 17:04:45 -0800 Subject: Add failing test(s) re ProxyCommand config parsing --- tests/test_util.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_util.py b/tests/test_util.py index 458709b2..83de0044 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -27,6 +27,7 @@ import os import unittest from Crypto.Hash import SHA import paramiko.util +from paramiko.util import lookup_ssh_host_config as host_config from util import ParamikoTest @@ -151,7 +152,7 @@ class UtilTest(ParamikoTest): x = rng.read(32) self.assertEquals(len(x), 32) - def test_7_host_config_expose_issue_33(self): + def test_7_host_config_expose_ssh_issue_33(self): test_config_file = """ Host www13.* Port 22 @@ -194,3 +195,22 @@ Host * raise AssertionError('foo') self.assertRaises(AssertionError, lambda: paramiko.util.retry_on_signal(raises_other_exception)) + + def test_9_proxycommand_config_parsing(self): + """ + ProxyCommand should not split on equals signs within the value. + """ + conf = """ +Host space-delimited + ProxyCommand foo bar=biz baz + +Host equals-delimited + ProxyCommand=foo bar=biz baz +""" + f = cStringIO.StringIO(conf) + config = paramiko.util.parse_ssh_config(f) + for host in ('space-delimited', 'equals-delimited'): + self.assertEquals( + host_config(host, config)['proxycommand'], + 'foo bar=biz baz' + ) -- cgit v1.2.3 From 191a5fc08cb8ce08917ad4e8739d7d5efbec2be2 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Mon, 5 Nov 2012 17:44:25 -0800 Subject: Implement (& test for) ProxyCommand interpolation. Forgot this earlier. --- paramiko/config.py | 7 ++++++- tests/test_util.py | 28 +++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/paramiko/config.py b/paramiko/config.py index 8daee18c..2828d903 100644 --- a/paramiko/config.py +++ b/paramiko/config.py @@ -174,7 +174,12 @@ class SSHConfig (object): ('%l', fqdn), ('%u', user), ('%r', remoteuser) - ] + ], + 'proxycommand': [ + ('%h', config['hostname']), + ('%p', port), + ('%r', remoteuser), + ], } for k in config: if k in replacements: diff --git a/tests/test_util.py b/tests/test_util.py index 83de0044..093a2157 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -196,7 +196,7 @@ Host * self.assertRaises(AssertionError, lambda: paramiko.util.retry_on_signal(raises_other_exception)) - def test_9_proxycommand_config_parsing(self): + def test_9_proxycommand_config_equals_parsing(self): """ ProxyCommand should not split on equals signs within the value. """ @@ -214,3 +214,29 @@ Host equals-delimited host_config(host, config)['proxycommand'], 'foo bar=biz baz' ) + + def test_10_proxycommand_interpolation(self): + """ + 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 +""")) + for host, val in ( + ('foo.com', "host foo.com port 25"), + ('specific', "host specific port 37 lol"), + ('portonly', "host portonly port 155"), + ): + self.assertEquals( + host_config(host, config)['proxycommand'], + val + ) -- cgit v1.2.3