2018-01-02 08:43:29 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
'''
|
|
|
|
Onionr - P2P Microblogging Platform & Social network
|
|
|
|
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
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
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/>.
|
|
|
|
'''
|
2018-01-26 07:22:48 +00:00
|
|
|
import unittest, sys, os, base64, tarfile, shutil, simplecrypt, logger
|
2018-01-02 08:43:29 +00:00
|
|
|
|
|
|
|
class OnionrTests(unittest.TestCase):
|
2018-01-05 09:16:21 +00:00
|
|
|
def testPython3(self):
|
|
|
|
if sys.version_info.major != 3:
|
2018-01-26 07:22:48 +00:00
|
|
|
logger.debug('Python version: ' + sys.version_info.major)
|
2018-01-05 09:16:21 +00:00
|
|
|
self.assertTrue(False)
|
|
|
|
else:
|
|
|
|
self.assertTrue(True)
|
2018-01-02 08:43:29 +00:00
|
|
|
def testNone(self):
|
2018-01-26 07:22:48 +00:00
|
|
|
logger.debug('--------------------------')
|
|
|
|
logger.info('Running simple program run test...')
|
2018-01-02 08:43:29 +00:00
|
|
|
# Test just running ./onionr with no arguments
|
|
|
|
blank = os.system('./onionr.py')
|
|
|
|
if blank != 0:
|
|
|
|
self.assertTrue(False)
|
|
|
|
else:
|
|
|
|
self.assertTrue(True)
|
2018-01-10 08:40:25 +00:00
|
|
|
def testPeer_a_DBCreation(self):
|
2018-01-26 07:22:48 +00:00
|
|
|
logger.debug('--------------------------')
|
|
|
|
logger.info('Running peer db creation test...')
|
2018-01-10 03:50:38 +00:00
|
|
|
if os.path.exists('data/peers.db'):
|
|
|
|
os.remove('data/peers.db')
|
|
|
|
import core
|
|
|
|
myCore = core.Core()
|
|
|
|
myCore.createPeerDB()
|
|
|
|
if os.path.exists('data/peers.db'):
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.assertTrue(False)
|
2018-01-10 08:40:25 +00:00
|
|
|
def testPeer_b_addPeerToDB(self):
|
2018-01-26 07:22:48 +00:00
|
|
|
logger.debug('--------------------------')
|
|
|
|
logger.info('Running peer db insertion test...')
|
2018-01-10 08:40:25 +00:00
|
|
|
import core
|
|
|
|
myCore = core.Core()
|
2018-01-14 00:07:13 +00:00
|
|
|
if not os.path.exists('data/peers.db'):
|
|
|
|
myCore.createPeerDB()
|
2018-01-10 08:40:25 +00:00
|
|
|
if myCore.addPeer('test'):
|
2018-01-14 00:07:13 +00:00
|
|
|
self.assertTrue(True)
|
2018-01-10 08:40:25 +00:00
|
|
|
else:
|
|
|
|
self.assertTrue(False)
|
2018-01-10 03:50:38 +00:00
|
|
|
def testData_b_Encrypt(self):
|
|
|
|
self.assertTrue(True)
|
|
|
|
return
|
2018-01-26 07:22:48 +00:00
|
|
|
logger.debug('--------------------------')
|
|
|
|
logger.info('Running data dir encrypt test...')
|
2018-01-07 08:55:44 +00:00
|
|
|
import core
|
2018-01-08 09:25:32 +00:00
|
|
|
myCore = core.Core()
|
|
|
|
myCore.dataDirEncrypt('password')
|
|
|
|
if os.path.exists('data-encrypted.dat'):
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.assertTrue(False)
|
2018-01-10 03:50:38 +00:00
|
|
|
def testData_a_Decrypt(self):
|
|
|
|
self.assertTrue(True)
|
|
|
|
return
|
2018-01-26 07:22:48 +00:00
|
|
|
logger.debug('--------------------------')
|
|
|
|
logger.info('Running data dir decrypt test...')
|
2018-01-08 09:25:32 +00:00
|
|
|
import core
|
|
|
|
myCore = core.Core()
|
|
|
|
myCore.dataDirDecrypt('password')
|
2018-01-10 03:50:38 +00:00
|
|
|
if os.path.exists('data/'):
|
2018-01-08 09:25:32 +00:00
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.assertTrue(False)
|
2018-01-06 08:51:26 +00:00
|
|
|
def testPGPGen(self):
|
2018-01-26 07:22:48 +00:00
|
|
|
logger.debug('--------------------------')
|
|
|
|
logger.info('Running PGP key generation test...')
|
2018-01-06 08:51:26 +00:00
|
|
|
if os.path.exists('data/pgp/'):
|
2018-01-07 08:55:44 +00:00
|
|
|
self.assertTrue(True)
|
2018-01-06 08:51:26 +00:00
|
|
|
else:
|
2018-01-20 18:06:25 +00:00
|
|
|
import core, netcontroller
|
2018-01-06 08:51:26 +00:00
|
|
|
myCore = core.Core()
|
2018-01-20 18:06:25 +00:00
|
|
|
net = netcontroller.NetController(1337)
|
|
|
|
net.startTor()
|
|
|
|
torID = open('data/hs/hostname').read()
|
2018-01-20 17:59:44 +00:00
|
|
|
myCore.generateMainPGP(torID)
|
2018-01-06 08:51:26 +00:00
|
|
|
if os.path.exists('data/pgp/'):
|
|
|
|
self.assertTrue(True)
|
2018-01-17 23:37:53 +00:00
|
|
|
def testHMACGen(self):
|
2018-01-26 07:22:48 +00:00
|
|
|
logger.debug('--------------------------')
|
|
|
|
logger.info('Running HMAC generation test...')
|
2018-01-17 23:37:53 +00:00
|
|
|
# Test if hmac key generation is working
|
|
|
|
import core
|
|
|
|
myCore = core.Core()
|
|
|
|
key = myCore.generateHMAC()
|
|
|
|
if len(key) > 10:
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.assertTrue(False)
|
2018-01-04 22:15:15 +00:00
|
|
|
def testQueue(self):
|
2018-01-26 07:22:48 +00:00
|
|
|
logger.debug('--------------------------')
|
|
|
|
logger.info('Running daemon queue test...')
|
2018-01-04 22:15:15 +00:00
|
|
|
# test if the daemon queue can read/write data
|
|
|
|
import core
|
|
|
|
myCore = core.Core()
|
2018-01-10 03:50:38 +00:00
|
|
|
if not os.path.exists('data/queue.db'):
|
|
|
|
myCore.daemonQueue()
|
2018-01-04 22:15:15 +00:00
|
|
|
while True:
|
|
|
|
command = myCore.daemonQueue()
|
|
|
|
if command == False:
|
2018-01-27 00:52:20 +00:00
|
|
|
logger.debug('The queue is empty (false)')
|
2018-01-04 22:15:15 +00:00
|
|
|
break
|
|
|
|
else:
|
2018-01-27 00:52:20 +00:00
|
|
|
logger.debug(command[0])
|
2018-01-04 22:15:15 +00:00
|
|
|
myCore.daemonQueueAdd('testCommand', 'testData')
|
|
|
|
command = myCore.daemonQueue()
|
|
|
|
if command[0] == 'testCommand':
|
|
|
|
if myCore.daemonQueue() == False:
|
2018-01-27 00:52:20 +00:00
|
|
|
logger.info('Succesfully added and read command')
|
2018-01-17 23:37:53 +00:00
|
|
|
unittest.main()
|