diff options
-rw-r--r-- | pexpect/pxssh.py | 13 | ||||
-rw-r--r-- | tests/test_pxssh.py | 9 |
2 files changed, 20 insertions, 2 deletions
diff --git a/pexpect/pxssh.py b/pexpect/pxssh.py index 3de1687..4b9ddce 100644 --- a/pexpect/pxssh.py +++ b/pexpect/pxssh.py @@ -105,11 +105,16 @@ class pxssh (spawn): username = raw_input('username: ') password = getpass.getpass('password: ') s.login (hostname, username, password) + + `debug_tunnel_command` is only for the test suite to confirm that the string + generated for SSH tunnelling is correct, using this will not allow you to do + anything other than get a string back from `pxssh.pxssh.login()`. ''' def __init__ (self, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, cwd=None, env=None, ignore_sighup=True, echo=True, - options={}, encoding=None, codec_errors='strict'): + options={}, encoding=None, codec_errors='strict', + debug_tunnel_command=False): spawn.__init__(self, None, timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize, logfile=logfile, @@ -145,6 +150,8 @@ class pxssh (spawn): # Unsetting SSH_ASKPASS on the remote side doesn't disable it! Annoying! #self.SSH_OPTS = "-x -o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'" self.force_password = False + + self.debug_tunnel_command = debug_tunnel_command # User defined SSH options, eg, # ssh.otions = dict(StrictHostKeyChecking="no",UserKnownHostsFile="/dev/null") @@ -334,8 +341,10 @@ class pxssh (spawn): for tunnel in tunnels: if spawn_local_ssh==False: tunnel = quote(tunnel) - ssh_options = ssh_options + ' -' + cmd_type + ' ' + tunnel + ssh_options = ssh_options + ' -' + cmd_type + ' ' + str(tunnel) cmd = "ssh %s -l %s %s" % (ssh_options, username, server) + if self.debug_tunnel_command: + return(cmd) # Are we asking for a local ssh command or to spawn one in another session? if spawn_local_ssh: diff --git a/tests/test_pxssh.py b/tests/test_pxssh.py index 3b3e50b..c89aa98 100644 --- a/tests/test_pxssh.py +++ b/tests/test_pxssh.py @@ -56,6 +56,15 @@ class PxsshTestCase(SSHTestBase): pass else: assert False, 'should have raised exception, pxssh.ExceptionPxssh' + + def test_ssh_tunnel_string(self): + ssh = pxssh.pxssh(debug_tunnel_command=True) + tunnels = { 'local': ['2424:localhost:22'],'remote': ['2525:localhost:22'], + 'dynamic': [8888] } + confirmation_string = 'ssh -q -R 2525:localhost:22 -L 2424:localhost:22 -D 8888 -l me server' + string = ssh.login('server', 'me', password='s3cret', ssh_tunnels=tunnels) + if string!=confirmation_string: + raise False, 'String generated from tunneling is potientally incorrect.' if __name__ == '__main__': |