@@ -617,6 +617,8 @@ def test_openssl111_deprecations(self):
617617 )
618618
619619 for protocol in protocols :
620+ if not has_tls_protocol (protocol ):
621+ continue
620622 with self .subTest (protocol = protocol ):
621623 with self .assertWarns (DeprecationWarning ) as cm :
622624 ssl .SSLContext (protocol )
@@ -626,6 +628,8 @@ def test_openssl111_deprecations(self):
626628 )
627629
628630 for version in versions :
631+ if not has_tls_version (version ):
632+ continue
629633 with self .subTest (version = version ):
630634 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
631635 with self .assertWarns (DeprecationWarning ) as cm :
@@ -1140,9 +1144,10 @@ class ContextTests(unittest.TestCase):
11401144
11411145 def test_constructor (self ):
11421146 for protocol in PROTOCOLS :
1143- with warnings_helper .check_warnings ():
1144- ctx = ssl .SSLContext (protocol )
1145- self .assertEqual (ctx .protocol , protocol )
1147+ if has_tls_protocol (protocol ):
1148+ with warnings_helper .check_warnings ():
1149+ ctx = ssl .SSLContext (protocol )
1150+ self .assertEqual (ctx .protocol , protocol )
11461151 with warnings_helper .check_warnings ():
11471152 ctx = ssl .SSLContext ()
11481153 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS )
@@ -1287,7 +1292,7 @@ def test_min_max_version(self):
12871292 ctx .maximum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
12881293 self .assertIn (
12891294 ctx .maximum_version ,
1290- {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .SSLv3 }
1295+ {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .TLSv1_1 , ssl . TLSVersion . SSLv3 }
12911296 )
12921297
12931298 ctx .minimum_version = ssl .TLSVersion .MAXIMUM_SUPPORTED
@@ -1299,19 +1304,19 @@ def test_min_max_version(self):
12991304 with self .assertRaises (ValueError ):
13001305 ctx .minimum_version = 42
13011306
1302- ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
1303-
1304- self .assertIn (
1305- ctx .minimum_version , minimum_range
1306- )
1307- self .assertEqual (
1308- ctx .maximum_version , ssl .TLSVersion .MAXIMUM_SUPPORTED
1309- )
1310- with self .assertRaises (ValueError ):
1311- ctx .minimum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1312- with self .assertRaises (ValueError ):
1313- ctx .maximum_version = ssl .TLSVersion .TLSv1
1307+ if has_tls_protocol (ssl .PROTOCOL_TLSv1_1 ):
1308+ ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
13141309
1310+ self .assertIn (
1311+ ctx .minimum_version , minimum_range
1312+ )
1313+ self .assertEqual (
1314+ ctx .maximum_version , ssl .TLSVersion .MAXIMUM_SUPPORTED
1315+ )
1316+ with self .assertRaises (ValueError ):
1317+ ctx .minimum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1318+ with self .assertRaises (ValueError ):
1319+ ctx .maximum_version = ssl .TLSVersion .TLSv1
13151320
13161321 @unittest .skipUnless (
13171322 hasattr (ssl .SSLContext , 'security_level' ),
@@ -1707,20 +1712,19 @@ def test_create_default_context(self):
17071712 self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
17081713 self ._assert_context_options (ctx )
17091714
1710-
1711-
17121715 def test__create_stdlib_context (self ):
17131716 ctx = ssl ._create_stdlib_context ()
17141717 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS_CLIENT )
17151718 self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
17161719 self .assertFalse (ctx .check_hostname )
17171720 self ._assert_context_options (ctx )
17181721
1719- with warnings_helper .check_warnings ():
1720- ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
1721- self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
1722- self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1723- self ._assert_context_options (ctx )
1722+ if has_tls_protocol (ssl .PROTOCOL_TLSv1 ):
1723+ with warnings_helper .check_warnings ():
1724+ ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
1725+ self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
1726+ self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1727+ self ._assert_context_options (ctx )
17241728
17251729 with warnings_helper .check_warnings ():
17261730 ctx = ssl ._create_stdlib_context (
@@ -3457,10 +3461,12 @@ def test_protocol_tlsv1_2(self):
34573461 client_options = ssl .OP_NO_TLSv1_2 )
34583462
34593463 try_protocol_combo (ssl .PROTOCOL_TLS , ssl .PROTOCOL_TLSv1_2 , 'TLSv1.2' )
3460- try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
3461- try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3462- try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
3463- try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
3464+ if has_tls_protocol (ssl .PROTOCOL_TLSv1 ):
3465+ try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
3466+ try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3467+ if has_tls_protocol (ssl .PROTOCOL_TLSv1_1 ):
3468+ try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
3469+ try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
34643470
34653471 def test_starttls (self ):
34663472 """Switching from clear text to encrypted and back again."""
0 commit comments