@@ -617,6 +617,8 @@ def test_openssl111_deprecations(self):
617
617
)
618
618
619
619
for protocol in protocols :
620
+ if not has_tls_protocol (protocol ):
621
+ continue
620
622
with self .subTest (protocol = protocol ):
621
623
with self .assertWarns (DeprecationWarning ) as cm :
622
624
ssl .SSLContext (protocol )
@@ -626,6 +628,8 @@ def test_openssl111_deprecations(self):
626
628
)
627
629
628
630
for version in versions :
631
+ if not has_tls_version (version ):
632
+ continue
629
633
with self .subTest (version = version ):
630
634
ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
631
<
10000
code>635 with self .assertWarns (DeprecationWarning ) as cm :
@@ -1139,9 +1143,10 @@ class ContextTests(unittest.TestCase):
1139
1143
1140
1144
def test_constructor (self ):
1141
1145
for protocol in PROTOCOLS :
1142
- with warnings_helper .check_warnings ():
1143
- ctx = ssl .SSLContext (protocol )
1144
- self .assertEqual (ctx .protocol , protocol )
1146
+ if has_tls_protocol (protocol ):
1147
+ with warnings_helper .check_warnings ():
1148
+ ctx = ssl .SSLContext (protocol )
1149
+ self .assertEqual (ctx .protocol , protocol )
1145
1150
with warnings_helper .check_warnings ():
1146
1151
ctx = ssl .SSLContext ()
1147
1152
self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS )
@@ -1286,7 +1291,7 @@ def test_min_max_version(self):
1286
1291
ctx .maximum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1287
1292
self .assertIn (
1288
1293
ctx .maximum_version ,
1289
- {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .SSLv3 }
1294
+ {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .TLSv1_1 , ssl . TLSVersion . SSLv3 }
1290
1295
)
1291
1296
1292
1297
ctx .minimum_version = ssl .TLSVersion .MAXIMUM_SUPPORTED
@@ -1298,19 +1303,19 @@ def test_min_max_version(self):
1298
1303
with self .assertRaises (ValueError ):
1299
1304
ctx .minimum_version = 42
1300
1305
1301
- ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
1302
-
1303
- self .assertIn (
1304
- ctx .minimum_version , minimum_range
1305
- )
1306
- self .assertEqual (
1307
- ctx .maximum_version , ssl .TLSVersion .MAXIMUM_SUPPORTED
1308
- )
1309
- with self .assertRaises (ValueError ):
1310
- ctx .minimum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1311
- with self .assertRaises (ValueError ):
1312
- ctx .maximum_version = ssl .TLSVersion .TLSv1
1306
+ if has_tls_protocol (ssl .PROTOCOL_TLSv1_1 ):
1307
+ ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
1313
1308
1309
+ self .assertIn (
1310
+ ctx .minimum_version , minimum_range
1311
+ )
1312
+ self .assertEqual (
1313
+ ctx .maximum_version , ssl .TLSVersion .MAXIMUM_SUPPORTED
1314
+ )
1315
+ with self .assertRaises (ValueError ):
1316
+ ctx .minimum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1317
+ with self .assertRaises (ValueError ):
1318
+ ctx .maximum_version = ssl .TLSVersion .TLSv1
1314
1319
1315
1320
@unittest .skipUnless (
1316
1321
hasattr (ssl .SSLContext , 'security_level' ),
@@ -1706,20 +1711,19 @@ def test_create_default_context(self):
1706
1711
self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1707
1712
self ._assert_context_options (ctx )
1708
1713
1709
-
1710
-
1711
1714
def test__create_stdlib_context (self ):
1712
1715
ctx = ssl ._create_stdlib_context ()
1713
1716
self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS_CLIENT )
1714
1717
self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1715
1718
self .assertFalse (ctx .check_hostname )
1716
1719
self ._assert_context_options (ctx )
1717
1720
1718
- with warnings_helper .check_warnings ():
1719
- ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
1720
- self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
1721
- self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1722
- self ._assert_context_options (ctx )
1721
+ if has_tls_protocol (ssl .PROTOCOL_TLSv1 ):
1722
+ with warnings_helper .check_warnings ():
1723
+ ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
1724
+ self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
1725
+ self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1726
+ self ._assert_context_options (ctx )
1723
1727
1724
1728
with warnings_helper .check_warnings ():
1725
1729
ctx = ssl ._create_stdlib_context (
@@ -3464,10 +3468,12 @@ def test_protocol_tlsv1_2(self):
3464
3468
client_options = ssl .OP_NO_TLSv1_2 )
3465
3469
3466
3470
try_protocol_combo (ssl .PROTOCOL_TLS , ssl .PROTOCOL_TLSv1_2 , 'TLSv1.2' )
3467
- try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
3468
- try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3469
- try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
3470
- try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
3471
+ if has_tls_protocol (ssl .PROTOCOL_TLSv1 ):
3472
+ try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
3473
+ try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3474
+ if has_tls_protocol (ssl .PROTOCOL_TLSv1_1 ):
3475
+ try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
3476
+ try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
3471
3477
3472
3478
def test_starttls (self ):
3473
3479
"""Switching from clear text to encrypted and back again."""
0 commit comments