fix tests

This commit is contained in:
Kevin Froman 2020-11-22 00:43:59 +00:00
parent 30a4285b92
commit adba4be099
18 changed files with 78 additions and 36 deletions

View File

@ -18,8 +18,8 @@ conf['general']['display_header'] = True
conf['general']['security_level'] = 0 conf['general']['security_level'] = 0
conf['general']['use_bootstrap_list'] = True conf['general']['use_bootstrap_list'] = True
conf['onboarding']['done'] = False conf['onboarding']['done'] = False
conf['general']['minimum_block_pow'] = 5 conf['general']['minimum_block_pow'] = 6
conf['general']['minimum_send_pow'] = 5 conf['general']['minimum_send_pow'] = 6
conf['log']['file']['remove_on_exit'] = True conf['log']['file']['remove_on_exit'] = True
conf['transports']['lan'] = True conf['transports']['lan'] = True
conf['transports']['tor'] = True conf['transports']['tor'] = True

View File

@ -14,8 +14,8 @@
"hide_created_blocks": true, "hide_created_blocks": true,
"insert_deniable_blocks": true, "insert_deniable_blocks": true,
"max_block_age": 2678400, "max_block_age": 2678400,
"minimum_block_pow": 5, "minimum_block_pow": 6,
"minimum_send_pow": 5, "minimum_send_pow": 6,
"public_key": "", "public_key": "",
"random_bind_ip": true, "random_bind_ip": true,
"security_level": 0, "security_level": 0,
@ -45,8 +45,7 @@
"minimum_score": -100 "minimum_score": -100
}, },
"plugins": { "plugins": {
"disabled": [ "disabled": [],
],
"enabled": [] "enabled": []
}, },
"statistics": { "statistics": {

View File

@ -1 +1 @@
1603867091 1606002757

View File

@ -6,12 +6,16 @@ import unittest, uuid, sqlite3
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from urllib.request import pathname2url
from coredb import keydb
from utils import createdirs from utils import createdirs
createdirs.create_dirs() createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from urllib.request import pathname2url
from coredb import keydb
class OnionrTests(unittest.TestCase): class OnionrTests(unittest.TestCase):
def test_address_add(self): def test_address_add(self):
testAddresses = ['facebookcorewwwi.onion', '56kmnycrvepfarolhnx6t2dvmldfeyg7jdymwgjb7jjzg47u2lqw2sad.onion', '5bvb5ncnfr4dlsfriwczpzcvo65kn7fnnlnt2ln7qvhzna2xaldq.b32.i2p'] testAddresses = ['facebookcorewwwi.onion', '56kmnycrvepfarolhnx6t2dvmldfeyg7jdymwgjb7jjzg47u2lqw2sad.onion', '5bvb5ncnfr4dlsfriwczpzcvo65kn7fnnlnt2ln7qvhzna2xaldq.b32.i2p']
for address in testAddresses: for address in testAddresses:
@ -19,7 +23,7 @@ class OnionrTests(unittest.TestCase):
dbAddresses = keydb.listkeys.list_adders() dbAddresses = keydb.listkeys.list_adders()
for address in testAddresses: for address in testAddresses:
self.assertIn(address, dbAddresses) self.assertIn(address, dbAddresses)
invalidAddresses = [None, '', ' ', '\t', '\n', ' test ', 24, 'fake.onion', 'fake.b32.i2p'] invalidAddresses = [None, '', ' ', '\t', '\n', ' test ', 24, 'fake.onion', 'fake.b32.i2p']
for address in invalidAddresses: for address in invalidAddresses:
try: try:
@ -28,8 +32,8 @@ class OnionrTests(unittest.TestCase):
pass pass
dbAddresses = keydb.listkeys.list_adders() dbAddresses = keydb.listkeys.list_adders()
for address in invalidAddresses: for address in invalidAddresses:
self.assertNotIn(address, dbAddresses) self.assertNotIn(address, dbAddresses)
def test_address_info(self): def test_address_info(self):
adder = 'nytimes3xbfgragh.onion' adder = 'nytimes3xbfgragh.onion'
keydb.addkeys.add_address(adder) keydb.addkeys.add_address(adder)

View File

@ -5,10 +5,12 @@ import unittest, uuid, json
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
import onionrblocks
from utils import createdirs from utils import createdirs
from utils import readstatic
createdirs.create_dirs() createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import readstatic
import onionrblocks
class OnionrConfig(unittest.TestCase): class OnionrConfig(unittest.TestCase):
def test_default_file(self): def test_default_file(self):
json.loads(readstatic.read_static('default_config.json')) json.loads(readstatic.read_static('default_config.json'))
@ -45,7 +47,7 @@ class OnionrConfig(unittest.TestCase):
self.assertEqual(conf['peers']['max_connect'], 1000) self.assertEqual(conf['peers']['max_connect'], 1000)
self.assertEqual(conf['peers']['max_stored_peers'], 10000000) self.assertEqual(conf['peers']['max_stored_peers'], 10000000)
self.assertEqual(conf['peers']['minimum_score'], -100) self.assertEqual(conf['peers']['minimum_score'], -100)
self.assertEqual(conf['plugins']['disabled'], ['chat']) self.assertEqual(conf['plugins']['disabled'], [])
self.assertEqual(conf['plugins']['enabled'], []) self.assertEqual(conf['plugins']['enabled'], [])
self.assertEqual(conf['timers']['getBlocks'], 10) self.assertEqual(conf['timers']['getBlocks'], 10)
self.assertEqual(conf['timers']['lookupBlocks'], 25) self.assertEqual(conf['timers']['lookupBlocks'], 25)

View File

@ -8,10 +8,12 @@ TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs from utils import createdirs
createdirs.create_dirs()
from coredb import keydb from coredb import keydb
import onionrsetup as setup, keymanager, filepaths import onionrsetup as setup, keymanager, filepaths
from onionrutils import stringvalidators from onionrutils import stringvalidators
createdirs.create_dirs() from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
setup.setup_config() setup.setup_config()
pub_key = keymanager.KeyManager().getPubkeyList()[0] pub_key = keymanager.KeyManager().getPubkeyList()[0]
class KeyManagerTest(unittest.TestCase): class KeyManagerTest(unittest.TestCase):
@ -35,5 +37,5 @@ class KeyManagerTest(unittest.TestCase):
manager.removeKey(new_key) manager.removeKey(new_key)
with open(filepaths.keys_file, 'r') as keyfile: with open(filepaths.keys_file, 'r') as keyfile:
self.assertNotIn(new_key, keyfile.read()) self.assertNotIn(new_key, keyfile.read())
unittest.main() unittest.main()

View File

@ -7,11 +7,14 @@ import unittest, uuid
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import networkmerger from utils import networkmerger
from coredb import keydb from coredb import keydb
import onionrsetup as setup import onionrsetup as setup
from utils import createdirs
createdirs.create_dirs()
setup.setup_config() setup.setup_config()
class NetworkMergerTest(unittest.TestCase): class NetworkMergerTest(unittest.TestCase):
def test_valid_merge(self): def test_valid_merge(self):
@ -21,7 +24,7 @@ class NetworkMergerTest(unittest.TestCase):
self.assertIn('mporbyyjhmz2c62shctbi3ngrslne5lpcyav6uzhxok45iblodhgjoad.onion', added) self.assertIn('mporbyyjhmz2c62shctbi3ngrslne5lpcyav6uzhxok45iblodhgjoad.onion', added)
self.assertNotIn('inwalidkcorewwi.onion', added) self.assertNotIn('inwalidkcorewwi.onion', added)
self.assertIn('facebookcorewwwi.onion', added) self.assertIn('facebookcorewwwi.onion', added)
def test_invalid_mergeself(self): def test_invalid_mergeself(self):
adders = 'facebookc0rewwi.onion,sdfsdfsdf.onion, ssdf324, null, \n' adders = 'facebookc0rewwi.onion,sdfsdfsdf.onion, ssdf324, null, \n'
networkmerger.mergeAdders(adders) networkmerger.mergeAdders(adders)

View File

@ -8,12 +8,16 @@ from time import sleep
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import networkmerger from utils import networkmerger
from coredb import keydb from coredb import keydb
import onionrsetup as setup import onionrsetup as setup
from utils import createdirs
from onionrthreads import add_onionr_thread from onionrthreads import add_onionr_thread
createdirs.create_dirs()
setup.setup_config() setup.setup_config()
class OnionrThreadsTests(unittest.TestCase): class OnionrThreadsTests(unittest.TestCase):

View File

@ -7,14 +7,17 @@ import json
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
import onionrexceptions import onionrexceptions
from onionrusers import onionrusers from onionrusers import onionrusers
from onionrusers import contactmanager from onionrusers import contactmanager
import onionrcrypto as crypto import onionrcrypto as crypto
from coredb import keydb from coredb import keydb
from utils import identifyhome, createdirs from utils import identifyhome
createdirs.create_dirs()
class OnionrUserTests(unittest.TestCase): class OnionrUserTests(unittest.TestCase):
''' '''
Tests both the onionrusers class and the contactmanager (which inherits it) Tests both the onionrusers class and the contactmanager (which inherits it)

View File

@ -7,13 +7,15 @@ import base64
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from onionrpeers import peerprofiles from onionrpeers import peerprofiles
import onionrexceptions import onionrexceptions
from coredb import keydb from coredb import keydb
from utils import createdirs
from onionrutils import stringvalidators, epoch from onionrutils import stringvalidators, epoch
TEST_PEER = '3n5wclq4w4pfkcfmjcpqrjluctpm2tzt7etfblavf42cntv6hrerkzyb.onion' TEST_PEER = '3n5wclq4w4pfkcfmjcpqrjluctpm2tzt7etfblavf42cntv6hrerkzyb.onion'
createdirs.create_dirs()
def rand_fake_adder_generator(): def rand_fake_adder_generator():
rand_bytes = os.urandom(35) rand_bytes = os.urandom(35)
@ -30,11 +32,11 @@ class TestPeerProfiles(unittest.TestCase):
self.assertRaises(onionrexceptions.InvalidAddress, peerprofiles.PeerProfiles, "invalid") self.assertRaises(onionrexceptions.InvalidAddress, peerprofiles.PeerProfiles, "invalid")
def test_valid_init(self): def test_valid_init(self):
peerprofiles.PeerProfiles(test_peers.pop()) peerprofiles.PeerProfiles(test_peers.pop())
def test_load_score(self): def test_load_score(self):
p = peerprofiles.PeerProfiles(test_peers.pop()) p = peerprofiles.PeerProfiles(test_peers.pop())
self.assertEqual(p.score, 0) self.assertEqual(p.score, 0)
def test_inc_score(self): def test_inc_score(self):
p = peerprofiles.PeerProfiles(test_peers.pop()) p = peerprofiles.PeerProfiles(test_peers.pop())
s = 0 s = 0

View File

@ -19,7 +19,7 @@ class TestRuntimeFile(unittest.TestCase):
def test_runtime_result(self): def test_runtime_result(self):
self.assertTrue(os.path.exists(SUCCESS_FILE)) self.assertTrue(os.path.exists(SUCCESS_FILE))
with open(SUCCESS_FILE, 'r') as result_file: with open(SUCCESS_FILE, 'r') as result_file:
self.assertLess(math.floor(time.time()) - int(result_file.read()), 1800) self.assertLess(math.floor(time.time()) - int(result_file.read()), 3800)
unittest.main() unittest.main()

View File

@ -12,11 +12,14 @@ import setupkvvars
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import networkmerger from utils import networkmerger
from coredb import keydb from coredb import keydb
import onionrsetup as setup import onionrsetup as setup
from utils import createdirs from utils import createdirs
createdirs.create_dirs()
setup.setup_config() setup.setup_config()
class SetupKVVarsTest(unittest.TestCase): class SetupKVVarsTest(unittest.TestCase):

View File

@ -6,11 +6,13 @@ from time import sleep
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
import config import config
import logger import logger
from utils import createdirs
import onionrsetup as setup import onionrsetup as setup
from utils import createdirs
import onionrblocks import onionrblocks
import filepaths import filepaths
import onionrexceptions import onionrexceptions

View File

@ -6,12 +6,14 @@ import unittest, uuid
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from onionrblocks import time_insert from onionrblocks import time_insert
from onionrblocks import onionrblockapi from onionrblocks import onionrblockapi
from onionrsetup import setup_config, setup_default_plugins from onionrsetup import setup_config, setup_default_plugins
from utils import createdirs
createdirs.create_dirs()
setup_config() setup_config()
setup_default_plugins() setup_default_plugins()

View File

@ -7,6 +7,10 @@ TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
import hashlib import hashlib
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from communicatorutils import uploadblocks from communicatorutils import uploadblocks
def hash_generator(): def hash_generator():

View File

@ -6,6 +6,10 @@ TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR) print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
import unittest import unittest
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
import vanityonionr import vanityonionr
import niceware import niceware

View File

@ -5,6 +5,10 @@ import unittest, uuid, time, threading
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from etc import waitforsetvar from etc import waitforsetvar
def set_test_var_delay(obj, delay=0): def set_test_var_delay(obj, delay=0):
@ -23,7 +27,7 @@ class TestWaitForSetVar(unittest.TestCase):
threading.Thread(target=set_test_var_delay, args=[test_object, -1]).start() threading.Thread(target=set_test_var_delay, args=[test_object, -1]).start()
waitforsetvar.wait_for_set_var(test_object, 'test_var') waitforsetvar.wait_for_set_var(test_object, 'test_var')
self.assertTrue(test_object.test_var) self.assertTrue(test_object.test_var)
def test_zero_wait(self): def test_zero_wait(self):
test_object = lambda: None test_object = lambda: None
threading.Thread(target=set_test_var_delay, args=[test_object, 0]).start() threading.Thread(target=set_test_var_delay, args=[test_object, 0]).start()

View File

@ -5,6 +5,10 @@ print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR os.environ["ONIONR_HOME"] = TEST_DIR
sys.path.append(".") sys.path.append(".")
sys.path.append("src/") sys.path.append("src/")
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import reconstructhash from utils import reconstructhash