From b42ca297e5caf32402b9e79077f828010786f2c5 Mon Sep 17 00:00:00 2001 From: Martin Vrachev Date: Tue, 5 May 2020 21:25:52 +0300 Subject: [PATCH] Remove PIPE arg and make QuiteHandler the default Passing a pipe to the subprocess, but not reading from it conceals helpful error messages. As the code redirects all of the stderr from the subprocess to nowhere, the error output of the process is never read. If we remove the PIPEs from the tests we should see some error messages on the console/logger that can help us understand what went wrong. On another hand, when we stop passing stderr=subprocess.PIPE arg to the subprocess.Popen function call there are a lot of HTTP messages together with the helpful error messages. One decision is to make QuietHTTPRequestHandler the default. That way we receive the helpful error messages without the HTTP messages. Signed-off-by: Martin Vrachev --- tests/simple_server.py | 10 +++++++++- tests/test_arbitrary_package_attack.py | 2 +- tests/test_endless_data_attack.py | 2 +- tests/test_extraneous_dependencies_attack.py | 2 +- tests/test_indefinite_freeze_attack.py | 2 +- tests/test_key_revocation_integration.py | 2 +- tests/test_mix_and_match_attack.py | 2 +- tests/test_multiple_repositories_integration.py | 4 ++-- tests/test_replay_attack.py | 2 +- tests/test_slow_retrieval_attack.py | 2 +- tests/test_updater.py | 12 ++++++------ tests/test_updater_root_rotation_integration.py | 2 +- 12 files changed, 26 insertions(+), 18 deletions(-) diff --git a/tests/simple_server.py b/tests/simple_server.py index d134343092..4f7b96dae1 100755 --- a/tests/simple_server.py +++ b/tests/simple_server.py @@ -71,7 +71,15 @@ def log_request(self, code='-', size='-'): if six.PY2 and platform.system() == 'Windows': handler = QuietHTTPRequestHandler else: - handler = SimpleHTTPRequestHandler + use_quiet_http_request_handler = True + + if len(sys.argv) > 2: + use_quiet_http_request_handler = sys.argv[2] + + if use_quiet_http_request_handler: + handler = QuietHTTPRequestHandler + else: + handler = SimpleHTTPRequestHandler httpd = six.moves.socketserver.TCPServer(('', PORT), handler) diff --git a/tests/test_arbitrary_package_attack.py b/tests/test_arbitrary_package_attack.py index 772f3164ca..dfd66cafaf 100755 --- a/tests/test_arbitrary_package_attack.py +++ b/tests/test_arbitrary_package_attack.py @@ -81,7 +81,7 @@ def setUpClass(cls): # etc. cls.SERVER_PORT = random.randint(30000, 45000) command = ['python', 'simple_server.py', str(cls.SERVER_PORT)] - cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + cls.server_process = subprocess.Popen(command) logger.info('Server process started.') logger.info('Server process id: ' + str(cls.server_process.pid)) logger.info('Serving on port: ' + str(cls.SERVER_PORT)) diff --git a/tests/test_endless_data_attack.py b/tests/test_endless_data_attack.py index f0fb850c08..62fdd90453 100755 --- a/tests/test_endless_data_attack.py +++ b/tests/test_endless_data_attack.py @@ -83,7 +83,7 @@ def setUpClass(cls): # etc. cls.SERVER_PORT = random.randint(30000, 45000) command = ['python', 'simple_server.py', str(cls.SERVER_PORT)] - cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + cls.server_process = subprocess.Popen(command) logger.info('Server process started.') logger.info('Server process id: '+str(cls.server_process.pid)) logger.info('Serving on port: '+str(cls.SERVER_PORT)) diff --git a/tests/test_extraneous_dependencies_attack.py b/tests/test_extraneous_dependencies_attack.py index 42e3f3b5ff..113481a8f0 100755 --- a/tests/test_extraneous_dependencies_attack.py +++ b/tests/test_extraneous_dependencies_attack.py @@ -87,7 +87,7 @@ def setUpClass(cls): # etc. cls.SERVER_PORT = random.randint(30000, 45000) command = ['python', 'simple_server.py', str(cls.SERVER_PORT)] - cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + cls.server_process = subprocess.Popen(command) logger.info('Server process started.') logger.info('Server process id: '+str(cls.server_process.pid)) logger.info('Serving on port: '+str(cls.SERVER_PORT)) diff --git a/tests/test_indefinite_freeze_attack.py b/tests/test_indefinite_freeze_attack.py index 694210c15f..feb64c5332 100755 --- a/tests/test_indefinite_freeze_attack.py +++ b/tests/test_indefinite_freeze_attack.py @@ -94,7 +94,7 @@ def setUpClass(cls): # etc. cls.SERVER_PORT = random.randint(30000, 45000) command = ['python', 'simple_server.py', str(cls.SERVER_PORT)] - cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + cls.server_process = subprocess.Popen(command) logger.info('Server process started.') logger.info('Server process id: '+str(cls.server_process.pid)) logger.info('Serving on port: '+str(cls.SERVER_PORT)) diff --git a/tests/test_key_revocation_integration.py b/tests/test_key_revocation_integration.py index 3b968160b1..9233877c57 100755 --- a/tests/test_key_revocation_integration.py +++ b/tests/test_key_revocation_integration.py @@ -83,7 +83,7 @@ def setUpClass(cls): # key files, etc. cls.SERVER_PORT = random.randint(30000, 45000) command = ['python', 'simple_server.py', str(cls.SERVER_PORT)] - cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + cls.server_process = subprocess.Popen(command) logger.info('\n\tServer process started.') logger.info('\tServer process id: '+str(cls.server_process.pid)) logger.info('\tServing on port: '+str(cls.SERVER_PORT)) diff --git a/tests/test_mix_and_match_attack.py b/tests/test_mix_and_match_attack.py index a35c8854a2..8f04595817 100755 --- a/tests/test_mix_and_match_attack.py +++ b/tests/test_mix_and_match_attack.py @@ -88,7 +88,7 @@ def setUpClass(cls): # etc. cls.SERVER_PORT = random.randint(30000, 45000) command = ['python', 'simple_server.py', str(cls.SERVER_PORT)] - cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + cls.server_process = subprocess.Popen(command) logger.info('Server process started.') logger.info('Server process id: '+str(cls.server_process.pid)) logger.info('Serving on port: '+str(cls.SERVER_PORT)) diff --git a/tests/test_multiple_repositories_integration.py b/tests/test_multiple_repositories_integration.py index fbc605d82b..414e43774b 100755 --- a/tests/test_multiple_repositories_integration.py +++ b/tests/test_multiple_repositories_integration.py @@ -136,14 +136,14 @@ def setUp(self): command = ['python', SIMPLE_SERVER_PATH, str(self.SERVER_PORT)] command2 = ['python', SIMPLE_SERVER_PATH, str(self.SERVER_PORT2)] - self.server_process = subprocess.Popen(command, stderr=subprocess.PIPE, + self.server_process = subprocess.Popen(command, cwd=self.repository_directory) logger.debug('Server process started.') logger.debug('Server process id: ' + str(self.server_process.pid)) logger.debug('Serving on port: ' + str(self.SERVER_PORT)) - self.server_process2 = subprocess.Popen(command2, stderr=subprocess.PIPE, + self.server_process2 = subprocess.Popen(command2, cwd=self.repository_directory2) diff --git a/tests/test_replay_attack.py b/tests/test_replay_attack.py index e76a0dfdc0..0c50f9e616 100755 --- a/tests/test_replay_attack.py +++ b/tests/test_replay_attack.py @@ -87,7 +87,7 @@ def setUpClass(cls): # etc. cls.SERVER_PORT = random.randint(30000, 45000) command = ['python', 'simple_server.py', str(cls.SERVER_PORT)] - cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + cls.server_process = subprocess.Popen(command) logger.info('Server process started.') logger.info('Server process id: '+str(cls.server_process.pid)) logger.info('Serving on port: '+str(cls.SERVER_PORT)) diff --git a/tests/test_slow_retrieval_attack.py b/tests/test_slow_retrieval_attack.py index cdd8e450f1..2c7b38c562 100755 --- a/tests/test_slow_retrieval_attack.py +++ b/tests/test_slow_retrieval_attack.py @@ -103,7 +103,7 @@ def _start_slow_server(self, mode): # as a delegated role 'targets/role1', three target files, five key files, # etc. command = ['python', 'slow_retrieval_server.py', str(self.SERVER_PORT), mode] - server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + server_process = subprocess.Popen(command) logger.info('Slow Retrieval Server process started.') logger.info('Server process id: '+str(server_process.pid)) logger.info('Serving on port: '+str(self.SERVER_PORT)) diff --git a/tests/test_updater.py b/tests/test_updater.py index 23f9ec1b5e..eb3e8e3790 100644 --- a/tests/test_updater.py +++ b/tests/test_updater.py @@ -104,7 +104,7 @@ def setUpClass(cls): # etc. cls.SERVER_PORT = random.randint(30000, 45000) command = ['python', cls.SIMPLE_SERVER_PATH, str(cls.SERVER_PORT)] - cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + cls.server_process = subprocess.Popen(command) logger.info('\n\tServer process started.') logger.info('\tServer process id: '+str(cls.server_process.pid)) logger.info('\tServing on port: '+str(cls.SERVER_PORT)) @@ -1097,7 +1097,7 @@ def test_6_get_one_valid_targetinfo(self): # timeout in Windows after a few tests. SERVER_PORT = random.randint(30000, 45000) command = ['python', self.SIMPLE_SERVER_PATH, str(SERVER_PORT)] - server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + server_process = subprocess.Popen(command) # NOTE: Following error is raised if a delay is not long enough: # @@ -1365,7 +1365,7 @@ def test_7_updated_targets(self): # timeout in Windows after a few tests. SERVER_PORT = random.randint(30000, 45000) command = ['python', self.SIMPLE_SERVER_PATH, str(SERVER_PORT)] - server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + server_process = subprocess.Popen(command) # NOTE: Following error is raised if a delay is not long enough to allow # the server process to set up and start listening: @@ -1497,7 +1497,7 @@ def test_8_remove_obsolete_targets(self): # timeout in Windows after a few tests. SERVER_PORT = random.randint(30000, 45000) command = ['python', self.SIMPLE_SERVER_PATH, str(SERVER_PORT)] - server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + server_process = subprocess.Popen(command) # NOTE: Following error is raised if a delay is not long enough to allow # the server process to set up and start listening: @@ -1888,14 +1888,14 @@ def setUp(self): command = ['python', self.SIMPLE_SERVER_PATH, str(self.SERVER_PORT)] command2 = ['python', self.SIMPLE_SERVER_PATH, str(self.SERVER_PORT2)] - self.server_process = subprocess.Popen(command, stderr=subprocess.PIPE, + self.server_process = subprocess.Popen(command, cwd=self.repository_directory) logger.debug('Server process started.') logger.debug('Server process id: ' + str(self.server_process.pid)) logger.debug('Serving on port: ' + str(self.SERVER_PORT)) - self.server_process2 = subprocess.Popen(command2, stderr=subprocess.PIPE, + self.server_process2 = subprocess.Popen(command2, cwd=self.repository_directory2) logger.debug('Server process 2 started.') diff --git a/tests/test_updater_root_rotation_integration.py b/tests/test_updater_root_rotation_integration.py index cb0f5dd231..c73c9f7045 100755 --- a/tests/test_updater_root_rotation_integration.py +++ b/tests/test_updater_root_rotation_integration.py @@ -90,7 +90,7 @@ def setUpClass(cls): # etc. cls.SERVER_PORT = random.randint(30000, 45000) command = ['python', 'simple_server.py', str(cls.SERVER_PORT)] - cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + cls.server_process = subprocess.Popen(command) logger.info('\n\tServer process started.') logger.info('\tServer process id: '+str(cls.server_process.pid)) logger.info('\tServing on port: '+str(cls.SERVER_PORT))