Fixed some mistakes in tor dependent tests and marked them

for skipping until the finish of debug.
This commit is contained in:
Dmitri Bogomolov 2019-10-21 15:20:29 +03:00
parent e3ccc3c7c8
commit 2bddae511a
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 32 additions and 17 deletions

View File

@ -1,4 +1,3 @@
python_prctl python_prctl
psutil psutil
pycrypto pycrypto
stem

View File

@ -14,14 +14,19 @@ import unittest
import knownnodes import knownnodes
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_startup import start_proxyconfig
from helper_msgcoding import MsgEncode, MsgDecode from helper_msgcoding import MsgEncode, MsgDecode
from helper_startup import start_proxyconfig
from network import asyncore_pollchoose as asyncore from network import asyncore_pollchoose as asyncore
from network.connectionpool import BMConnectionPool from network.connectionpool import BMConnectionPool
from network.node import Peer from network.node import Peer
from network.tcp import Socks4aBMConnection, Socks5BMConnection, TCPConnection from network.tcp import Socks4aBMConnection, Socks5BMConnection, TCPConnection
from queues import excQueue from queues import excQueue
try:
import stem.version as stem_version
except ImportError:
stem_version = None
knownnodes_file = os.path.join(state.appdata, 'knownnodes.dat') knownnodes_file = os.path.join(state.appdata, 'knownnodes.dat')
@ -171,12 +176,29 @@ class TestCore(unittest.TestCase):
self.assertIsInstance(con, connection_base) self.assertIsInstance(con, connection_base)
self.assertNotEqual(peer.host, '127.0.0.1') self.assertNotEqual(peer.host, '127.0.0.1')
return return
else: # pylint: disable=useless-else-on-loop self.fail(
self.fail( 'Failed to connect during %s sec' % (time.time() - _started))
'Failed to connect during %s sec' % (time.time() - _started))
def test_onionservicesonly(self): def test_bootstrap(self):
"""test onionservicesonly networking mode""" """test bootstrapping"""
self._initiate_bootstrap()
self._check_bootstrap()
@unittest.skipUnless(stem_version, 'No stem, skipping tor dependent test')
def test_bootstrap_tor(self):
"""test bootstrapping with tor"""
self._initiate_bootstrap()
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'stem')
start_proxyconfig()
self._check_bootstrap()
@unittest.skipUnless(stem_version, 'No stem, skipping tor dependent test')
def test_onionservicesonly(self): # this should start after bootstrap
"""
set onionservicesonly, wait for 3 connections and check them all
are onions
"""
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'SOCKS5')
BMConfigParser().set('bitmessagesettings', 'onionservicesonly', 'true') BMConfigParser().set('bitmessagesettings', 'onionservicesonly', 'true')
self._initiate_bootstrap() self._initiate_bootstrap()
BMConfigParser().remove_option('bitmessagesettings', 'dontconnect') BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
@ -185,21 +207,15 @@ class TestCore(unittest.TestCase):
for n, peer in enumerate(BMConnectionPool().outboundConnections): for n, peer in enumerate(BMConnectionPool().outboundConnections):
if n > 2: if n > 2:
return return
if not peer.host.endswith('.onion'): if (
not peer.host.endswith('.onion')
and not peer.host.startswith('bootstrap')
):
self.fail( self.fail(
'Found non onion hostname %s in outbound connections!' 'Found non onion hostname %s in outbound connections!'
% peer.host) % peer.host)
self.fail('Failed to connect to at least 3 nodes within 360 sec') self.fail('Failed to connect to at least 3 nodes within 360 sec')
def test_bootstrap(self):
"""test bootstrapping"""
self._initiate_bootstrap()
self._check_bootstrap()
self._initiate_bootstrap()
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'stem')
start_proxyconfig()
self._check_bootstrap()
def run(): def run():
"""Starts all tests defined in this module""" """Starts all tests defined in this module"""