Skip to content

Commit b42ca29

Browse files
committed
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 <[email protected]>
1 parent dae1a1b commit b42ca29

12 files changed

+26
-18
lines changed

tests/simple_server.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ def log_request(self, code='-', size='-'):
7171
if six.PY2 and platform.system() == 'Windows':
7272
handler = QuietHTTPRequestHandler
7373
else:
74-
handler = SimpleHTTPRequestHandler
74+
use_quiet_http_request_handler = True
75+
76+
if len(sys.argv) > 2:
77+
use_quiet_http_request_handler = sys.argv[2]
78+
79+
if use_quiet_http_request_handler:
80+
handler = QuietHTTPRequestHandler
81+
else:
82+
handler = SimpleHTTPRequestHandler
7583

7684
httpd = six.moves.socketserver.TCPServer(('', PORT), handler)
7785

tests/test_arbitrary_package_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def setUpClass(cls):
8181
# etc.
8282
cls.SERVER_PORT = random.randint(30000, 45000)
8383
command = ['python', 'simple_server.py', str(cls.SERVER_PORT)]
84-
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
84+
cls.server_process = subprocess.Popen(command)
8585
logger.info('Server process started.')
8686
logger.info('Server process id: ' + str(cls.server_process.pid))
8787
logger.info('Serving on port: ' + str(cls.SERVER_PORT))

tests/test_endless_data_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def setUpClass(cls):
8383
# etc.
8484
cls.SERVER_PORT = random.randint(30000, 45000)
8585
command = ['python', 'simple_server.py', str(cls.SERVER_PORT)]
86-
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
86+
cls.server_process = subprocess.Popen(command)
8787
logger.info('Server process started.')
8888
logger.info('Server process id: '+str(cls.server_process.pid))
8989
logger.info('Serving on port: '+str(cls.SERVER_PORT))

tests/test_extraneous_dependencies_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def setUpClass(cls):
8787
# etc.
8888
cls.SERVER_PORT = random.randint(30000, 45000)
8989
command = ['python', 'simple_server.py', str(cls.SERVER_PORT)]
90-
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
90+
cls.server_process = subprocess.Popen(command)
9191
logger.info('Server process started.')
9292
logger.info('Server process id: '+str(cls.server_process.pid))
9393
logger.info('Serving on port: '+str(cls.SERVER_PORT))

tests/test_indefinite_freeze_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def setUpClass(cls):
9494
# etc.
9595
cls.SERVER_PORT = random.randint(30000, 45000)
9696
command = ['python', 'simple_server.py', str(cls.SERVER_PORT)]
97-
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
97+
cls.server_process = subprocess.Popen(command)
9898
logger.info('Server process started.')
9999
logger.info('Server process id: '+str(cls.server_process.pid))
100100
logger.info('Serving on port: '+str(cls.SERVER_PORT))

tests/test_key_revocation_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def setUpClass(cls):
8383
# key files, etc.
8484
cls.SERVER_PORT = random.randint(30000, 45000)
8585
command = ['python', 'simple_server.py', str(cls.SERVER_PORT)]
86-
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
86+
cls.server_process = subprocess.Popen(command)
8787
logger.info('\n\tServer process started.')
8888
logger.info('\tServer process id: '+str(cls.server_process.pid))
8989
logger.info('\tServing on port: '+str(cls.SERVER_PORT))

tests/test_mix_and_match_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def setUpClass(cls):
8888
# etc.
8989
cls.SERVER_PORT = random.randint(30000, 45000)
9090
command = ['python', 'simple_server.py', str(cls.SERVER_PORT)]
91-
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
91+
cls.server_process = subprocess.Popen(command)
9292
logger.info('Server process started.')
9393
logger.info('Server process id: '+str(cls.server_process.pid))
9494
logger.info('Serving on port: '+str(cls.SERVER_PORT))

tests/test_multiple_repositories_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ def setUp(self):
136136
command = ['python', SIMPLE_SERVER_PATH, str(self.SERVER_PORT)]
137137
command2 = ['python', SIMPLE_SERVER_PATH, str(self.SERVER_PORT2)]
138138

139-
self.server_process = subprocess.Popen(command, stderr=subprocess.PIPE,
139+
self.server_process = subprocess.Popen(command,
140140
cwd=self.repository_directory)
141141

142142
logger.debug('Server process started.')
143143
logger.debug('Server process id: ' + str(self.server_process.pid))
144144
logger.debug('Serving on port: ' + str(self.SERVER_PORT))
145145

146-
self.server_process2 = subprocess.Popen(command2, stderr=subprocess.PIPE,
146+
self.server_process2 = subprocess.Popen(command2,
147147
cwd=self.repository_directory2)
148148

149149

tests/test_replay_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def setUpClass(cls):
8787
# etc.
8888
cls.SERVER_PORT = random.randint(30000, 45000)
8989
command = ['python', 'simple_server.py', str(cls.SERVER_PORT)]
90-
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
90+
cls.server_process = subprocess.Popen(command)
9191
logger.info('Server process started.')
9292
logger.info('Server process id: '+str(cls.server_process.pid))
9393
logger.info('Serving on port: '+str(cls.SERVER_PORT))

tests/test_slow_retrieval_attack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _start_slow_server(self, mode):
103103
# as a delegated role 'targets/role1', three target files, five key files,
104104
# etc.
105105
command = ['python', 'slow_retrieval_server.py', str(self.SERVER_PORT), mode]
106-
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
106+
server_process = subprocess.Popen(command)
107107
logger.info('Slow Retrieval Server process started.')
108108
logger.info('Server process id: '+str(server_process.pid))
109109
logger.info('Serving on port: '+str(self.SERVER_PORT))

tests/test_updater.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def setUpClass(cls):
104104
# etc.
105105
cls.SERVER_PORT = random.randint(30000, 45000)
106106
command = ['python', cls.SIMPLE_SERVER_PATH, str(cls.SERVER_PORT)]
107-
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
107+
cls.server_process = subprocess.Popen(command)
108108
logger.info('\n\tServer process started.')
109109
logger.info('\tServer process id: '+str(cls.server_process.pid))
110110
logger.info('\tServing on port: '+str(cls.SERVER_PORT))
@@ -1097,7 +1097,7 @@ def test_6_get_one_valid_targetinfo(self):
10971097
# timeout in Windows after a few tests.
10981098
SERVER_PORT = random.randint(30000, 45000)
10991099
command = ['python', self.SIMPLE_SERVER_PATH, str(SERVER_PORT)]
1100-
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
1100+
server_process = subprocess.Popen(command)
11011101

11021102
# NOTE: Following error is raised if a delay is not long enough:
11031103
# <urlopen error [Errno 111] Connection refused>
@@ -1365,7 +1365,7 @@ def test_7_updated_targets(self):
13651365
# timeout in Windows after a few tests.
13661366
SERVER_PORT = random.randint(30000, 45000)
13671367
command = ['python', self.SIMPLE_SERVER_PATH, str(SERVER_PORT)]
1368-
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
1368+
server_process = subprocess.Popen(command)
13691369

13701370
# NOTE: Following error is raised if a delay is not long enough to allow
13711371
# the server process to set up and start listening:
@@ -1497,7 +1497,7 @@ def test_8_remove_obsolete_targets(self):
14971497
# timeout in Windows after a few tests.
14981498
SERVER_PORT = random.randint(30000, 45000)
14991499
command = ['python', self.SIMPLE_SERVER_PATH, str(SERVER_PORT)]
1500-
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
1500+
server_process = subprocess.Popen(command)
15011501

15021502
# NOTE: Following error is raised if a delay is not long enough to allow
15031503
# the server process to set up and start listening:
@@ -1888,14 +1888,14 @@ def setUp(self):
18881888
command = ['python', self.SIMPLE_SERVER_PATH, str(self.SERVER_PORT)]
18891889
command2 = ['python', self.SIMPLE_SERVER_PATH, str(self.SERVER_PORT2)]
18901890

1891-
self.server_process = subprocess.Popen(command, stderr=subprocess.PIPE,
1891+
self.server_process = subprocess.Popen(command,
18921892
cwd=self.repository_directory)
18931893

18941894
logger.debug('Server process started.')
18951895
logger.debug('Server process id: ' + str(self.server_process.pid))
18961896
logger.debug('Serving on port: ' + str(self.SERVER_PORT))
18971897

1898-
self.server_process2 = subprocess.Popen(command2, stderr=subprocess.PIPE,
1898+
self.server_process2 = subprocess.Popen(command2,
18991899
cwd=self.repository_directory2)
19001900

19011901
logger.debug('Server process 2 started.')

tests/test_updater_root_rotation_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def setUpClass(cls):
9090
# etc.
9191
cls.SERVER_PORT = random.randint(30000, 45000)
9292
command = ['python', 'simple_server.py', str(cls.SERVER_PORT)]
93-
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
93+
cls.server_process = subprocess.Popen(command)
9494
logger.info('\n\tServer process started.')
9595
logger.info('\tServer process id: '+str(cls.server_process.pid))
9696
logger.info('\tServing on port: '+str(cls.SERVER_PORT))

0 commit comments

Comments
 (0)