Removed defunct tests and fixed remaining tests

This commit is contained in:
Kevin F 2022-09-27 00:49:51 +00:00
parent 3852b15c89
commit 2eea681e98
17 changed files with 8 additions and 592 deletions

View File

@ -24,9 +24,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
def version(verbosity=5, function=logger.info):
"""Display the Onionr version."""
function('Onionr v%s (%s) (API v%s)' % (onionrvalues.ONIONR_VERSION,
platform.machine(),
onionrvalues.API_VERSION),
function('Onionr v%s (%s)' % (onionrvalues.ONIONR_VERSION,
platform.machine()),
terminal=True)
if verbosity >= 1:
function(onionrvalues.ONIONR_TAGLINE, terminal=True)

View File

@ -2,10 +2,6 @@
This file defines values and requirements used by Onionr
"""
import platform
import os
import filepaths
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -20,21 +16,11 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
DENIABLE_PEER_ADDRESS = "OVPCZLOXD6DC5JHX4EQ3PSOGAZ3T24F75HQLIUZSDSMYPEOXCPFA"
PASSWORD_LENGTH = 25
ONIONR_TAGLINE = 'Private P2P Communication - GPLv3 - https://Onionr.net'
ONIONR_VERSION = '9.0.0'
ONIONR_VERSION_CODENAME = 'Taraxacum'
ONIONR_VERSION_TUPLE = tuple(ONIONR_VERSION.split('.')) # (MAJOR, MINOR, VERSION)
API_VERSION = '2' # increments of 1; only change when something fundamental about how the API works changes. This way other nodes know how to communicate without learning too much information about you.
MIN_PY_VERSION = 7 # min version of 7 so we can take advantage of non-cyclic type hints
MIN_PY_VERSION = 10
DEVELOPMENT_MODE = False
"""Onionr user IDs are ed25519 keys, which are always 32 bytes in length"""
MAIN_PUBLIC_KEY_SIZE = 32
ORIG_RUN_DIR_ENV_VAR = 'ORIG_ONIONR_RUN_DIR'
DATABASE_LOCK_TIMEOUT = 60
BLOCK_EXPORT_FILE_EXT = '.onionr'

View File

@ -4,7 +4,7 @@ from time import sleep
import secrets
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
TEST_DIR = 'testdata/%s-%s' % (secrets.token_hex(1), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
@ -62,7 +62,6 @@ class OnionrServerPeerAnnounce(unittest.TestCase):
writer.write(address.encode('utf-8') + b'\n')
await writer.drain()
self.assertEqual(await reader.readexactly(1), int(1).to_bytes(1,'big'))
try:
await reader.readexactly(1)
except asyncio.IncompleteReadError:

View File

@ -4,7 +4,7 @@ from time import sleep
import secrets
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
TEST_DIR = 'testdata/%s-%s' % (secrets.token_hex(2), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR

View File

@ -12,7 +12,3 @@ with Popen(['./onionr.sh', 'details'], stdout=PIPE) as onionr_proc:
output = onionr_proc.stdout.read().decode()
if onionr_proc.returncode != 0:
raise ValueError('Raised non zero exit ' + str(onionr_proc.returncode))
for word in ['Human-readable']:
if word not in output:
raise ValueError(word + " not in " + output)

View File

@ -1,62 +0,0 @@
#!/usr/bin/env python3
import sys, os, random
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
TEST_DIR_1 = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
TEST_DIR_2 = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
import time
os.environ["ONIONR_HOME"] = TEST_DIR_1
from utils import createdirs
createdirs.create_dirs()
import onionrexceptions, onionrcrypto as crypto
from onionrusers import onionrusers
from onionrusers import contactmanager
class OnionrForwardSecrecyTests(unittest.TestCase):
'''
Tests both the onionrusers class and the contactmanager (which inherits it)
'''
def test_forward_encrypt_bin(self):
friend = crypto.generate()
friendUser = onionrusers.OnionrUser(friend[0], saveUser=True)
for x in range(5):
message = os.urandom(32)
forwardKey = friendUser.generateForwardKey()
fakeForwardPair = crypto.generate()
self.assertTrue(friendUser.addForwardKey(fakeForwardPair[0]))
encrypted = friendUser.forwardEncrypt(message)
decrypted = crypto.encryption.pub_key_decrypt(encrypted[0], privkey=fakeForwardPair[1], encodedData=True)
self.assertEqual(decrypted, message)
def test_forward_encrypt(self):
friend = crypto.generate()
friendUser = onionrusers.OnionrUser(friend[0], saveUser=True)
for x in range(5):
message = 'hello world %s' % (random.randint(1, 1000))
forwardKey = friendUser.generateForwardKey()
fakeForwardPair = crypto.generate()
self.assertTrue(friendUser.addForwardKey(fakeForwardPair[0]))
encrypted = friendUser.forwardEncrypt(message)
decrypted = crypto.encryption.pub_key_decrypt(encrypted[0], privkey=fakeForwardPair[1], encodedData=True)
self.assertEqual(decrypted, message.encode())
return
unittest.main()

View File

@ -1,17 +0,0 @@
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
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
from onionrutils import getopenport
class GetOpenPortTest(unittest.TestCase):
def test_open_port(self):
open_port = int(getopenport.get_open_port())
self.assertGreaterEqual(open_port, 1024)
unittest.main()

View File

@ -1,120 +0,0 @@
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid, hashlib, base64
import nacl.exceptions
import nacl.signing, nacl.hash, nacl.encoding
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrutils import stringvalidators, mnemonickeys
import onionrcrypto as crypto, onionrexceptions
class OnionrCryptoTests(unittest.TestCase):
def test_blake2b(self):
self.assertEqual(crypto.hashers.blake2b_hash('test'), crypto.hashers.blake2b_hash(b'test'))
self.assertEqual(crypto.hashers.blake2b_hash(b'test'), crypto.hashers.blake2b_hash(b'test'))
self.assertNotEqual(crypto.hashers.blake2b_hash(''), crypto.hashers.blake2b_hash(b'test'))
try:
crypto.hashers.blake2b_hash(None)
except nacl.exceptions.TypeError:
pass
else:
self.assertTrue(False)
self.assertEqual(nacl.hash.blake2b(b'test'), crypto.hashers.blake2b_hash(b'test'))
def test_sha3256(self):
hasher = hashlib.sha3_256()
self.assertEqual(crypto.hashers.sha3_hash('test'), crypto.hashers.sha3_hash(b'test'))
self.assertEqual(crypto.hashers.sha3_hash(b'test'), crypto.hashers.sha3_hash(b'test'))
self.assertNotEqual(crypto.hashers.sha3_hash(''), crypto.hashers.sha3_hash(b'test'))
try:
crypto.hashers.sha3_hash(None)
except TypeError:
pass
else:
self.assertTrue(False)
hasher.update(b'test')
normal = hasher.hexdigest()
self.assertEqual(crypto.hashers.sha3_hash(b'test'), normal)
def valid_default_id(self):
self.assertTrue(stringvalidators.validate_pub_key(crypto.pub_key))
def test_human_readable_length(self):
human = mnemonickeys.get_human_readable_ID()
self.assertTrue(len(human.split('-')) == 16)
def test_safe_compare(self):
self.assertTrue(crypto.cryptoutils.safe_compare('test', 'test'))
self.assertTrue(crypto.cryptoutils.safe_compare('test', b'test'))
self.assertFalse(crypto.cryptoutils.safe_compare('test', 'test2'))
try:
crypto.cryptoutils.safe_compare('test', None)
except TypeError:
pass
else:
self.assertTrue(False)
def test_asymmetric(self):
keyPair = crypto.generate()
keyPair2 = crypto.generate()
message = "hello world"
self.assertTrue(len(crypto.encryption.pub_key_encrypt(message, keyPair2[0], encodedData=True)) > 0)
encrypted = crypto.encryption.pub_key_encrypt(message, keyPair2[0], encodedData=False)
decrypted = crypto.encryption.pub_key_decrypt(encrypted, privkey=keyPair2[1], encodedData=False)
self.assertTrue(decrypted.decode() == message)
try:
crypto.encryption.pub_key_encrypt(None, keyPair2[0])
except TypeError:
pass
else:
self.assertTrue(False)
blankMessage = crypto.encryption.pub_key_encrypt('', keyPair2[0])
self.assertTrue('' == crypto.encryption.pub_key_decrypt(blankMessage, privkey=keyPair2[1], encodedData=False).decode())
# Try to encrypt arbitrary bytes
crypto.encryption.pub_key_encrypt(os.urandom(32), keyPair2[0])
def test_pub_from_priv(self):
priv = nacl.signing.SigningKey.generate().encode(encoder=nacl.encoding.Base32Encoder)
pub = crypto.cryptoutils.getpubfrompriv.get_pub_key_from_priv(priv)
self.assertTrue(stringvalidators.validate_pub_key(pub))
def test_deterministic(self):
password = os.urandom(32)
gen = crypto.generate_deterministic(password)
self.assertTrue(stringvalidators.validate_pub_key(gen[0]))
try:
crypto.generate_deterministic('weakpassword')
except onionrexceptions.PasswordStrengthError:
pass
else:
self.assertFalse(True)
try:
crypto.generate_deterministic(None)
except TypeError:
pass
else:
self.assertFalse(True)
gen = crypto.generate_deterministic('weakpassword', bypassCheck=True)
password = base64.b64encode(os.urandom(32))
gen1 = crypto.generate_deterministic(password)
gen2 = crypto.generate_deterministic(password)
self.assertFalse(gen == gen1)
self.assertTrue(gen1 == gen2)
self.assertTrue(stringvalidators.validate_pub_key(gen1[0]))
unittest.main()

View File

@ -1,41 +0,0 @@
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
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
from utils import createdirs
createdirs.create_dirs()
from coredb import keydb
import onionrsetup as setup, keymanager, filepaths
from onionrutils import stringvalidators
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
setup.setup_config()
pub_key = keymanager.KeyManager().getPubkeyList()[0]
class KeyManagerTest(unittest.TestCase):
def test_sane_default(self):
self.assertGreaterEqual(len(pub_key), 52)
self.assertLessEqual(len(pub_key), 56)
self.assertEqual(pub_key, keymanager.KeyManager().getPubkeyList()[0])
stringvalidators.validate_pub_key(pub_key)
def test_change(self):
new_key = keymanager.KeyManager().addKey()[0]
self.assertNotEqual(new_key, pub_key)
self.assertEqual(new_key, keymanager.KeyManager().getPubkeyList()[1])
stringvalidators.validate_pub_key(new_key)
def test_remove(self):
manager = keymanager.KeyManager()
new_key = manager.addKey()[0]
priv_key = manager.getPrivkey(new_key)
self.assertIn(new_key, manager.getPubkeyList())
with open(filepaths.keys_file, 'r') as keyfile:
self.assertIn(new_key, keyfile.read())
manager.removeKey(new_key)
with open(filepaths.keys_file, 'r') as keyfile:
self.assertNotIn(new_key, keyfile.read())
unittest.main()

View File

@ -1,31 +0,0 @@
import sys, os
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
import requests
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import onionrprocess
class TestOnionrProcess(unittest.TestCase):
def test_onionr_process(self):
def _sub_proc():
return 2
def _sub_proc_arg(arg):
return arg
def _sub_proc_kwarg(arg=''):
return arg
def _sub_proc_kwarg_default(arg=4):
return arg
def _sub_proc_both(arg, arg2=5):
return (arg, arg2)
self.assertEqual(onionrprocess.run_func_in_new_process(_sub_proc), 2)
self.assertEqual(onionrprocess.run_func_in_new_process(_sub_proc_arg, 3), 3)
self.assertEqual(onionrprocess.run_func_in_new_process(_sub_proc_kwarg, 4), 4)
self.assertEqual(onionrprocess.run_func_in_new_process(_sub_proc_kwarg_default), 4)
self.assertEqual(onionrprocess.run_func_in_new_process(_sub_proc_both, 6), (6, 5))
unittest.main()

View File

@ -10,10 +10,7 @@ print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from coredb import keydb
import onionrsetup as setup
from onionrthreads import add_onionr_thread
@ -25,7 +22,7 @@ class OnionrThreadsTests(unittest.TestCase):
def _test_func(obj_list):
obj_list.append(1)
add_onionr_thread(_test_func, 0.05, l, initial_sleep=0)
add_onionr_thread(_test_func, 0.05, "test", l, initial_sleep=0)
sleep(0.05)
self.assertGreaterEqual(len(l), 1)
@ -34,7 +31,8 @@ class OnionrThreadsTests(unittest.TestCase):
def _test_func(obj_list):
obj_list.append(1)
add_onionr_thread(_test_func, 0.05, l, initial_sleep=1)
add_onionr_thread(_test_func, 0.05, "test", l, initial_sleep=1)
sleep(0.05)
self.assertEqual(len(l), 0)

View File

@ -1,102 +0,0 @@
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
import json
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
import onionrexceptions
from onionrusers import onionrusers
from onionrusers import contactmanager
import onionrcrypto as crypto
from coredb import keydb
from utils import identifyhome
class OnionrUserTests(unittest.TestCase):
'''
Tests both the onionrusers class and the contactmanager (which inherits it)
'''
def test_users(self):
keypair = crypto.generate()
onionrusers.OnionrUser(keypair[0])
def test_contact_init_no_save(self):
contact = crypto.generate()[0]
contact = contactmanager.ContactManager(contact)
self.assertFalse(contact.publicKey in keydb.listkeys.list_pub_keys())
def test_contact_create(self):
contact = crypto.generate()[0]
contact = contactmanager.ContactManager(contact, saveUser=True)
self.assertTrue(contact.publicKey in keydb.listkeys.list_pub_keys())
def test_contact_set_info(self):
contact = crypto.generate()[0]
contact = contactmanager.ContactManager(contact, saveUser=True)
fileLocation = '%s/contacts/%s.json' % (identifyhome.identify_home(), contact.publicKey)
contact.set_info('alias', 'bob')
self.assertTrue(os.path.exists(fileLocation))
with open(fileLocation, 'r') as data:
data = data.read()
data = json.loads(data)
self.assertEqual(data['alias'], 'bob')
def test_contact_get_info(self):
contact = crypto.generate()[0]
contact = contactmanager.ContactManager(contact, saveUser=True)
fileLocation = '%s/contacts/%s.json' % (identifyhome.identify_home(), contact.publicKey)
with open(fileLocation, 'w') as contactFile:
contactFile.write('{"alias": "bob"}')
self.assertEqual(contact.get_info('alias', forceReload=True), 'bob')
self.assertEqual(contact.get_info('fail', forceReload=True), None)
self.assertEqual(contact.get_info('fail'), None)
def test_is_friend(self):
contact = crypto.generate()[0]
contact = onionrusers.OnionrUser(contact, saveUser=True)
self.assertFalse(contact.isFriend())
contact.setTrust(1)
self.assertTrue(contact.isFriend())
def test_encrypt(self):
contactPair = crypto.generate()
contact = contactmanager.ContactManager(contactPair[0], saveUser=True)
encrypted = contact.encrypt('test')
decrypted = crypto.encryption.pub_key_decrypt(encrypted, privkey=contactPair[1], encodedData=True).decode()
self.assertEqual('test', decrypted)
def test_delete_contact(self):
contact = crypto.generate()[0]
contact = contactmanager.ContactManager(contact, saveUser=True)
fileLocation = '%s/contacts/%s.json' % (identifyhome.identify_home(), contact.publicKey)
self.assertFalse(os.path.exists(fileLocation))
with open(fileLocation, 'w') as contactFile:
contactFile.write('{"alias": "test"}')
self.assertTrue(os.path.exists(fileLocation))
contact.delete_contact()
self.assertFalse(os.path.exists(fileLocation))
try:
contact.get_info('alias')
except onionrexceptions.ContactDeleted:
pass
else:
self.assertTrue(False)
try:
contact.set_info('alias', 'test2')
except onionrexceptions.ContactDeleted:
pass
else:
self.assertTrue(False)
unittest.main()

View File

@ -1,27 +0,0 @@
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
import json
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import identifyhome, createdirs
import onionrvalues
class TestOnionrValues(unittest.TestCase):
def test_api_version(self):
self.assertEqual(onionrvalues.API_VERSION, '2')
def test_default_expire(self):
self.assertEqual(onionrvalues.DEFAULT_EXPIRE, 2678400)
def test_block_clock_skew(self):
self.assertEqual(onionrvalues.MAX_BLOCK_CLOCK_SKEW, 120)
def test_block_export_ext(self):
self.assertEqual(onionrvalues.BLOCK_EXPORT_FILE_EXT, '.onionr')
unittest.main()

View File

@ -1,39 +0,0 @@
#!/usr/bin/env python3
import sys, os
from time import sleep
import tempfile
sys.path.append(".")
sys.path.append("src/")
import uuid
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import unittest, json
from utils import identifyhome, createdirs, readoffset
from onionrsetup import setup_config
createdirs.create_dirs()
setup_config()
class TestReadOffset(unittest.TestCase):
def test_read_offset(self):
temp = tempfile.mkstemp()[1]
f = open(temp, 'wb')
data = b"test1\ntest2\ntest3\test4"
f.write(data)
f.close()
self.assertEqual(readoffset.read_from_offset(temp, 5).data, data[5:])
self.assertEqual(readoffset.read_from_offset(temp, 5).new_offset, len(data))
os.remove(temp)
def test_read_whole(self):
temp = tempfile.mkstemp()[1]
f = open(temp, 'wb')
data = b"test1\ntest2\ntest3\test4"
f.write(data)
f.close()
self.assertEqual(readoffset.read_from_offset(temp).data, data)
self.assertEqual(readoffset.read_from_offset(temp).new_offset, len(data))
os.remove(temp)
unittest.main()

View File

@ -1,36 +0,0 @@
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
import time
import math
from deadsimplekv import DeadSimpleKV
import setupkvvars
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from coredb import keydb
import onionrsetup as setup
from utils import createdirs
setup.setup_config()
class SetupKVVarsTest(unittest.TestCase):
def test_set_var_values(self):
kv = DeadSimpleKV()
setupkvvars.setup_kv(kv)
self.assertFalse(kv.get('shutdown'))
self.assertEqual(kv.get('generating_blocks'), [])
self.assertEqual(kv.get('lastNodeSeen'), None)
self.assertAlmostEqual(math.floor(kv.get('startTime')), math.floor(time.time()), places=0)
self.assertTrue(kv.get('isOnline'))
unittest.main()

View File

@ -1,58 +0,0 @@
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
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
from onionrutils import stringvalidators
class OnionrValidations(unittest.TestCase):
def test_hash_validator(self):
valid = ['00003b3813a166e706e490238e9515633cc3d083efe982a67753d50d87a00c96\n', '00003b3813a166e706e490238e9515633cc3d083efe982a67753d50d87a00c96', b'00003b3813a166e706e490238e9515633cc3d083efe982a67753d50d87a00c96',
'00003b3813a166e706e490238e9515633cc36', b'00003b3813a166e706e490238e9515633cc3d083']
invalid = [None, 0, 1, True, False, '%#W483242#', '00003b3813a166e706e490238e9515633cc3d083efe982a67753d50d87a00c9666', '', b'',
b'00003b3813a166e706e490238e9515633cc3d083efe982a67753d50d87a00c9666666', b' ', '\n', '00003b3813a166e706e490238e9515633cc3d083efe982a67753d50d87a00ccccc\n']
for x in valid:
self.assertTrue(stringvalidators.validate_hash(x))
for x in invalid:
try:
result = stringvalidators.validate_hash(x)
print('testing', x, result)
except AttributeError:
result = False
try:
self.assertFalse(result)
except AssertionError:
raise AssertionError("%s returned true" % (x,))
def test_pubkey_validator(self):
# Test ed25519 public key validity
valids = ['JZ5VE72GUS3C7BOHDRIYZX4B5U5EJMCMLKHLYCVBQQF3UKHYIRRQ====', 'JZ5VE72GUS3C7BOHDRIYZX4B5U5EJMCMLKHLYCVBQQF3UKHYIRRQ']
invalid = [None, '', ' ', 'dfsg', '\n', 'JZ5VE72GUS3C7BOHDRIYZX4B5U5EJMCMLKHLYCVBQQF3UKHYIR$Q====']
for valid in valids:
print('testing', valid)
self.assertTrue(stringvalidators.validate_pub_key(valid))
for x in invalid:
#print('testing', x)
self.assertFalse(stringvalidators.validate_pub_key(x))
def test_integer_string(self):
valid = ["1", "100", 100, "-5", -5]
invalid = ['test', "1d3434", "1e100", None]
for x in valid:
#print('testing', x)
self.assertTrue(stringvalidators.is_integer_string(x))
for x in invalid:
#print('testing', x)
self.assertFalse(stringvalidators.is_integer_string(x))
unittest.main()

View File

@ -1,29 +0,0 @@
#!/usr/bin/env python3
import unittest, sys, uuid, os
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
sys.path.append(".")
sys.path.append("src/")
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import reconstructhash
class ZFill_Hash(unittest.TestCase):
def test_reconstruct(self):
h = b"4d20d791cbc293999b97cc627aa011692d317dede3d0fbd390c763210b0d"
self.assertEqual(reconstructhash.reconstruct_hash(h), b"0000" + h)
h = b"4d20d791cbc293999b97cc627aa011692d317dede3d0fbd390c763210b0d"
self.assertEqual(reconstructhash.reconstruct_hash(h, 62), b"00" + h)
def test_deconstruct(self):
h = b"0000e918d24999ad9b0ff00c1d414f36b74afc93871a0ece4bd452f82b56af87"
h_no = b"e918d24999ad9b0ff00c1d414f36b74afc93871a0ece4bd452f82b56af87"
self.assertEqual(reconstructhash.deconstruct_hash(h), h_no)
h = "0000e918d24999ad9b0ff00c1d414f36b74afc93871a0ece4bd452f82b56af87"
h_no = "e918d24999ad9b0ff00c1d414f36b74afc93871a0ece4bd452f82b56af87"
self.assertEqual(reconstructhash.deconstruct_hash(h), h_no)
unittest.main()