From 103c7a6cfa6e2f4f0e152dfbda3d82026fd725a9 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Thu, 13 Apr 2023 21:00:31 +0300 Subject: [PATCH] Add a simple blind test for process running with --socks-proxy --- minode/tests/test_process.py | 23 +++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 24 insertions(+) diff --git a/minode/tests/test_process.py b/minode/tests/test_process.py index 3d7b51e..386e40a 100644 --- a/minode/tests/test_process.py +++ b/minode/tests/test_process.py @@ -18,6 +18,11 @@ try: i2p_port_free = True except (OSError, socket.error): i2p_port_free = False +try: + socket.socket().bind(('127.0.0.1', 9050)) + tor_port_free = True +except (OSError, socket.error): + tor_port_free = False class TestProcessProto(unittest.TestCase): @@ -185,3 +190,21 @@ class TestProcessI2P(TestProcess): class TestProcessNoI2P(TestProcessShutdown): """Test minode process shutdown with --i2p and no IP""" _process_cmd = ['minode', '--i2p', '--no-ip'] + + +@unittest.skipIf(tor_port_free, 'No running tor detected') +class TestProcessTor(TestProcessProto): + """A test case for minode process running with tor enabled""" + _process_cmd = ['minode', '--socks-proxy', '127.0.0.1:9050'] + _wait_time = 60 + + def test_connections(self): + """Check minode process connections""" + for _ in range(self._wait_time): + time.sleep(0.5) + connections = self.connections() + for c in connections: + self.assertEqual(c.raddr[0], '127.0.0.1') + self.assertEqual(c.raddr[1], 9050) + if len(connections) > self._connection_limit / 2: + break diff --git a/requirements.txt b/requirements.txt index e560573..8082633 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ coverage psutil +PySocks