adjust test to use new stringvalidation module
This commit is contained in:
parent
122eb4ee5f
commit
a5a50a84d4
129
onionr/core.py
129
onionr/core.py
@ -42,76 +42,75 @@ class Core:
|
|||||||
if not self.dataDir.endswith('/'):
|
if not self.dataDir.endswith('/'):
|
||||||
self.dataDir += '/'
|
self.dataDir += '/'
|
||||||
|
|
||||||
#try:
|
try:
|
||||||
self.usageFile = self.dataDir + 'disk-usage.txt'
|
self.usageFile = self.dataDir + 'disk-usage.txt'
|
||||||
self.config = config
|
self.config = config
|
||||||
self.maxBlockSize = 10000000 # max block size in bytes
|
self.maxBlockSize = 10000000 # max block size in bytes
|
||||||
|
|
||||||
self.onionrInst = None
|
self.onionrInst = None
|
||||||
self.queueDB = self.dataDir + 'queue.db'
|
self.queueDB = self.dataDir + 'queue.db'
|
||||||
self.peerDB = self.dataDir + 'peers.db'
|
self.peerDB = self.dataDir + 'peers.db'
|
||||||
self.blockDB = self.dataDir + 'blocks.db'
|
self.blockDB = self.dataDir + 'blocks.db'
|
||||||
self.blockDataLocation = self.dataDir + 'blocks/'
|
self.blockDataLocation = self.dataDir + 'blocks/'
|
||||||
self.blockDataDB = self.blockDataLocation + 'block-data.db'
|
self.blockDataDB = self.blockDataLocation + 'block-data.db'
|
||||||
self.publicApiHostFile = self.dataDir + 'public-host.txt'
|
self.publicApiHostFile = self.dataDir + 'public-host.txt'
|
||||||
self.privateApiHostFile = self.dataDir + 'private-host.txt'
|
self.privateApiHostFile = self.dataDir + 'private-host.txt'
|
||||||
self.addressDB = self.dataDir + 'address.db'
|
self.addressDB = self.dataDir + 'address.db'
|
||||||
self.hsAddress = ''
|
self.hsAddress = ''
|
||||||
self.i2pAddress = config.get('i2p.own_addr', None)
|
self.i2pAddress = config.get('i2p.own_addr', None)
|
||||||
self.bootstrapFileLocation = 'static-data/bootstrap-nodes.txt'
|
self.bootstrapFileLocation = 'static-data/bootstrap-nodes.txt'
|
||||||
self.bootstrapList = []
|
self.bootstrapList = []
|
||||||
self.requirements = onionrvalues.OnionrValues()
|
self.requirements = onionrvalues.OnionrValues()
|
||||||
self.torPort = torPort
|
self.torPort = torPort
|
||||||
self.dataNonceFile = self.dataDir + 'block-nonces.dat'
|
self.dataNonceFile = self.dataDir + 'block-nonces.dat'
|
||||||
self.dbCreate = dbcreator.DBCreator(self)
|
self.dbCreate = dbcreator.DBCreator(self)
|
||||||
self.forwardKeysFile = self.dataDir + 'forward-keys.db'
|
self.forwardKeysFile = self.dataDir + 'forward-keys.db'
|
||||||
self.keyStore = simplekv.DeadSimpleKV(self.dataDir + 'cachedstorage.dat', refresh_seconds=5)
|
self.keyStore = simplekv.DeadSimpleKV(self.dataDir + 'cachedstorage.dat', refresh_seconds=5)
|
||||||
self.storage_counter = storagecounter.StorageCounter(self)
|
self.storage_counter = storagecounter.StorageCounter(self)
|
||||||
|
|
||||||
# Socket data, defined here because of multithreading constraints with gevent
|
# Socket data, defined here because of multithreading constraints with gevent
|
||||||
self.killSockets = False
|
self.killSockets = False
|
||||||
self.startSocket = {}
|
self.startSocket = {}
|
||||||
self.socketServerConnData = {}
|
self.socketServerConnData = {}
|
||||||
self.socketReasons = {}
|
self.socketReasons = {}
|
||||||
self.socketServerResponseData = {}
|
self.socketServerResponseData = {}
|
||||||
|
|
||||||
if not os.path.exists(self.dataDir):
|
if not os.path.exists(self.dataDir):
|
||||||
os.mkdir(self.dataDir)
|
os.mkdir(self.dataDir)
|
||||||
if not os.path.exists(self.dataDir + 'blocks/'):
|
if not os.path.exists(self.dataDir + 'blocks/'):
|
||||||
os.mkdir(self.dataDir + 'blocks/')
|
os.mkdir(self.dataDir + 'blocks/')
|
||||||
if not os.path.exists(self.blockDB):
|
if not os.path.exists(self.blockDB):
|
||||||
self.createBlockDB()
|
self.createBlockDB()
|
||||||
if not os.path.exists(self.forwardKeysFile):
|
if not os.path.exists(self.forwardKeysFile):
|
||||||
self.dbCreate.createForwardKeyDB()
|
self.dbCreate.createForwardKeyDB()
|
||||||
if not os.path.exists(self.peerDB):
|
if not os.path.exists(self.peerDB):
|
||||||
self.createPeerDB()
|
self.createPeerDB()
|
||||||
if not os.path.exists(self.addressDB):
|
if not os.path.exists(self.addressDB):
|
||||||
self.createAddressDB()
|
self.createAddressDB()
|
||||||
|
|
||||||
if os.path.exists(self.dataDir + '/hs/hostname'):
|
if os.path.exists(self.dataDir + '/hs/hostname'):
|
||||||
with open(self.dataDir + '/hs/hostname', 'r') as hs:
|
with open(self.dataDir + '/hs/hostname', 'r') as hs:
|
||||||
self.hsAddress = hs.read().strip()
|
self.hsAddress = hs.read().strip()
|
||||||
|
|
||||||
# Load bootstrap address list
|
# Load bootstrap address list
|
||||||
if os.path.exists(self.bootstrapFileLocation):
|
if os.path.exists(self.bootstrapFileLocation):
|
||||||
with open(self.bootstrapFileLocation, 'r') as bootstrap:
|
with open(self.bootstrapFileLocation, 'r') as bootstrap:
|
||||||
bootstrap = bootstrap.read()
|
bootstrap = bootstrap.read()
|
||||||
for i in bootstrap.split('\n'):
|
for i in bootstrap.split('\n'):
|
||||||
self.bootstrapList.append(i)
|
self.bootstrapList.append(i)
|
||||||
else:
|
else:
|
||||||
logger.warn('Warning: address bootstrap file not found ' + self.bootstrapFileLocation)
|
logger.warn('Warning: address bootstrap file not found ' + self.bootstrapFileLocation)
|
||||||
|
|
||||||
self.use_subprocess = powchoice.use_subprocess(self)
|
self.use_subprocess = powchoice.use_subprocess(self)
|
||||||
# Initialize the crypto object
|
# Initialize the crypto object
|
||||||
self._crypto = onionrcrypto.OnionrCrypto(self)
|
self._crypto = onionrcrypto.OnionrCrypto(self)
|
||||||
self._blacklist = onionrblacklist.OnionrBlackList(self)
|
self._blacklist = onionrblacklist.OnionrBlackList(self)
|
||||||
self.serializer = serializeddata.SerializedData(self)
|
self.serializer = serializeddata.SerializedData(self)
|
||||||
|
|
||||||
# except Exception as error:
|
except Exception as error:
|
||||||
# print(str(error))
|
logger.error('Failed to initialize core Onionr library.', error=error, terminal=True)
|
||||||
# logger.error('Failed to initialize core Onionr library.', error=error, terminal=True)
|
logger.fatal('Cannot recover from error.', terminal=True)
|
||||||
# logger.fatal('Cannot recover from error.', terminal=True)
|
sys.exit(1)
|
||||||
# sys.exit(1)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def refreshFirstStartVars(self):
|
def refreshFirstStartVars(self):
|
||||||
@ -441,7 +440,7 @@ class Core:
|
|||||||
localcommand.local_command(self, '/waitforshare/' + retData, post=True, maxWait=5)
|
localcommand.local_command(self, '/waitforshare/' + retData, post=True, maxWait=5)
|
||||||
self.daemonQueueAdd('uploadBlock', retData)
|
self.daemonQueueAdd('uploadBlock', retData)
|
||||||
else:
|
else:
|
||||||
print('shite', localcommand.local_command(self, '/ping', maxWait=10))
|
pass
|
||||||
self.addToBlockDB(retData, selfInsert=True, dataSaved=True)
|
self.addToBlockDB(retData, selfInsert=True, dataSaved=True)
|
||||||
blockmetadata.process_block_metadata(self, retData)
|
blockmetadata.process_block_metadata(self, retData)
|
||||||
|
|
||||||
|
@ -35,11 +35,11 @@ class OnionrValidations(unittest.TestCase):
|
|||||||
|
|
||||||
for valid in valids:
|
for valid in valids:
|
||||||
print('testing', valid)
|
print('testing', valid)
|
||||||
self.assertTrue(c._utils.validatePubKey(valid))
|
self.assertTrue(stringvalidators.validate_pub_key(valid))
|
||||||
|
|
||||||
for x in invalid:
|
for x in invalid:
|
||||||
#print('testing', x)
|
#print('testing', x)
|
||||||
self.assertFalse(c._utils.validatePubKey(x))
|
self.assertFalse(stringvalidators.validate_pub_key(x))
|
||||||
|
|
||||||
def test_integer_string(self):
|
def test_integer_string(self):
|
||||||
valid = ["1", "100", 100, "-5", -5]
|
valid = ["1", "100", 100, "-5", -5]
|
||||||
|
Loading…
Reference in New Issue
Block a user