diff options
author | Red_M <pooatyou.com@gmail.com> | 2018-03-30 12:25:05 +1000 |
---|---|---|
committer | Red_M <pooatyou.com@gmail.com> | 2018-03-30 12:25:05 +1000 |
commit | 4fce2c648d03842b5c775f3109d5cd6602a5034c (patch) | |
tree | c471b3674892c6a407c7eb03573c5c3657f1c630 | |
parent | 45108f0650c09680d0d0b7d7d3be4eeb86b8494d (diff) | |
download | pexpect-4fce2c648d03842b5c775f3109d5cd6602a5034c.tar.gz |
Add testing for remote tunnels and passing the SSH authentication socket to the next connection.
-rw-r--r-- | pexpect/pxssh.py | 10 | ||||
-rw-r--r-- | tests/test_pxssh.py | 34 |
2 files changed, 35 insertions, 9 deletions
diff --git a/pexpect/pxssh.py b/pexpect/pxssh.py index 4b9ddce..60e3d8c 100644 --- a/pexpect/pxssh.py +++ b/pexpect/pxssh.py @@ -106,15 +106,15 @@ class pxssh (spawn): 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 + `debug_command_string` is only for the test suite to confirm that the string + generated for SSH 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', - debug_tunnel_command=False): + debug_command_string=False): spawn.__init__(self, None, timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize, logfile=logfile, @@ -151,7 +151,7 @@ class pxssh (spawn): #self.SSH_OPTS = "-x -o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'" self.force_password = False - self.debug_tunnel_command = debug_tunnel_command + self.debug_command_string = debug_command_string # User defined SSH options, eg, # ssh.otions = dict(StrictHostKeyChecking="no",UserKnownHostsFile="/dev/null") @@ -343,7 +343,7 @@ class pxssh (spawn): tunnel = quote(tunnel) ssh_options = ssh_options + ' -' + cmd_type + ' ' + str(tunnel) cmd = "ssh %s -l %s %s" % (ssh_options, username, server) - if self.debug_tunnel_command: + if self.debug_command_string: return(cmd) # Are we asking for a local ssh command or to spawn one in another session? diff --git a/tests/test_pxssh.py b/tests/test_pxssh.py index f68a1cc..f447840 100644 --- a/tests/test_pxssh.py +++ b/tests/test_pxssh.py @@ -56,9 +56,9 @@ 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) + ssh = pxssh.pxssh(debug_command_string=True) tunnels = { 'local': ['2424:localhost:22'],'remote': ['2525:localhost:22'], 'dynamic': [8888] } confirmation_strings = 0 @@ -68,8 +68,34 @@ class PxsshTestCase(SSHTestBase): if confirmation in string: confirmation_strings+=1 - if confirmation_strings!=3: - assert False, 'String generated from tunneling is potientally incorrect.' + if confirmation_strings!=len(confirmation_array): + assert False, 'String generated from tunneling is incorrect.' + + def test_remote_ssh_tunnel_string(self): + ssh = pxssh.pxssh(debug_command_string=True) + tunnels = { 'local': ['2424:localhost:22'],'remote': ['2525:localhost:22'], + 'dynamic': [8888] } + confirmation_strings = 0 + confirmation_array = ['-R \'2525:localhost:22\'','-L \'2424:localhost:22\'','-D \'8888\''] + string = ssh.login('server', 'me', password='s3cret', ssh_tunnels=tunnels, spawn_local_ssh=False) + for confirmation in confirmation_array: + if confirmation in string: + confirmation_strings+=1 + + if confirmation_strings!=len(confirmation_array): + assert False, 'String generated from remote tunneling is incorrect.' + + def test_force_ssh_agent_sock_string(self): + ssh = pxssh.pxssh(debug_command_string=True) + confirmation_strings = 0 + confirmation_array = [' -A'] + string = ssh.login('server', 'me', password='s3cret', ssh_key=True) + for confirmation in confirmation_array: + if confirmation in string: + confirmation_strings+=1 + + if confirmation_strings!=len(confirmation_array): + assert False, 'String generated from forcing the SSH agent sock is incorrect.' if __name__ == '__main__': |