4
4
import unittest
5
5
import unittest .mock
6
6
from test import support
7
- from test .support import socket_helper
7
+ from test .support import socket_helper , warnings_helper
8
8
import socket
9
9
import select
10
10
import time
@@ -1129,8 +1129,12 @@ class ContextTests(unittest.TestCase):
1129
1129
1130
1130
def test_constructor (self ):
1131
1131
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 ()
1134
1138
self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS )
1135
1139
self .assertRaises (ValueError , ssl .SSLContext , - 1 )
1136
1140
self .assertRaises (ValueError , ssl .SSLContext , 42 )
@@ -1281,7 +1285,7 @@ def test_min_max_version(self):
1281
1285
ctx .maximum_version = ssl .TLSVersion .MINIMUM_SUPPORTED
1282
1286
self .assertIn (
1283
1287
ctx .maximum_version ,
1284
- {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .SSLv3 }
1288
+ {ssl .TLSVersion .TLSv1 , ssl .TLSVersion .TLSv1_1 , ssl . TLSVersion . SSLv3 }
1285
1289
)
1286
1290
1287
1291
ctx .minimum_version = ssl .TLSVersion .MAXIMUM_SUPPORTED
@@ -1293,19 +1297,19 @@ def test_min_max_version(self):
1293
1297
with self .assertRaises (ValueError ):
1294
1298
ctx .minimum_version = 42
1295
1299
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 )
1308
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
1309
1313
1310
1314
@unittest .skipUnless (have_verify_flags (),
1311
1315
"verify_flags need OpenSSL > 0.9.8" )
@@ -1692,10 +1696,12 @@ def test__create_stdlib_context(self):
1692
1696
self .assertFalse (ctx .check_hostname )
1693
1697
self ._assert_context_options (ctx )
1694
1698
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 )
1699
1705
1700
1706
ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 ,
1701
1707
cert_reqs = ssl .CERT_REQUIRED ,
@@ -3411,10 +3417,12 @@ def test_protocol_tlsv1_2(self):
3411
3417
client_options = ssl .OP_NO_TLSv1_2 )
3412
3418
3413
3419
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 )
3418
3426
3419
3427
def test_starttls (self ):
3420
3428
"""Switching from clear text to encrypted and back again."""
0 commit comments