@@ -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
635
with self .assertWarns (DeprecationWarning ) as cm :
@@ -1140,9 +1144,10 @@ class ContextTests(unittest.TestCase):
1140
1144
1141
1145
def test_constructor (self ):
1142
1146
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 )
1146
1151
with warnings_helper .check_warnings ():
1147
1152
ctx = ssl .SSLContext ()
1148
1153
self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS )
@@ -1287,7 +1292,7 @@ def test_min_max_version(self):
1287
1292
ctx .maximum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1288
1293
self .assertIn (
1289
1294
ctx .maximum_version ,
1290
- {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .SSLv3 }
1295
+ {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .TLSv1_1 , ssl . TLSVersion . SSLv3 }
1291
1296
)
1292
1297
1293
1298
ctx .minimum_version = ssl .TLSVersion .MAXIMUM_SUPPORTED
@@ -1299,19 +1304,19 @@ def test_min_max_version(self):
1299
1304
with self .assertRaises (ValueError ):
1300
1305
ctx .minimum_version = 42
1301
1306
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 )
1314
1309
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
1315
1320
1316
1321
@unittest .skipUnless (
1317
1322
hasattr (ssl .SSLContext , 'security_level' ),
@@ -1707,20 +1712,19 @@ def test_create_default_context(self):
1707
1712
self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1708
1713
self ._assert_context_options (ctx )
1709
1714
1710
-
1711
-
1712
1715
def test__create_stdlib_context (self ):
1713
1716
ctx = ssl ._create_stdlib_context ()
1714
1717
self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS_CLIENT )
1715
1718
self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1716
1719
self .assertFalse (ctx .check_hostname )
1717
1720
self ._assert_context_options (ctx )
1718
1721
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 )
1724
1728
1725
1729
with warnings_helper .check_warnings ():
1726
1730
ctx = ssl ._create_stdlib_context (
@@ -3457,10 +3461,12 @@ def test_protocol_tlsv1_2(self):
3457
3461
client_options = ssl .OP_NO_TLSv1_2 )
3458
3462
3459
3463
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 )
3464
3470
3465
3471
def test_starttls (self ):
3466
3472
"""Switching from clear text to encrypted and back again."""
0 commit comments