@@ -290,6 +290,9 @@ def test_https_connection(self):
290
290
# Trust the certfile that happens to use a different hostname than we
291
291
# will expect.
292
292
os .environ ['REQUESTS_CA_BUNDLE' ] = bad_cert_fname
293
+ # Clear sessions to ensure that the certificate we just specified is used.
294
+ # TODO: Confirm necessity of this session clearing and lay out mechanics.
295
+ tuf .download ._sessions = {}
293
296
294
297
# Try connecting to the server process with the bad cert while trusting
295
298
# the bad cert. Expect failure because even though we trust it, the
@@ -316,8 +319,12 @@ def test_https_connection(self):
316
319
with self .assertRaises (requests .exceptions .SSLError ):
317
320
download .unsafe_download (good2_https_url , target_data_length )
318
321
322
+
319
323
# Configure environment to now trust the certfile that is expired.
320
324
os .environ ['REQUESTS_CA_BUNDLE' ] = expired_cert_fname
325
+ # Clear sessions to ensure that the certificate we just specified is used.
326
+ # TODO: Confirm necessity of this session clearing and lay out mechanics.
327
+ tuf .download ._sessions = {}
321
328
322
329
# Try connecting to the server process with the expired cert while
323
330
# trusting the expired cert. Expect failure because even though we trust
@@ -328,20 +335,23 @@ def test_https_connection(self):
328
335
with self .assertRaises (requests .exceptions .SSLError ):
329
336
download .unsafe_download (expired_https_url , target_data_length )
330
337
338
+
331
339
# Try connecting to the server processes with the good certs while
332
340
# trusting the appropriate good certs. Expect success.
333
- # Note: running these OK downloads at the top of this try section causes
334
- # a failure in a previous assertion: retrieving the same good URL
335
- # again after no longer "trusting" the good certfile still succeeds
336
- # if we had previously succeeded in retrieving that same URL while
337
- # still trusting the good cert. Perhaps it's a caching issue....?
338
- # I'm not especially concerned yet, but take note for later....
341
+ # TODO: expand testing to switch expected certificates back and forth a
342
+ # bit more while clearing / not clearing sessions.
339
343
os .environ ['REQUESTS_CA_BUNDLE' ] = good_cert_fname
344
+ # Clear sessions to ensure that the certificate we just specified is used.
345
+ # TODO: Confirm necessity of this session clearing and lay out mechanics.
346
+ tuf .download ._sessions = {}
340
347
logger .info ('Trying HTTPS download of target file: ' + good_https_url )
341
348
download .safe_download (good_https_url , target_data_length )
342
349
download .unsafe_download (good_https_url , target_data_length )
343
350
344
351
os .environ ['REQUESTS_CA_BUNDLE' ] = good2_cert_fname
352
+ # Clear sessions to ensure that the certificate we just specified is used.
353
+ # TODO: Confirm necessity of this session clearing and lay out mechanics.
354
+ tuf .download ._sessions = {}
345
355
logger .info ('Trying HTTPS download of target file: ' + good2_https_url )
346
356
download .safe_download (good2_https_url , target_data_length )
347
357
download .unsafe_download (good2_https_url , target_data_length )
0 commit comments