summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRed_M <1468433+Red-M@users.noreply.github.com>2018-03-30 12:18:49 +1000
committerGitHub <noreply@github.com>2018-03-30 12:18:49 +1000
commita2c3ba94b26346c29834cb38244b8d218bc4d882 (patch)
treead5c29387b4b5bde14ad06e6bddb3feea97bc259
parentaa0a2e42fb3167fff2350357f2a452c2a6ee50b4 (diff)
parent45108f0650c09680d0d0b7d7d3be4eeb86b8494d (diff)
downloadpexpect-a2c3ba94b26346c29834cb38244b8d218bc4d882.tar.gz
Merge pull request #480 from Red-M/master
Minor bug fix and basic test for SSH tunneling
-rw-r--r--pexpect/pxssh.py13
-rw-r--r--tests/test_pxssh.py14
2 files changed, 25 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..f68a1cc 100644
--- a/tests/test_pxssh.py
+++ b/tests/test_pxssh.py
@@ -56,6 +56,20 @@ 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_strings = 0
+ confirmation_array = ['-R 2525:localhost:22','-L 2424:localhost:22','-D 8888']
+ string = ssh.login('server', 'me', password='s3cret', ssh_tunnels=tunnels)
+ for confirmation in confirmation_array:
+ if confirmation in string:
+ confirmation_strings+=1
+
+ if confirmation_strings!=3:
+ assert False, 'String generated from tunneling is potientally incorrect.'
if __name__ == '__main__':