Skip to content

Commit

Permalink
Fix deprecation message, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Oct 7, 2020
1 parent 3515508 commit 0803f6a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/urllib3/connection.py
Expand Up @@ -409,7 +409,7 @@ def connect(self):
):
warnings.warn(
"Negotiating TLSv1/TLSv1.1 by default is deprecated "
"and will be disabled in urllib3 v2.0.0. Connecting to"
"and will be disabled in urllib3 v2.0.0. Connecting to "
"'%s' with '%s' can be enabled by explicitly opting-in "
"with 'ssl_version'" % (self.host, self.sock.version()),
DeprecationWarning,
Expand Down
38 changes: 36 additions & 2 deletions test/with_dummyserver/test_https.py
Expand Up @@ -733,18 +733,52 @@ def test_default_tls_version_deprecations(self):
finally:
conn.close()

assert w is not None
if self.tls_protocol_deprecated():
assert len(w) == 1
assert str(w[0].message) == (
"Negotiating TLSv1/TLSv1.1 by default is deprecated "
"and will be disabled in urllib3 v2.0.0. Connecting to"
"and will be disabled in urllib3 v2.0.0. Connecting to "
"'%s' with '%s' can be enabled by explicitly opting-in "
"with 'ssl_version'" % (self.host, self.tls_protocol_name)
)
else:
assert w == []

def test_no_tls_version_deprecation_with_ssl_version(self):
if self.tls_protocol_name is None:
pytest.skip("Skipping base test class")

with HTTPSConnectionPool(
self.host, self.port, ca_certs=DEFAULT_CA, ssl_version=util.PROTOCOL_TLS
) as https_pool:
conn = https_pool._get_conn()
try:
with warnings.catch_warnings(record=True) as w:
conn.connect()
finally:
conn.close()

assert w == []

def test_no_tls_version_deprecation_with_ssl_context(self):
if self.tls_protocol_name is None:
pytest.skip("Skipping base test class")

with HTTPSConnectionPool(
self.host,
self.port,
ca_certs=DEFAULT_CA,
ssl_context=util.ssl_.create_urllib3_context(),
) as https_pool:
conn = https_pool._get_conn()
try:
with warnings.catch_warnings(record=True) as w:
conn.connect()
finally:
conn.close()

assert w == []

@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python 3.8+")
def test_sslkeylogfile(self, tmpdir, monkeypatch):
if not hasattr(util.SSLContext, "keylog_filename"):
Expand Down

0 comments on commit 0803f6a

Please sign in to comment.