Skip to content

Commit 48b323e

Browse files
ambvtiran
andauthored
[3.8] gh-94208: Add more TLS version/protocol checks for FreeBSD (GH-94347) (GH-95313)
Three test cases were failing on FreeBSD with latest OpenSSL. (cherry picked from commit 1bc86c2) Co-authored-by: Christian Heimes <[email protected]>
1 parent f78733b commit 48b323e

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

Lib/test/test_ssl.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,12 @@ class ContextTests(unittest.TestCase):
11271127

11281128
def test_constructor(self):
11291129
for protocol in PROTOCOLS:
1130-
ssl.SSLContext(protocol)
1131-
ctx = ssl.SSLContext()
1130+
if has_tls_protocol(protocol):
1131+
with support.check_warnings():
1132+
ctx = ssl.SSLContext(protocol)
1133+
self.assertEqual(ctx.protocol, protocol)
1134+
with support.check_warnings():
1135+
ctx = ssl.SSLContext()
11321136
self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLS)
11331137
self.assertRaises(ValueError, ssl.SSLContext, -1)
11341138
self.assertRaises(ValueError, ssl.SSLContext, 42)
@@ -1279,7 +1283,7 @@ def test_min_max_version(self):
12791283
ctx.maximum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
12801284
self.assertIn(
12811285
ctx.maximum_version,
1282-
{ssl.TLSVersion.TLSv1, ssl.TLSVersion.SSLv3}
1286+
{ssl.TLSVersion.TLSv1, ssl.TLSVersion.TLSv1_1, ssl.TLSVersion.SSLv3}
12831287
)
12841288

12851289
ctx.minimum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED
@@ -1291,19 +1295,19 @@ def test_min_max_version(self):
12911295
with self.assertRaises(ValueError):
12921296
ctx.minimum_version = 42
12931297

1294-
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_1)
1295-
1296-
self.assertIn(
1297-
ctx.minimum_version, minimum_range
1298-
)
1299-
self.assertEqual(
1300-
ctx.maximum_version, ssl.TLSVersion.MAXIMUM_SUPPORTED
1301-
)
1302-
with self.assertRaises(ValueError):
1303-
ctx.minimum_version = ssl.TLSVersion.MINIMUM_SUPPORTED
1304-
with self.assertRaises(ValueError):
1305-
ctx.maximum_version = ssl.TLSVersion.TLSv1
1298+
if has_tls_protocol(ssl.PROTOCOL_TLSv1_1):
1299+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_1)
13061300

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
13071311

13081312
@unittest.skipUnless(have_verify_flags(),
13091313
"verify_flags need OpenSSL > 0.9.8")
@@ -1689,10 +1693,12 @@ def test__create_stdlib_context(self):
16891693
self.assertFalse(ctx.check_hostname)
16901694
self._assert_context_options(ctx)
16911695

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

16971703
ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1,
16981704
cert_reqs=ssl.CERT_REQUIRED,
@@ -3406,10 +3412,12 @@ def test_protocol_tlsv1_2(self):
34063412
client_options=ssl.OP_NO_TLSv1_2)
34073413

34083414
try_protocol_combo(ssl.PROTOCOL_TLS, ssl.PROTOCOL_TLSv1_2, 'TLSv1.2')
3409-
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1, False)
3410-
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_2, False)
3411-
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
3412-
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2, False)
3415+
if has_tls_protocol(ssl.PROTOCOL_TLSv1):
3416+
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1, False)
3417+
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1_2, False)
3418+
if has_tls_protocol(ssl.PROTOCOL_TLSv1_1):
3419+
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
3420+
try_protocol_combo(ssl.PROTOCOL_TLSv1_1, ssl.PROTOCOL_TLSv1_2, False)
34133421

34143422
def test_starttls(self):
34153423
"""Switching from clear text to encrypted and back again."""
Lines changed: 2 additions & 0 deletions
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)