From 29dd235872a633e694277af4128fcabdcc3c242c Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Mon, 1 Mar 2021 19:45:40 +0200 Subject: [PATCH] Block UDP 53 in test_bootstrap_tor using subprocess call of iptables --- src/tests/core.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tests/core.py b/src/tests/core.py index 52cea234..4857951a 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -18,6 +18,7 @@ import unittest import protocol import state +import subprocess import helper_sent import helper_addressbook @@ -263,9 +264,22 @@ class TestCore(unittest.TestCase): def test_bootstrap_tor(self): """test bootstrapping with tor""" BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'SOCKS5') + iptables_rule = [ + 'OUTPUT', '-p', 'udp', '--dport', '53', '-j', 'REJECT'] + try: + subprocess.call(['sudo', 'iptables', '-A'] + iptables_rule) + except OSError: + print('Failed to use iptables ):') + else: + with self.assertRaises(socket.gaierror): + socket.getaddrinfo('bootstrap8080.bitmessage.org', 8444) self._initiate_bootstrap() self._check_connection() self._check_knownnodes() + try: + subprocess.call(['sudo', 'iptables', '-D'] + iptables_rule) + except OSError: + pass @unittest.skipIf(tor_port_free, 'no running tor detected') def test_onionservicesonly(self):