Skip to content

Commit c199831

Browse files
ambvtiran
andauthored
[3.7] gh-94208: Add more TLS version/protocol checks for FreeBSD (GH-94347) (GH-95314)
Three test cases were failing on FreeBSD with latest OpenSSL. (cherry picked from commit 1bc86c2) Co-authored-by: Christian Heimes <christian@python.org>
1 parent dfc5e45 commit c199831

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

Lib/test/test_ssl.py

+31-23
Original file line numberDiff line numberDiff line change
@@ -1131,8 +1131,12 @@ class ContextTests(unittest.TestCase):
11311131
@skip_if_broken_ubuntu_ssl
11321132
def test_constructor(self):
11331133
for protocol in PROTOCOLS:
1134-
ssl.SSLContext(protocol)
1135-
ctx = ssl.SSLContext()
1134+
if has_tls_protocol(protocol):
1135+
with support.check_warnings():
1136+
ctx = ssl.SSLContext(protocol)
1137+
self.assertEqual(ctx.protocol, protocol)
1138+
with support.check_warnings():
1139+
ctx = ssl.SSLContext()
11361140
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS)
11371141
self.assertRaises(ValueError, ssl.SSLContext, -1)
11381142
self.assertRaises(ValueError, ssl.SSLContext, 42)
@@ -1284,7 +1288,7 @@ def test_min_max_version(self):
12841288
ctx.maximum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
12851289
self.assertIn(
12861290
ctx.maximum_version,
1287-
{ssl.TLSVersion.TLSv1, ssl.TLSVersion.SSLv3}
1291+
{ssl.TLSVersion.TLSv1, ssl.TLSVersion.TLSv1_1, ssl.TLSVersion.SSLv3}
12881292
)
12891293

12901294
ctx.minimum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED
@@ -1296,19 +1300,19 @@ def test_min_max_version(self):
12961300
with self.assertRaises(ValueError):
12971301
ctx.minimum_version = 42
12981302

1299-
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_1)
1300-
1301-
self.assertIn(
1302-
ctx.minimum_version, minimum_range
1303-
)
1304-
self.assertEqual(
1305-
ctx.maximum_version, ssl.TLSVersion.MAXIMUM_SUPPORTED
1306-
)
1307-
with self.assertRaises(ValueError):
1308-
ctx.minimum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
1309-
with self.assertRaises(ValueError):
1310-
ctx.maximum_version = ssl.TLSVersion.TLSv1
1303+
if has_tls_protocol(ssl.PROTOCOL_TLSv1_1):
1304+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_1)
13111305

1306+
self.assertIn(
1307+
ctx.minimum_version, minimum_range
1308+
)
1309+
self.assertEqual(
1310+
ctx.maximum_version, ssl.TLSVersion.MAXIMUM_SUPPORTED
1311+
)
1312+
with self.assertRaises(ValueError):
1313+
ctx.minimum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
1314+
with self.assertRaises(ValueError):
1315+
ctx.maximum_version = ssl.TLSVersion.TLSv1
13121316

13131317
@unittest.skipUnless(have_verify_flags(),
13141318
"verify_flags need OpenSSL > 0.9.8")
@@ -1690,10 +1694,12 @@ def test__create_stdlib_context(self):
16901694
self.assertFalse(ctx.check_hostname)
16911695
self._assert_context_options(ctx)
16921696

1693-
ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1)
1694-
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1)
1695-
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
1696-
self._assert_context_options(ctx)
1697+
if has_tls_protocol(ssl.PROTOCOL_TLSv1):
1698+
with support.check_warnings():
1699+
ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1)
1700+
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1)
1701+
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
1702+
self._assert_context_options(ctx)
16971703

16981704
ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1,
16991705
cert_reqs=ssl.CERT_REQUIRED,
@@ -3363,10 +3369,12 @@ def test_protocol_tlsv1_2(self):
33633369
client_options=ssl.OP_NO_TLSv1_2)
33643370

33653371
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1_2, 'TLSv1.2')
3366-
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1, False)
3367-
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_2, False)
3368-
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
3369-
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2, False)
3372+
if has_tls_protocol(ssl.PROTOCOL_TLSv1):
3373+
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1, False)
3374+
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_2, False)
3375+
if has_tls_protocol(ssl.PROTOCOL_TLSv1_1):
3376+
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
3377+
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2, False)
33703378

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

0 commit comments

Comments
 (0)