44import unittest
55import unittest .mock
66from test import support
7- from test .support import socket_helper
7+ from test .support import socket_helper , warnings_helper
88import socket
99import select
1010import time
@@ -1129,8 +1129,12 @@ class ContextTests(unittest.TestCase):
11291129
11301130 def test_constructor (self ):
11311131 for protocol in PROTOCOLS :
1132- ssl .SSLContext (protocol )
1133- ctx = ssl .SSLContext ()
1132+ if has_tls_protocol (protocol ):
1133+ with warnings_helper .check_warnings ():
1134+ ctx = ssl .SSLContext (protocol )
1135+ self .assertEqual (ctx .protocol , protocol )
1136+ with warnings_helper .check_warnings ():
1137+ ctx = ssl .SSLContext ()
11341138 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS )
11351139 self .assertRaises (ValueError , ssl .SSLContext , - 1 )
11361140 self .assertRaises (ValueError , ssl .SSLContext , 42 )
@@ -1281,7 +1285,7 @@ def test_min_max_version(self):
12811285 ctx .maximum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
12821286 self .assertIn (
12831287 ctx .maximum_version ,
1284- {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .SSLv3 }
1288+ {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .TLSv1_1 , ssl . TLSVersion . SSLv3 }
12851289 )
12861290
12871291 ctx .minimum_version = ssl .TLSVersion .MAXIMUM_SUPPORTED
@@ -1293,19 +1297,19 @@ def test_min_max_version(self):
12931297 with self .assertRaises (ValueError ):
12941298 ctx .minimum_version = 42
12951299
1296- ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
1297-
1298- self .assertIn (
1299- ctx .minimum_version , minimum_range
1300- )
1301- self .assertEqual (
1302- ctx .maximum_version , ssl .TLSVersion .MAXIMUM_SUPPORTED
1303- )
1304- with self .assertRaises (ValueError ):
1305- ctx .minimum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1306- with self .assertRaises (ValueError ):
1307- ctx .maximum_version = ssl .TLSVersion .TLSv1
1300+ if has_tls_protocol (ssl .PROTOCOL_TLSv1_1 ):
1301+ ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
13081302
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
13091313
13101314 @unittest .skipUnless (have_verify_flags (),
13111315 "verify_flags need OpenSSL > 0.9.8" )
@@ -1692,10 +1696,12 @@ def test__create_stdlib_context(self):
16921696 self .assertFalse (ctx .check_hostname )
16931697 self ._assert_context_options (ctx )
16941698
1695- ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
1696- self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
1697- self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1698- self ._assert_context_options (ctx )
1699+ if has_tls_protocol (ssl .PROTOCOL_TLSv1 ):
1700+ with warnings_helper .check_warnings ():
1701+ ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
1702+ self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
1703+ self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
1704+ self ._assert_context_options (ctx )
16991705
17001706 ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 ,
17011707 cert_reqs = ssl .CERT_REQUIRED ,
@@ -3411,10 +3417,12 @@ def test_protocol_tlsv1_2(self):
34113417 client_options = ssl .OP_NO_TLSv1_2 )
34123418
34133419 try_protocol_combo (ssl .PROTOCOL_TLS , ssl .PROTOCOL_TLSv1_2 , 'TLSv1.2' )
3414- try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
3415- try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3416- try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
3417- try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
3420+ if has_tls_protocol (ssl .PROTOCOL_TLSv1 ):
3421+ try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
3422+ try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3423+ if has_tls_protocol (ssl .PROTOCOL_TLSv1_1 ):
3424+ try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
3425+ try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
34183426
34193427 def test_starttls (self ):
34203428 """Switching from clear text to encrypted and back again."""
0 commit comments