@@ -197,28 +197,29 @@ def test_download_url_to_tempfileobj_and_urls(self):
197
197
198
198
199
199
200
+ '''
200
201
# This test uses sites on the internet, requiring a net connection to succeed.
201
202
# Since this is the only such test in TUF, I'm not going to enable it... but
202
203
# it's here in case it's useful for diagnosis.
203
- # def test_https_validation(self):
204
- # """
205
- # Use some known URLs on the net to ensure that TUF download checks SSL
206
- # certificates appropriately.
207
- # """
208
- # # We should never get as far as the target file download itself, so the
209
- # # length we pass to safe_download and unsafe_download shouldn't matter.
210
- # irrelevant_length = 10
211
- #
212
- # for bad_url in [
213
- # 'https://expired.badssl.com/', # expired certificate
214
- # 'https://wrong.host.badssl.com/', ]: # hostname verification fail
215
- #
216
- # with self.assertRaises(requests.exceptions.SSLError):
217
- # download.safe_download(bad_url, irrelevant_length)
218
- #
219
- # with self.assertRaises(requests.exceptions.SSLError):
220
- # download.unsafe_download(bad_url, irrelevant_length)
204
+ def test_https_validation(self):
205
+ """
206
+ Use some known URLs on the net to ensure that TUF download checks SSL
207
+ certificates appropriately.
208
+ """
209
+ # We should never get as far as the target file download itself, so the
210
+ # length we pass to safe_download and unsafe_download shouldn't matter.
211
+ irrelevant_length = 10
212
+
213
+ for bad_url in [
214
+ 'https://expired.badssl.com/', # expired certificate
215
+ 'https://wrong.host.badssl.com/', ]: # hostname verification fail
221
216
217
+ with self.assertRaises(requests.exceptions.SSLError):
218
+ download.safe_download(bad_url, irrelevant_length)
219
+
220
+ with self.assertRaises(requests.exceptions.SSLError):
221
+ download.unsafe_download(bad_url, irrelevant_length)
222
+ '''
222
223
223
224
224
225
@@ -250,10 +251,12 @@ def test_https_connection(self):
250
251
bad_cert_fname = os .path .join ('ssl_certs' , 'ssl_cert_wronghost.crt' )
251
252
expired_cert_fname = os .path .join ('ssl_certs' , 'ssl_cert_expired.crt' )
252
253
253
- # Launch three https servers (serve files in the current dir).
254
- # The first we expect to operate correctly.
255
- # The second we run with an HTTPS certificate with an unexpected hostname.
256
- # The third we run with an HTTPS certificate that is expired.
254
+ # Launch four HTTPS servers (serve files in the current dir).
255
+ # 1: we expect to operate correctly
256
+ # 2: also good; uses a slightly different cert (controls for the cert
257
+ # generation method used for the next two, in case it comes to matter)
258
+ # 3: run with an HTTPS certificate with an unexpected hostname
259
+ # 4: run with an HTTPS certificate that is expired
257
260
port1 = str (random .randint (30000 , 45000 ))
258
261
port2 = str (int (port1 ) + 1 )
259
262
port3 = str (int (port1 ) + 2 )
@@ -267,7 +270,7 @@ def test_https_connection(self):
267
270
bad_https_server_proc = subprocess .Popen (command3 , stderr = subprocess .PIPE )
268
271
expd_https_server_proc = subprocess .Popen (command4 , stderr = subprocess .PIPE )
269
272
270
- # Provide a delay long enough to allow the https servers to start.
273
+ # Provide a delay long enough to allow the HTTPS servers to start.
271
274
# Encountered an error on one test system at delay value of 0.2s, so
272
275
# increasing to 0.5s.
273
276
# Expect to see "Connection refused" if this delay is not long enough
@@ -280,7 +283,7 @@ def test_https_connection(self):
280
283
bad_https_url = good_https_url .replace (':' + port1 , ':' + port3 )
281
284
expired_https_url = good_https_url .replace (':' + port1 , ':' + port4 )
282
285
283
- # Download the target file using an https connection.
286
+ # Download the target file using an HTTPS connection.
284
287
285
288
# Use try-finally solely to ensure that the server processes are killed.
286
289
try :
@@ -291,7 +294,7 @@ def test_https_connection(self):
291
294
# Try connecting to the server process with the bad cert while trusting
292
295
# the bad cert. Expect failure because even though we trust it, the
293
296
# hostname we're connecting to does not match the hostname in the cert.
294
- logger .info ('Trying https download of target file: ' + bad_https_url )
297
+ logger .info ('Trying HTTPS download of target file: ' + bad_https_url )
295
298
with self .assertRaises (requests .exceptions .SSLError ):
296
299
download .safe_download (bad_https_url , target_data_length )
297
300
with self .assertRaises (requests .exceptions .SSLError ):
@@ -301,13 +304,13 @@ def test_https_connection(self):
301
304
# trusting the good certs (trusting the bad cert instead). Expect failure
302
305
# because even though the server's cert file is otherwise OK, we don't
303
306
# trust it.
304
- print ('Trying https download of target file: ' + good_https_url )
307
+ print ('Trying HTTPS download of target file: ' + good_https_url )
305
308
with self .assertRaises (requests .exceptions .SSLError ):
306
309
download .safe_download (good_https_url , target_data_length )
307
310
with self .assertRaises (requests .exceptions .SSLError ):
308
311
download .unsafe_download (good_https_url , target_data_length )
309
312
310
- print ('Trying https download of target file: ' + good2_https_url )
313
+ print ('Trying HTTPS download of target file: ' + good2_https_url )
311
314
with self .assertRaises (requests .exceptions .SSLError ):
312
315
download .safe_download (good2_https_url , target_data_length )
313
316
with self .assertRaises (requests .exceptions .SSLError ):
@@ -319,7 +322,7 @@ def test_https_connection(self):
319
322
# Try connecting to the server process with the expired cert while
320
323
# trusting the expired cert. Expect failure because even though we trust
321
324
# it, it is expired.
322
- logger .info ('Trying https download of target file: ' + expired_https_url )
325
+ logger .info ('Trying HTTPS download of target file: ' + expired_https_url )
323
326
with self .assertRaises (requests .exceptions .SSLError ):
324
327
download .safe_download (expired_https_url , target_data_length )
325
328
with self .assertRaises (requests .exceptions .SSLError ):
@@ -334,12 +337,12 @@ def test_https_connection(self):
334
337
# still trusting the good cert. Perhaps it's a caching issue....?
335
338
# I'm not especially concerned yet, but take note for later....
336
339
os .environ ['REQUESTS_CA_BUNDLE' ] = good_cert_fname
337
- logger .info ('Trying https download of target file: ' + good_https_url )
340
+ logger .info ('Trying HTTPS download of target file: ' + good_https_url )
338
341
download .safe_download (good_https_url , target_data_length )
339
342
download .unsafe_download (good_https_url , target_data_length )
340
343
341
344
os .environ ['REQUESTS_CA_BUNDLE' ] = good2_cert_fname
342
- logger .info ('Trying https download of target file: ' + good2_https_url )
345
+ logger .info ('Trying HTTPS download of target file: ' + good2_https_url )
343
346
download .safe_download (good2_https_url , target_data_length )
344
347
download .unsafe_download (good2_https_url , target_data_length )
345
348
0 commit comments