@@ -610,6 +610,8 @@ def test_openssl111_deprecations(self):
610610 )
611611
612612 for protocol in protocols :
613+ if not has_tls_protocol (protocol ):
614+ continue
613615 with self .subTest (protocol = protocol ):
614616 with self .assertWarns (DeprecationWarning ) as cm :
615617 ssl .SSLContext (protocol )
@@ -619,6 +621,8 @@ def test_openssl111_deprecations(self):
619621 )
620622
621623 for version in versions :
624+ if not has_tls_version (version ):
625+ continue
622626 with self .subTest (version = version ):
623627 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
624628 with self .assertWarns (DeprecationWarning ) as cm :
@@ -934,9 +938,10 @@ class ContextTests(unittest.TestCase):
934938
935939 def test_constructor (self ):
936940 for protocol in PROTOCOLS :
937- with warnings_helper .check_warnings ():
938- ctx = ssl .SSLContext (protocol )
939- self .assertEqual (ctx .protocol , protocol )
941+ if has_tls_protocol (protocol ):
942+ with warnings_helper .check_warnings ():
943+ ctx = ssl .SSLContext (protocol )
944+ self .assertEqual (ctx .protocol , protocol )
940945 with warnings_helper .check_warnings ():
941946 ctx = ssl .SSLContext ()
942947 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS )
@@ -1081,7 +1086,7 @@ def test_min_max_version(self):
10811086 ctx .maximum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
10821087 self .assertIn (
10831088 ctx .maximum_version ,
1084- {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .SSLv3 }
1089+ {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .TLSv1_1 , ssl . TLSVersion . SSLv3 }
10851090 )
10861091
10871092 ctx .minimum_version = ssl .TLSVersion .MAXIMUM_SUPPORTED
@@ -1093,19 +1098,19 @@ def test_min_max_version(self):
10931098 with self .assertRaises (ValueError ):
10941099 ctx .minimum_version = 42
10951100
1096- ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
1097-
1098- self .assertIn (
1099- ctx .minimum_version , minimum_range
1100- )
1101- self .assertEqual (
1102- ctx .maximum_version , ssl .TLSVersion .MAXIMUM_SUPPORTED
1103- )
1104- with self .assertRaises (ValueError ):
1105- ctx .minimum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1106- with self .assertRaises (ValueError ):
1107- ctx .maximum_version = ssl .TLSVersion .TLSv1
1101+ if has_tls_protocol (ssl .PROTOCOL_TLSv1_1 ):
1102+ ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
11081103
1104+ self .assertIn (
1105+ ctx .minimum_version , minimum_range
1106+ )
1107+ self .assertEqual (
1108+ ctx .maximum_version , ssl .TLSVersion .MAXIMUM_SUPPORTED
1109+ )
1110+ with self .assertRaises (ValueError ):
1111+ ctx .minimum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1112+ with self .assertRaises (ValueError ):
1113+ ctx .maximum_version = ssl .TLSVersion .TLSv1
11091114
11101115 @unittest .skipUnless (
11111116 hasattr (ssl .SSLContext , 'security_level' ),
@@ -1502,20 +1507,19 @@ def test_create_default_context(self):
15021507 self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
15031508 self ._assert_context_options (ctx )
15041509
1505-
1506-
15071510 def test__create_stdlib_context (self ):
15081511 ctx = ssl ._create_stdlib_context ()
15091512 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS_CLIENT )
15101513 self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
15111514 self .assertFalse (ctx .check_hostname )
15121515 self ._assert_context_options (ctx )
15131516
1514- with warnings_helper .check_warnings ():
1515- ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
1516- self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
1517- self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1518- self ._assert_context_options (ctx )
1517+ if has_tls_protocol (ssl .PROTOCOL_TLSv1 ):
1518+ with warnings_helper .check_warnings ():
1519+ ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
1520+ self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
1521+ self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1522+ self ._assert_context_options (ctx )
15191523
15201524 with warnings_helper .check_warnings ():
15211525 ctx = ssl ._create_stdlib_context (
@@ -3249,10 +3253,12 @@ def test_protocol_tlsv1_2(self):
32493253 client_options = ssl .OP_NO_TLSv1_2 )
32503254
32513255 try_protocol_combo (ssl .PROTOCOL_TLS , ssl .PROTOCOL_TLSv1_2 , 'TLSv1.2' )
3252- try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
3253- try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3254- try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
3255- try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
3256+ if has_tls_protocol (ssl .PROTOCOL_TLSv1 ):
3257+ try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
3258+ try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3259+ if has_tls_protocol (ssl .PROTOCOL_TLSv1_1 ):
3260+ try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
3261+ try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
32563262
32573263 def test_starttls (self ):
32583264 """Switching from clear text to encrypted and back again."""
0 commit comments