@@ -290,6 +290,9 @@ def test_https_connection(self):
290290 # Trust the certfile that happens to use a different hostname than we
291291 # will expect.
292292 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 = {}
293296
294297 # Try connecting to the server process with the bad cert while trusting
295298 # the bad cert. Expect failure because even though we trust it, the
@@ -316,8 +319,12 @@ def test_https_connection(self):
316319 with self .assertRaises (requests .exceptions .SSLError ):
317320 download .unsafe_download (good2_https_url , target_data_length )
318321
322+
319323 # Configure environment to now trust the certfile that is expired.
320324 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 = {}
321328
322329 # Try connecting to the server process with the expired cert while
323330 # trusting the expired cert. Expect failure because even though we trust
@@ -328,20 +335,23 @@ def test_https_connection(self):
328335 with self .assertRaises (requests .exceptions .SSLError ):
329336 download .unsafe_download (expired_https_url , target_data_length )
330337
338+
331339 # Try connecting to the server processes with the good certs while
332340 # 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.
339343 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 = {}
340347 logger .info ('Trying HTTPS download of target file: ' + good_https_url )
341348 download .safe_download (good_https_url , target_data_length )
342349 download .unsafe_download (good_https_url , target_data_length )
343350
344351 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 = {}
345355 logger .info ('Trying HTTPS download of target file: ' + good2_https_url )
346356 download .safe_download (good2_https_url , target_data_length )
347357 download .unsafe_download (good2_https_url , target_data_length )
0 commit comments