Skip to content

Commit

Permalink
Remove deprecated setting of ssl_context
Browse files Browse the repository at this point in the history
Raise an exception if both a proxy_ssl_context and a ssl_context
are provided when use_forwarding_for_https=True, instead of
only raising a warning.

Modify tests to account for change.

Resolves urllib3#2577
  • Loading branch information
avi364 committed Jul 3, 2022
1 parent 929fba8 commit 6b3430f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
4 changes: 2 additions & 2 deletions changelog/2577.bugfix.rst
Expand Up @@ -2,5 +2,5 @@ The ``proxy_ssl_context`` argument for ``urllib3.ProxyManager`` will be used
for the connection to the proxy when the connection is forwarded, either because
``use_forwarding_for_https`` is set to ``True`` or because the target is a HTTP destination.
Previously, ``proxy_ssl_context`` was not used in these situations. If ``ssl_context``
is passed as a keyword argument, it will be used if ``proxy_ssl_context`` is not set,
but this use is deprecated.
was passed as a keyword argument, it had been used if ``proxy_ssl_context`` were not set,
but setting ``ssl_context`` will now raise an error.
22 changes: 6 additions & 16 deletions src/urllib3/connection.py
Expand Up @@ -424,26 +424,16 @@ def __init__(

if proxy_config and proxy_config.use_forwarding_for_https:
if proxy_config.ssl_context is not None and ssl_context is not None:
warnings.warn(
"The 'ssl_context' parameter is not used to configure the connection to the proxy when the 'use_forwarding_for_https' parameter is set to True "
"and should not be set. The 'proxy_ssl_context' parameter is used to configure the connection. "
"In a later urllib3 v2.x release, setting ssl_context will result in an error",
DeprecationWarning,
stacklevel=2,
raise ValueError(
"The 'ssl_context' parameter cannot be set when use_forwarding_for_https is True"
)
elif proxy_config.ssl_context is None and ssl_context is not None:
warnings.warn(
"The 'ssl_context' parameter should not be used to configure the connection to the proxy when the 'use_forwarding_for_https' parameter is set to True, "
"Use the 'proxy_ssl_context' parameter to customize the connection. "
"In a later urllib3 v2.x release, setting ssl_context will result in an error",
DeprecationWarning,
stacklevel=2,
)
self.proxy_config = ProxyConfig(
ssl_context, proxy_config.use_forwarding_for_https
raise ValueError(
"The 'ssl_context' parameter cannot be set when use_forwarding_for_https is True. Use the 'proxy_ssl_context' parameter to customize the connection to the proxy"
)
else:

self.ssl_context = proxy_config.ssl_context
self.ssl_context = proxy_config.ssl_context
else:
self.ssl_context = ssl_context

Expand Down
8 changes: 6 additions & 2 deletions test/with_dummyserver/test_proxy_poolmanager.py
Expand Up @@ -426,7 +426,9 @@ def test_forwarding_for_https_error_with_ssl_ctx(self) -> None:
use_forwarding_for_https=True,
ssl_context=ctx,
) as proxy:
with pytest.warns(DeprecationWarning):
with pytest.raises(
ValueError, match="The 'ssl_context' parameter cannot be set"
):
proxy.request("GET", self.https_url)

def test_forwarding_for_https_error_with_only_ssl_ctx(self) -> None:
Expand All @@ -435,7 +437,9 @@ def test_forwarding_for_https_error_with_only_ssl_ctx(self) -> None:
with proxy_from_url(
self.https_proxy_url, use_forwarding_for_https=True, ssl_context=ctx
) as proxy:
with pytest.warns(DeprecationWarning):
with pytest.raises(
ValueError, match="The 'ssl_context' parameter cannot be set"
):
proxy.request("GET", self.https_url)

def test_headerdict(self) -> None:
Expand Down

0 comments on commit 6b3430f

Please sign in to comment.