From de20687ee6b742646128a7629b57096631a20619 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Fri, 28 Jul 2023 13:48:17 +0530 Subject: [PATCH] [test] Fix `test_load_certifi` Closes #7688, #7675 --- test/test_networking_utils.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/test_networking_utils.py b/test/test_networking_utils.py index ef46f79ed..dbf656090 100644 --- a/test/test_networking_utils.py +++ b/test/test_networking_utils.py @@ -95,17 +95,20 @@ class TestNetworkingUtils: @pytest.mark.skipif(not certifi, reason='certifi is not installed') def test_load_certifi(self): + context_certifi = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + context_certifi.load_verify_locations(cafile=certifi.where()) context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) - context2 = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) ssl_load_certs(context, use_certifi=True) - context2.load_verify_locations(cafile=certifi.where()) - assert context.get_ca_certs() == context2.get_ca_certs() + assert context.get_ca_certs() == context_certifi.get_ca_certs() - # Test load normal certs - # XXX: could there be a case where system certs are the same as certifi? - context3 = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) - ssl_load_certs(context3, use_certifi=False) - assert context3.get_ca_certs() != context.get_ca_certs() + context_default = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + context_default.load_default_certs() + context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + ssl_load_certs(context, use_certifi=False) + assert context.get_ca_certs() == context_default.get_ca_certs() + + if context_default.get_ca_certs() == context_certifi.get_ca_certs(): + pytest.skip('System uses certifi as default. The test is not valid') @pytest.mark.parametrize('method,status,expected', [ ('GET', 303, 'GET'),