+ now require runtime tests to generate unittest result that is somewhat fresh
+ add runtime test for webpass needing to be set
This commit is contained in:
parent
6624a80c68
commit
8a3f84097a
@ -2,6 +2,8 @@
|
||||
|
||||
Hooks to handle daemon events
|
||||
"""
|
||||
from threading import Thread
|
||||
|
||||
from .removefrominsertqueue import remove_from_insert_queue
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
@ -67,10 +69,11 @@ def daemon_event_handlers(shared_state: 'TooMany'):
|
||||
comm_inst.offlinePeers = []
|
||||
|
||||
def test_runtime():
|
||||
comm_inst.shared_state.get_by_string(
|
||||
"OnionrRunTestManager").run_tests()
|
||||
Thread(target=comm_inst.shared_state.get_by_string(
|
||||
"OnionrRunTestManager").run_tests).start()
|
||||
|
||||
events_api.register_listener(remove_from_insert_queue_wrapper)
|
||||
events_api.register_listener(print_test)
|
||||
events_api.register_listener(upload_event)
|
||||
events_api.register_listener(test_runtime)
|
||||
|
||||
|
@ -134,7 +134,6 @@ def daemon():
|
||||
events.event('daemon_start')
|
||||
communicator.startCommunicator(shared_state)
|
||||
|
||||
localcommand.local_command('shutdown')
|
||||
|
||||
if not offline_mode:
|
||||
net.killTor()
|
||||
|
@ -25,11 +25,12 @@ def do_runtime_test():
|
||||
"""Send runtime test daemon queue command."""
|
||||
spawn(
|
||||
localcommand.local_command,
|
||||
f'/daemon-event/test_runtime',
|
||||
f'daemon-event/test_runtime',
|
||||
post=True,
|
||||
is_json=True,
|
||||
postData={}
|
||||
).get(10)
|
||||
postData={},
|
||||
maxWait=300
|
||||
).get(300)
|
||||
|
||||
|
||||
do_runtime_test.onionr_help = "If Onionr is running, " # type: ignore
|
||||
|
@ -66,6 +66,8 @@ def local_command(command, data='', silent = True, post=False,
|
||||
if data != '':
|
||||
data = '&data=' + urllib.parse.quote_plus(data)
|
||||
payload = 'http://%s/%s%s' % (hostname, command, data)
|
||||
if not config.get('client.webpassword'):
|
||||
config.reload()
|
||||
|
||||
try:
|
||||
if post:
|
||||
@ -89,5 +91,4 @@ def local_command(command, data='', silent = True, post=False,
|
||||
if not silent:
|
||||
logger.error('Failed to make local request (command: %s):%s' % (command, error), terminal=True)
|
||||
ret_data = False
|
||||
|
||||
return ret_data
|
||||
|
@ -1,13 +1,15 @@
|
||||
"""
|
||||
Onionr - Private P2P Communication
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
Test Onionr as it is running
|
||||
Test Onionr as it is running
|
||||
"""
|
||||
import os
|
||||
|
||||
import logger
|
||||
from onionrutils import epoch
|
||||
|
||||
from . import uicheck, inserttest, stresstest
|
||||
from . import ownnode
|
||||
from .webpasstest import webpass_test
|
||||
"""
|
||||
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
|
||||
@ -27,9 +29,12 @@ RUN_TESTS = [uicheck.check_ui,
|
||||
inserttest.insert_bin_test,
|
||||
ownnode.test_tor_adder,
|
||||
ownnode.test_own_node,
|
||||
stresstest.stress_test_block_insert
|
||||
stresstest.stress_test_block_insert,
|
||||
webpass_test
|
||||
]
|
||||
|
||||
SUCCESS_FILE = os.path.dirname(os.path.realpath(__file__)) + '/../../tests/runtime-result.txt'
|
||||
|
||||
|
||||
class OnionrRunTestManager:
|
||||
def __init__(self):
|
||||
@ -40,6 +45,11 @@ class OnionrRunTestManager:
|
||||
cur_time = epoch.get_epoch()
|
||||
logger.info(f"Doing runtime tests at {cur_time}")
|
||||
|
||||
try:
|
||||
os.remove(SUCCESS_FILE)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
try:
|
||||
for i in RUN_TESTS:
|
||||
last = i
|
||||
@ -47,3 +57,9 @@ class OnionrRunTestManager:
|
||||
logger.info("[RUNTIME TEST] " + last.__name__ + " passed")
|
||||
except (ValueError, AttributeError):
|
||||
logger.error(last.__name__ + ' failed')
|
||||
else:
|
||||
ep = str(epoch.get_epoch())
|
||||
logger.info(f'All runtime tests passed at {ep}')
|
||||
with open(SUCCESS_FILE, 'w') as f:
|
||||
f.write(ep)
|
||||
|
||||
|
@ -29,10 +29,9 @@ def test_own_node(test_manager):
|
||||
if config.get('general.security_level', 0) > 0:
|
||||
return
|
||||
own_tor_address = gettransports.get()[0]
|
||||
print(socks_port)
|
||||
if 'this is an onionr node' \
|
||||
not in basicrequests.do_get_request(own_tor_address,
|
||||
port=socks_port).lower():
|
||||
not in basicrequests.do_get_request('http://' + own_tor_address,
|
||||
port=socks_port, ignoreAPI=True).lower():
|
||||
logger.warn('Own node not reachable in test')
|
||||
raise ValueError
|
||||
|
||||
@ -47,7 +46,6 @@ def test_tor_adder(test_manager):
|
||||
raise ValueError('No Tor node address created yet')
|
||||
|
||||
if hs not in gettransports.get():
|
||||
print(hs in gettransports.get(), 'meme')
|
||||
logger.error('gettransports Tor not same as file: %s %s' %
|
||||
(hs, gettransports.get()))
|
||||
raise ValueError('gettransports Tor not same as file')
|
||||
|
@ -5,5 +5,5 @@ def check_ui(test_manager):
|
||||
result = localcommand.local_command(point)
|
||||
if not result: raise ValueError
|
||||
result = result.lower()
|
||||
if not 'script' in result:
|
||||
if 'script' not in result:
|
||||
raise ValueError(f'uicheck failed on {point}')
|
||||
|
11
src/runtests/webpasstest.py
Normal file
11
src/runtests/webpasstest.py
Normal file
@ -0,0 +1,11 @@
|
||||
import requests
|
||||
|
||||
from onionrutils import localcommand
|
||||
|
||||
|
||||
def webpass_test(test_manager):
|
||||
if requests.get('http://' + localcommand.get_hostname() + '/ping') == \
|
||||
'pong!':
|
||||
raise ValueError
|
||||
if localcommand.local_command('ping') != 'pong!':
|
||||
raise ValueError('Could not ping with normal localcommand in webpasstest')
|
@ -5,4 +5,4 @@
|
||||
|
||||
<p>Onionr is a decentralized, distributed peer-to-peer data communication network.</p>
|
||||
|
||||
<p>To learn more about Onionr, see the website at <a href="http://onionr.onionkvc5ibm37bmxwr56bdxcdnb6w3wm4bdghh5qo6f6za7gn7styid.onion ">http://onionr.onionkvc5ibm37bmxwr56bdxcdnb6w3wm4bdghh5qo6f6za7gn7styid.onion</a> or <a href='https://onionr.net/'>Onionr.net</a></p>
|
||||
<p>To learn more about Onionr, see the website at <a href="http://onionrbak72t5zhbzuey2fdkpczlvhowgcpqc6uoyrd3uxztzxwz5cyd.onion/">http://onionrbak72t5zhbzuey2fdkpczlvhowgcpqc6uoyrd3uxztzxwz5cyd.onion/</a> or <a href='https://onionr.net/'>Onionr.net</a></p>
|
||||
|
1
tests/runtime-result.txt
Normal file
1
tests/runtime-result.txt
Normal file
@ -0,0 +1 @@
|
||||
1580360010
|
26
tests/test_runtime_result.py
Normal file
26
tests/test_runtime_result.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys, os, time, math
|
||||
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
|
||||
|
||||
SUCCESS_FILE = os.path.dirname(__file__) + '/runtime-result.txt'
|
||||
|
||||
from utils import identifyhome, createdirs
|
||||
from onionrsetup import setup_config
|
||||
createdirs.create_dirs()
|
||||
setup_config()
|
||||
|
||||
class TestRuntimeFile(unittest.TestCase):
|
||||
def test_runtime_result(self):
|
||||
self.assertTrue(os.path.exists(SUCCESS_FILE))
|
||||
with open(SUCCESS_FILE, 'r') as result_file:
|
||||
self.assertLess(math.floor(time.time()) - int(result_file.read()), 600)
|
||||
|
||||
|
||||
|
||||
unittest.main()
|
42
tests/test_webpass_required.py
Normal file
42
tests/test_webpass_required.py
Normal file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys, os
|
||||
import threading
|
||||
|
||||
from gevent import sleep
|
||||
import requests
|
||||
|
||||
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
|
||||
from onionrsetup import setup_config
|
||||
createdirs.create_dirs()
|
||||
setup_config()
|
||||
from onionrcommands import daemonlaunch
|
||||
from onionrutils import localcommand, getclientapiserver
|
||||
import config
|
||||
|
||||
class TestWebpass(unittest.TestCase):
|
||||
def test_needs_webpass(self):
|
||||
config.set('general.use_bootstrap', False)
|
||||
threading.Thread(target=daemonlaunch.start).start()
|
||||
while localcommand.local_command('/ping') != 'pong!':
|
||||
sleep(1)
|
||||
self.assertNotEqual(
|
||||
requests.get('http://' + getclientapiserver.get_client_API_server() + '/ping'),
|
||||
'pong!'
|
||||
)
|
||||
while True:
|
||||
try:
|
||||
daemonlaunch.kill_daemon()
|
||||
except KeyError:
|
||||
sleep(1)
|
||||
|
||||
|
||||
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user