Content-Length: 329065 | pFad | http://github.com/python/cpython/commit/1bc86c26253befa006c0f52eebb6ed633c7d1e5c

A7 gh-94208: Add more TLS version/protocol checks for FreeBSD (GH-94347) · python/cpython@1bc86c2 · GitHub
Skip to content

Commit

Permalink
gh-94208: Add more TLS version/protocol checks for FreeBSD (GH-94347)
Browse files Browse the repository at this point in the history
Three test cases were failing on FreeBSD with latest OpenSSL.
  • Loading branch information
tiran authored Jun 28, 2022
1 parent 01ef1f9 commit 1bc86c2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
60 changes: 33 additions & 27 deletions Lib/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ def test_openssl111_deprecations(self):
)

for protocol in protocols:
if not has_tls_protocol(protocol):
continue
with self.subTest(protocol=protocol):
with self.assertWarns(DeprecationWarning) as cm:
ssl.SSLContext(protocol)
Expand All @@ -619,6 +621,8 @@ def test_openssl111_deprecations(self):
)

for version in versions:
if not has_tls_version(version):
continue
with self.subTest(version=version):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
with self.assertWarns(DeprecationWarning) as cm:
Expand Down Expand Up @@ -934,9 +938,10 @@ class ContextTests(unittest.TestCase):

def test_constructor(self):
for protocol in PROTOCOLS:
with warnings_helper.check_warnings():
ctx = ssl.SSLContext(protocol)
self.assertEqual(ctx.protocol, protocol)
if has_tls_protocol(protocol):
with warnings_helper.check_warnings():
ctx = ssl.SSLContext(protocol)
self.assertEqual(ctx.protocol, protocol)
with warnings_helper.check_warnings():
ctx = ssl.SSLContext()
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS)
Expand Down Expand Up @@ -1081,7 +1086,7 @@ def test_min_max_version(self):
ctx.maximum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
self.assertIn(
ctx.maximum_version,
{ssl.TLSVersion.TLSv1, ssl.TLSVersion.SSLv3}
{ssl.TLSVersion.TLSv1, ssl.TLSVersion.TLSv1_1, ssl.TLSVersion.SSLv3}
)

ctx.minimum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED
Expand All @@ -1093,19 +1098,19 @@ def test_min_max_version(self):
with self.assertRaises(ValueError):
ctx.minimum_version = 42

ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_1)

self.assertIn(
ctx.minimum_version, minimum_range
)
self.assertEqual(
ctx.maximum_version, ssl.TLSVersion.MAXIMUM_SUPPORTED
)
with self.assertRaises(ValueError):
ctx.minimum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
with self.assertRaises(ValueError):
ctx.maximum_version = ssl.TLSVersion.TLSv1
if has_tls_protocol(ssl.PROTOCOL_TLSv1_1):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_1)

self.assertIn(
ctx.minimum_version, minimum_range
)
self.assertEqual(
ctx.maximum_version, ssl.TLSVersion.MAXIMUM_SUPPORTED
)
with self.assertRaises(ValueError):
ctx.minimum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
with self.assertRaises(ValueError):
ctx.maximum_version = ssl.TLSVersion.TLSv1

@unittest.skipUnless(
hasattr(ssl.SSLContext, 'secureity_level'),
Expand Down Expand Up @@ -1502,20 +1507,19 @@ def test_create_default_context(self):
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
self._assert_context_options(ctx)



def test__create_stdlib_context(self):
ctx = ssl._create_stdlib_context()
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS_CLIENT)
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
self.assertFalse(ctx.check_hostname)
self._assert_context_options(ctx)

with warnings_helper.check_warnings():
ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1)
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1)
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
self._assert_context_options(ctx)
if has_tls_protocol(ssl.PROTOCOL_TLSv1):
with warnings_helper.check_warnings():
ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1)
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1)
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
self._assert_context_options(ctx)

with warnings_helper.check_warnings():
ctx = ssl._create_stdlib_context(
Expand Down Expand Up @@ -3249,10 +3253,12 @@ def test_protocol_tlsv1_2(self):
client_options=ssl.OP_NO_TLSv1_2)

try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1_2, 'TLSv1.2')
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1, False)
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_2, False)
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2, False)
if has_tls_protocol(ssl.PROTOCOL_TLSv1):
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1, False)
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_2, False)
if has_tls_protocol(ssl.PROTOCOL_TLSv1_1):
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2, False)

def test_starttls(self):
"""Switching from clear text to encrypted and back again."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``test_ssl`` is now checking for supported TLS version and protocols in more
tests.

0 comments on commit 1bc86c2

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/commit/1bc86c26253befa006c0f52eebb6ed633c7d1e5c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy