@@ -610,6 +610,8 @@ def test_openssl111_deprecations(self):
610
610
)
611
611
612
612
for protocol in protocols :
613
+ if not has_tls_protocol (protocol ):
614
+ continue
613
615
with self .subTest (protocol = protocol ):
614
616
with self .assertWarns (DeprecationWarning ) as cm :
615
617
ssl .SSLContext (protocol )
@@ -619,6 +621,8 @@ def test_openssl111_deprecations(self):
619
621
)
620
622
621
623
for version in versions :
624
+ if not has_tls_version (version ):
625
+ continue
622
626
with self .subTest (version = version ):
623
627
ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
624
628
with self .assertWarns (DeprecationWarning ) as cm :
@@ -934,9 +938,10 @@ class ContextTests(unittest.TestCase):
934
938
935
939
def test_constructor (self ):
936
940
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 )
940
945
with warnings_helper .check_warnings ():
941
946
ctx = ssl .SSLContext ()
942
947
self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS )
@@ -1081,7 +1086,7 @@ def test_min_max_version(self):
1081
1086
ctx .maximum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1082
1087
self .assertIn (
1083
1088
ctx .maximum_version ,
1084
- {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .SSLv3 }
1089
+ {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .TLSv1_1 , ssl . TLSVersion . SSLv3 }
1085
1090
)
1086
1091
1087
1092
ctx .minimum_version = ssl .TLSVersion .MAXIMUM_SUPPORTED
@@ -1093,19 +1098,19 @@ def test_min_max_version(self):
1093
1098
with self .assertRaises (ValueError ):
1094
1099
ctx .minimum_version = 42
1095
1100
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 )
1108
1103
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
1109
1114
1110
1115
@unittest .skipUnless (
1111
1116
hasattr (ssl .SSLContext , 'security_level' ),
@@ -1502,20 +1507,19 @@ def test_create_default_context(self):
1502
1507
self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1503
1508
self ._assert_context_options (ctx )
1504
1509
1505
-
1506
-
1507
1510
def test__create_stdlib_context (self ):
1508
1511
ctx = ssl ._create_stdlib_context ()
1509
1512
self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS_CLIENT )
1510
1513
self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1511
1514
self .assertFalse (ctx .check_hostname )
1512
1515
self ._assert_context_options (ctx )
1513
1516
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 )
1519
1523
1520
1524
with warnings_helper .check_warnings ():
1521
1525
ctx = ssl ._create_stdlib_context (
@@ -3249,10 +3253,12 @@ def test_protocol_tlsv1_2(self):
3249
3253
client_options = ssl .OP_NO_TLSv1_2 )
3250
3254
3251
3255
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 )
3256
3262
3257
3263
def test_starttls (self ):
3258
3264
"""Switching from clear text to encrypted and back again."""
0 commit comments