Skip to content

Commit

Permalink
Remove PIPE arg and make QuiteHandler the default
Browse files Browse the repository at this point in the history
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 <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed May 7, 2020
1 parent dae1a1b commit b42ca29
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 18 deletions.
10 changes: 9 additions & 1 deletion tests/simple_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_arbitrary_package_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_endless_data_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_extraneous_dependencies_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_indefinite_freeze_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_key_revocation_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mix_and_match_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_multiple_repositories_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_replay_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_slow_retrieval_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 6 additions & 6 deletions tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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:
# <urlopen error [Errno 111] Connection refused>
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_updater_root_rotation_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit b42ca29

Please sign in to comment.