diff options
-rw-r--r-- | src/test/include.am | 3 | ||||
-rw-r--r-- | src/test/test_rebind.py | 64 | ||||
-rwxr-xr-x | src/test/test_rebind.sh | 7 |
3 files changed, 74 insertions, 0 deletions
diff --git a/src/test/include.am b/src/test/include.am index 81b089b8f7..cb94490302 100644 --- a/src/test/include.am +++ b/src/test/include.am @@ -33,6 +33,7 @@ endif if USEPYTHON TESTSCRIPTS += src/test/test_ntor.sh src/test/test_hs_ntor.sh src/test/test_bt.sh +TESTSCRIPTS += src/test/test_rebind.sh endif TESTS += src/test/test src/test/test-slow src/test/test-memwipe \ @@ -342,6 +343,8 @@ EXTRA_DIST += \ src/test/hs_indexes.py \ src/test/fuzz_static_testcases.sh \ src/test/slownacl_curve25519.py \ + src/test/test_rebind.sh \ + src/test/test_rebind.py \ src/test/zero_length_keys.sh \ src/test/rust_supp.txt \ src/test/test_keygen.sh \ diff --git a/src/test/test_rebind.py b/src/test/test_rebind.py new file mode 100644 index 0000000000..582e496012 --- /dev/null +++ b/src/test/test_rebind.py @@ -0,0 +1,64 @@ +import sys +import subprocess +import socket +import os +import time + +def try_connecting_to_socksport(): + socks_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + if socks_socket.connect_ex(('127.0.0.1', 9052)): + tor_process.terminate() + print 'FAIL' + sys.exit('Cannot connect to SOCKSPort') + socks_socket.close() + +def wait_for_log(s): + while True: + l = tor_process.stdout.readline() + if s in l: + return + +if not os.path.exists(sys.argv[1]): + sys.exit('ERROR: cannot find tor at %s' % sys.argv[1]) + +tor_path = sys.argv[1] + +tor_process = subprocess.Popen([tor_path, + '-ControlPort', '127.0.0.1:9053', + '-SOCKSPort', '127.0.0.1:9052', + '-FetchServerDescriptors', '0'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + +if tor_process == None: + sys.exit('ERROR: running tor failed') + +if len(sys.argv) < 2: + sys.exit('Usage: %s <path-to-tor>' % sys.argv[0]) + +wait_for_log('Opened Control listener on') + +try_connecting_to_socksport() + +control_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +if control_socket.connect_ex(('127.0.0.1', 9053)): + tor_process.terminate() + print 'FAIL' + sys.exit('Cannot connect to ControlPort') + +control_socket.sendall('AUTHENTICATE \r\n') +control_socket.sendall('SETCONF SOCKSPort=0.0.0.0:9052\r\n') +wait_for_log('Opened Socks listener') + +try_connecting_to_socksport() + +control_socket.sendall('SETCONF SOCKSPort=127.0.0.1:9052\r\n') +wait_for_log('Opened Socks listener') + +try_connecting_to_socksport() + +control_socket.sendall('SIGNAL HALT\r\n') + +time.sleep(0.1) +print 'OK' +tor_process.terminate() diff --git a/src/test/test_rebind.sh b/src/test/test_rebind.sh new file mode 100755 index 0000000000..47f38afc45 --- /dev/null +++ b/src/test/test_rebind.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +exitcode=0 + +"${PYTHON:-python}" "${abs_top_srcdir:-.}/src/test/test_rebind.py" "${TESTING_TOR_BINARY}" || exitcode=1 + +exit ${exitcode} |