summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_expect.py11
-rw-r--r--tests/test_pxssh.py50
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/test_expect.py b/tests/test_expect.py
index ec55d43..795518a 100755
--- a/tests/test_expect.py
+++ b/tests/test_expect.py
@@ -408,6 +408,17 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase):
p.buffer = b'Testing'
p.sendeof ()
+ def test_before_across_chunks(self):
+ # https://github.com/pexpect/pexpect/issues/478
+ child = pexpect.spawn(
+ '''/bin/bash -c "openssl rand -base64 {} | head -500 | nl --number-format=rz --number-width=5 2>&1 ; echo 'PATTERN!!!'"'''.format(1024 * 1024 * 2),
+ searchwindowsize=128
+ )
+ child.expect(['PATTERN'])
+ assert len(child.before.splitlines()) == 500
+ assert child.after == b'PATTERN'
+ assert child.buffer == b'!!!\r\n'
+
def _before_after(self, p):
p.timeout = 5
diff --git a/tests/test_pxssh.py b/tests/test_pxssh.py
index 3b3e50b..285ec73 100644
--- a/tests/test_pxssh.py
+++ b/tests/test_pxssh.py
@@ -57,6 +57,56 @@ class PxsshTestCase(SSHTestBase):
else:
assert False, 'should have raised exception, pxssh.ExceptionPxssh'
+ def test_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)
+ for confirmation in confirmation_array:
+ if confirmation in string:
+ confirmation_strings+=1
+
+ 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_ssh_key_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.'
+
+ confirmation_strings = 0
+ confirmation_array = [' -i True']
+ 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 adding an SSH key is incorrect.'
+
if __name__ == '__main__':
unittest.main()