Skip to content

Commit 7ce54c2

Browse files
authored
Reset bundle path to use system settings/environment variables (#697)
1 parent 27440fb commit 7ce54c2

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

pyproj/network.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,29 @@ def set_ca_bundle_path(ca_bundle_path: Union[Path, str, bool, None] = None) -> N
3333
Default is None, which only uses the `certifi` package path as a fallback if
3434
the environment variables are not set. If a path is passed in, then
3535
that will be the path used. If it is set to True, then it will default
36-
to using the path provied by the `certifi` package. If it is set to False,
37-
then it will not set the path.
36+
to using the path provied by the `certifi` package. If it is set to False
37+
or an empty string then it will default to the system settings or environment
38+
variables.
3839
"""
39-
if ca_bundle_path is False:
40-
return
41-
4240
env_var_names = (
4341
"PROJ_CURL_CA_BUNDLE",
4442
"CURL_CA_BUNDLE",
4543
"SSL_CERT_FILE",
4644
)
47-
if isinstance(ca_bundle_path, (str, Path)):
45+
if ca_bundle_path is False:
46+
# need to reset CA Bundle path to use system settings
47+
# or environment variables because it
48+
# could have been changed by the user previously
49+
ca_bundle_path = ""
50+
elif isinstance(ca_bundle_path, (str, Path)):
4851
ca_bundle_path = str(ca_bundle_path)
4952
elif (ca_bundle_path is True) or not any(
5053
env_var_name in os.environ for env_var_name in env_var_names
5154
):
5255
ca_bundle_path = certifi.where()
56+
else:
57+
# reset CA Bundle path to use system settings
58+
# or environment variables
59+
ca_bundle_path = ""
5360

54-
if isinstance(ca_bundle_path, str):
55-
_set_ca_bundle_path(ca_bundle_path)
61+
_set_ca_bundle_path(ca_bundle_path)

test/test_network.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_ca_bundle_path__always_certifi(c_set_ca_bundle_path_mock, env_var):
2626
@patch("pyproj.network._set_ca_bundle_path")
2727
def test_ca_bundle_path__skip(c_set_ca_bundle_path_mock):
2828
set_ca_bundle_path(False)
29-
c_set_ca_bundle_path_mock.assert_not_called()
29+
c_set_ca_bundle_path_mock.assert_called_with("")
3030

3131

3232
@pytest.mark.parametrize(
@@ -36,7 +36,7 @@ def test_ca_bundle_path__skip(c_set_ca_bundle_path_mock):
3636
def test_ca_bundle_path__env_var_skip(c_set_ca_bundle_path_mock, env_var):
3737
with patch.dict("os.environ", {env_var: "/tmp/dummy/path/cacert.pem"}, clear=True):
3838
set_ca_bundle_path()
39-
c_set_ca_bundle_path_mock.assert_not_called()
39+
c_set_ca_bundle_path_mock.assert_called_with("")
4040

4141

4242
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)