onionr/tests/test_networkmerger.py

36 lines
1.2 KiB
Python
Raw Permalink Normal View History

2019-07-26 05:55:20 +00:00
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
2019-11-21 09:26:23 +00:00
sys.path.append("src/")
2019-07-26 05:55:20 +00:00
import unittest, uuid
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
2020-11-22 00:43:59 +00:00
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
2019-12-10 10:46:36 +00:00
from utils import networkmerger
2019-07-26 05:55:20 +00:00
from coredb import keydb
import onionrsetup as setup
2019-08-05 23:09:04 +00:00
setup.setup_config()
2019-07-26 05:55:20 +00:00
class NetworkMergerTest(unittest.TestCase):
def test_valid_merge(self):
adders = 'facebookcorewwwi.onion,mporbyyjhmz2c62shctbi3ngrslne5lpcyav6uzhxok45iblodhgjoad.onion'
networkmerger.mergeAdders(adders)
added = keydb.listkeys.list_adders()
self.assertIn('mporbyyjhmz2c62shctbi3ngrslne5lpcyav6uzhxok45iblodhgjoad.onion', added)
self.assertNotIn('inwalidkcorewwi.onion', added)
self.assertIn('facebookcorewwwi.onion', added)
2020-11-22 00:43:59 +00:00
2019-07-26 05:55:20 +00:00
def test_invalid_mergeself(self):
adders = 'facebookc0rewwi.onion,sdfsdfsdf.onion, ssdf324, null, \n'
networkmerger.mergeAdders(adders)
added = keydb.listkeys.list_adders()
for adder in adders:
self.assertNotIn(adder, added)
2019-09-13 02:22:25 +00:00
unittest.main()