Skip to content

Commit 52c8df7

Browse files
authored
Merge branch 'develop' into snapshot-merkle-tree
2 parents d77db05 + e3ff011 commit 52c8df7

28 files changed

Lines changed: 462 additions & 293 deletions

requirements-pinned.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
certifi==2020.6.20 # via requests
2-
cffi==1.14.1 # via cryptography, pynacl
2+
cffi==1.14.2 # via cryptography, pynacl
33
chardet==3.0.4 # via requests
44
colorama==0.4.3 # via securesystemslib
55
cryptography==3.0 # via securesystemslib
@@ -11,7 +11,7 @@ pycparser==2.20 # via cffi
1111
pynacl==1.4.0 # via securesystemslib
1212
python-dateutil==2.8.1 # via securesystemslib
1313
requests==2.24.0
14-
securesystemslib[colors,crypto,pynacl]==0.15.0
14+
securesystemslib[colors,crypto,pynacl]==0.16.0
1515
six==1.15.0
1616
subprocess32==3.5.4 ; python_version < '3' # via securesystemslib
1717
urllib3==1.25.10 # via requests

tests/proxy_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def test(HandlerClass=ProxyRequestHandler, ServerClass=ThreadingHTTPServer, prot
466466
port = int(sys.argv[1])
467467
else:
468468
port = 8080
469-
server_address = ('127.0.0.1', port) # MODIFIED: changed from '::1'
469+
server_address = ('localhost', port)
470470

471471
# MODIFIED: Argument added, conditional below added to control INTERCEPT
472472
# setting.

tests/simple_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
import sys
3737
import random
38-
import platform
3938

4039
import six
4140
from six.moves.SimpleHTTPServer import SimpleHTTPRequestHandler
@@ -80,6 +79,9 @@ def log_request(self, code='-', size='-'):
8079
else:
8180
handler = SimpleHTTPRequestHandler
8281

82+
# Allow re-use so you can re-run tests as often as you want even if the
83+
# tests re-use ports. Otherwise TCP TIME-WAIT prevents reuse for ~1 minute
84+
six.moves.socketserver.TCPServer.allow_reuse_address = True
8385
httpd = six.moves.socketserver.TCPServer(('', PORT), handler)
8486

8587
httpd.serve_forever()

tests/test_arbitrary_package_attack.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@
3939
import os
4040
import tempfile
4141
import random
42-
import time
4342
import shutil
4443
import json
4544
import subprocess
4645
import logging
47-
import sys
4846
import unittest
4947

5048
import tuf
@@ -55,6 +53,8 @@
5553
import tuf.client.updater as updater
5654
import tuf.unittest_toolbox as unittest_toolbox
5755

56+
import utils
57+
5858
import securesystemslib
5959
import six
6060

@@ -87,9 +87,7 @@ def setUpClass(cls):
8787
logger.info('Serving on port: ' + str(cls.SERVER_PORT))
8888
cls.url = 'http://localhost:' + str(cls.SERVER_PORT) + os.path.sep
8989

90-
# NOTE: Following error is raised if a delay is not applied:
91-
# <urlopen error [Errno 111] Connection refused>
92-
time.sleep(1)
90+
utils.wait_for_server('localhost', cls.SERVER_PORT)
9391

9492

9593

@@ -106,6 +104,7 @@ def tearDownClass(cls):
106104
if cls.server_process.returncode is None:
107105
logger.info('Server process ' + str(cls.server_process.pid) + ' terminated.')
108106
cls.server_process.kill()
107+
cls.server_process.wait()
109108

110109

111110

tests/test_developer_tool.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222
"""
2323

2424
import os
25-
import time
26-
import datetime
2725
import unittest
2826
import logging
2927
import tempfile
3028
import shutil
31-
import unittest
3229

3330
import tuf
3431
import tuf.log

tests/test_download.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import random
4040
import subprocess
4141
import sys
42-
import time
4342
import unittest
4443

4544
import tuf
@@ -48,10 +47,11 @@
4847
import tuf.unittest_toolbox as unittest_toolbox
4948
import tuf.exceptions
5049

50+
import utils
51+
5152
import requests.exceptions
5253

5354
import securesystemslib
54-
import six
5555

5656
logger = logging.getLogger(__name__)
5757

@@ -81,13 +81,7 @@ def setUp(self):
8181
junk, rel_target_filepath = os.path.split(target_filepath)
8282
self.url = 'http://localhost:'+str(self.PORT)+'/'+rel_target_filepath
8383

84-
# Provide a delay long enough to allow the HTTPS servers to start.
85-
# Encountered an error on one test system at delay value of 0.2s, so
86-
# increasing to 0.5s. Further increasing to 2s due to occasional failures
87-
# in other tests in similar circumstances on AppVeyor.
88-
# Expect to see "Connection refused" if this delay is not long enough
89-
# (though other issues could cause that).
90-
time.sleep(2)
84+
utils.wait_for_server('localhost', self.PORT)
9185

9286
# Computing hash of target file data.
9387
m = hashlib.md5()
@@ -102,6 +96,8 @@ def tearDown(self):
10296
if self.server_proc.returncode is None:
10397
logger.info('\tServer process '+str(self.server_proc.pid)+' terminated.')
10498
self.server_proc.kill()
99+
# Drop return values of communicate()
100+
self.server_proc.communicate()
105101
self.target_fileobj.close()
106102

107103

@@ -129,8 +125,8 @@ def test_download_url_to_tempfileobj_and_lengths(self):
129125
# the server-reported length of the file does not match the
130126
# required_length. 'updater.py' *does* verify the hashes of downloaded
131127
# content.
132-
download.safe_download(self.url, self.target_data_length - 4)
133-
download.unsafe_download(self.url, self.target_data_length - 4)
128+
download.safe_download(self.url, self.target_data_length - 4).close()
129+
download.unsafe_download(self.url, self.target_data_length - 4).close()
134130

135131
# We catch 'tuf.exceptions.DownloadLengthMismatchError' for safe_download()
136132
# because it will not download more bytes than requested (in this case, a
@@ -140,7 +136,7 @@ def test_download_url_to_tempfileobj_and_lengths(self):
140136

141137
# Calling unsafe_download() with a mismatched length should not raise an
142138
# exception.
143-
download.unsafe_download(self.url, self.target_data_length + 1)
139+
download.unsafe_download(self.url, self.target_data_length + 1).close()
144140

145141

146142

@@ -277,12 +273,8 @@ def test_https_connection(self):
277273
expd_https_server_proc = popen_python(
278274
['simple_https_server.py', port4, expired_cert_fname])
279275

280-
# Provide a delay long enough to allow the four HTTPS servers to start.
281-
# Have encountered errors at 0.2s, 0.5s, and 2s, primarily on AppVeyor.
282-
# Increasing to 4s for this test.
283-
# Expect to see "Connection refused" if this delay is not long enough
284-
# (though other issues could cause that).
285-
time.sleep(3)
276+
for port in range(self.PORT + 1, self.PORT + 5):
277+
utils.wait_for_server('localhost', port)
286278

287279
relative_target_fpath = os.path.basename(target_filepath)
288280
good_https_url = 'https://localhost:' + port1 + '/' + relative_target_fpath
@@ -314,13 +306,13 @@ def test_https_connection(self):
314306
# trusting the good certs (trusting the bad cert instead). Expect failure
315307
# because even though the server's cert file is otherwise OK, we don't
316308
# trust it.
317-
print('Trying HTTPS download of target file: ' + good_https_url)
309+
logger.info('Trying HTTPS download of target file: ' + good_https_url)
318310
with self.assertRaises(requests.exceptions.SSLError):
319311
download.safe_download(good_https_url, target_data_length)
320312
with self.assertRaises(requests.exceptions.SSLError):
321313
download.unsafe_download(good_https_url, target_data_length)
322314

323-
print('Trying HTTPS download of target file: ' + good2_https_url)
315+
logger.info('Trying HTTPS download of target file: ' + good2_https_url)
324316
with self.assertRaises(requests.exceptions.SSLError):
325317
download.safe_download(good2_https_url, target_data_length)
326318
with self.assertRaises(requests.exceptions.SSLError):
@@ -372,6 +364,8 @@ def test_https_connection(self):
372364
if proc.returncode is None:
373365
logger.info('Terminating server process ' + str(proc.pid))
374366
proc.kill()
367+
# drop return values
368+
proc.communicate()
375369

376370

377371

tests/test_endless_data_attack.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@
4242
import os
4343
import tempfile
4444
import random
45-
import time
4645
import shutil
4746
import json
4847
import subprocess
4948
import logging
50-
import sys
5149
import unittest
5250

5351
import tuf
@@ -57,6 +55,8 @@
5755
import tuf.unittest_toolbox as unittest_toolbox
5856
import tuf.roledb
5957

58+
import utils
59+
6060
import securesystemslib
6161
import six
6262

@@ -89,9 +89,7 @@ def setUpClass(cls):
8989
logger.info('Serving on port: '+str(cls.SERVER_PORT))
9090
cls.url = 'http://localhost:'+str(cls.SERVER_PORT) + os.path.sep
9191

92-
# NOTE: Following error is raised if a delay is not applied:
93-
# <urlopen error [Errno 111] Connection refused>
94-
time.sleep(.8)
92+
utils.wait_for_server('localhost', cls.SERVER_PORT)
9593

9694

9795

@@ -108,6 +106,7 @@ def tearDownClass(cls):
108106
if cls.server_process.returncode is None:
109107
logger.info('Server process '+str(cls.server_process.pid)+' terminated.')
110108
cls.server_process.kill()
109+
cls.server_process.wait()
111110

112111

113112

tests/test_extraneous_dependencies_attack.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@
4545
import os
4646
import tempfile
4747
import random
48-
import time
4948
import shutil
5049
import json
5150
import subprocess
5251
import logging
53-
import sys
5452
import unittest
5553

5654
import tuf.formats
@@ -60,6 +58,8 @@
6058
import tuf.keydb
6159
import tuf.unittest_toolbox as unittest_toolbox
6260

61+
import utils
62+
6363
import securesystemslib
6464
import six
6565

@@ -93,9 +93,7 @@ def setUpClass(cls):
9393
logger.info('Serving on port: '+str(cls.SERVER_PORT))
9494
cls.url = 'http://localhost:'+str(cls.SERVER_PORT) + os.path.sep
9595

96-
# NOTE: Following error is raised if a delay is not applied:
97-
# <urlopen error [Errno 111] Connection refused>
98-
time.sleep(.7)
96+
utils.wait_for_server('localhost', cls.SERVER_PORT)
9997

10098

10199

@@ -112,6 +110,7 @@ def tearDownClass(cls):
112110
if cls.server_process.returncode is None:
113111
logger.info('Server process '+str(cls.server_process.pid)+' terminated.')
114112
cls.server_process.kill()
113+
cls.server_process.wait()
115114

116115

117116

tests/test_indefinite_freeze_attack.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import json
5353
import subprocess
5454
import logging
55-
import sys
5655
import unittest
5756

5857
import tuf.formats
@@ -64,6 +63,8 @@
6463
import tuf.keydb
6564
import tuf.exceptions
6665

66+
import utils
67+
6768
import securesystemslib
6869
import six
6970

@@ -100,13 +101,7 @@ def setUpClass(cls):
100101
logger.info('Serving on port: '+str(cls.SERVER_PORT))
101102
cls.url = 'http://localhost:'+str(cls.SERVER_PORT) + os.path.sep
102103

103-
# Provide a delay long enough to allow the HTTP server to start.
104-
# Encountered an error on one test system at delay value of 0.2s, so
105-
# increasing to 0.5s. Further increasing to 2s due to occasional failures
106-
# in other tests in similar circumstances on AppVeyor.
107-
# Expect to see "Connection refused" if this delay is not long enough
108-
# (though other issues could cause that).
109-
time.sleep(2)
104+
utils.wait_for_server('localhost', cls.SERVER_PORT)
110105

111106

112107

@@ -123,6 +118,7 @@ def tearDownClass(cls):
123118
if cls.server_process.returncode is None:
124119
logger.info('Server process '+str(cls.server_process.pid)+' terminated.')
125120
cls.server_process.kill()
121+
cls.server_process.wait()
126122

127123

128124

tests/test_key_revocation_integration.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,11 @@
3838
from __future__ import unicode_literals
3939

4040
import os
41-
import time
4241
import shutil
43-
import copy
4442
import tempfile
4543
import logging
4644
import random
4745
import subprocess
48-
import sys
4946
import unittest
5047

5148
import tuf
@@ -56,6 +53,8 @@
5653
import tuf.unittest_toolbox as unittest_toolbox
5754
import tuf.client.updater as updater
5855

56+
import utils
57+
5958
import securesystemslib
6059
import six
6160

@@ -89,9 +88,7 @@ def setUpClass(cls):
8988
logger.info('\tServing on port: '+str(cls.SERVER_PORT))
9089
cls.url = 'http://localhost:'+str(cls.SERVER_PORT) + os.path.sep
9190

92-
# NOTE: Following error is raised if a delay is not applied:
93-
# <urlopen error [Errno 111] Connection refused>
94-
time.sleep(1)
91+
utils.wait_for_server('localhost', cls.SERVER_PORT)
9592

9693

9794

@@ -108,6 +105,7 @@ def tearDownClass(cls):
108105
if cls.server_process.returncode is None:
109106
logger.info('\tServer process '+str(cls.server_process.pid)+' terminated.')
110107
cls.server_process.kill()
108+
cls.server_process.wait()
111109

112110

113111

0 commit comments

Comments
 (0)