+ 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
					
				
					 12 changed files with 115 additions and 17 deletions
				
			
		|  | @ -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') | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue