1
+ import platform
1
2
import socket
2
3
import ssl
4
+ import sys
3
5
4
6
import pytest
5
7
from six .moves import urllib
@@ -73,17 +75,25 @@ def test_not_trusted_ca():
73
75
pass
74
76
75
77
76
- ssl_context_accept_version = hasattr (tests .ssl_context (), "maximum_version" ) and hasattr (
77
- tests .ssl_context (), "minimum_version"
78
+ ssl_context_accept_version = (
79
+ hasattr (tests .ssl_context (), "maximum_version" )
80
+ and hasattr (tests .ssl_context (), "minimum_version" )
81
+ and not (platform .python_implementation ().lower () == "pypy" and sys .version_info < (3 ,))
82
+ )
83
+ tls_minmax_versions = (
84
+ (None , "TLSv1_2" , ssl .TLSVersion .TLSv1_2 )
85
+ # TODO remove pypy2 workaround `and hasattr` clause
86
+ if ssl_context_accept_version and hasattr (ssl , "TLSVersion" ) else (None ,)
78
87
)
79
88
80
89
81
90
@pytest .mark .skipif (not ssl_context_accept_version , reason = "ssl doesn't support TLS min/max" )
82
91
@pytest .mark .parametrize ("attr" , ("maximum_version" , "minimum_version" ))
83
- @pytest .mark .parametrize ("version" , ( None , "TLSv1_2" , ssl . TLSVersion . TLSv1_2 ) if ssl_context_accept_version else ( None ,) )
92
+ @pytest .mark .parametrize ("version" , tls_minmax_versions )
84
93
def test_set_tls_version (attr , version ):
94
+ ctx = tests .ssl_context ()
85
95
# We expect failure on Python < 3.7 or OpenSSL < 1.1
86
- expect_success = hasattr (ssl . SSLContext () , attr )
96
+ expect_success = hasattr (ctx , attr )
87
97
kwargs = {"tls_" + attr : version }
88
98
http = httplib2 .Http (** kwargs )
89
99
try :
@@ -94,10 +104,7 @@ def test_set_tls_version(attr, version):
94
104
assert expect_success
95
105
96
106
97
- @pytest .mark .skipif (
98
- not hasattr (tests .ssl_context (), "maximum_version" ),
99
- reason = "ssl doesn't support TLS min/max" ,
100
- )
107
+ @pytest .mark .skipif (not ssl_context_accept_version , reason = "ssl doesn't support TLS min/max" )
101
108
def test_max_tls_version ():
102
109
http = httplib2 .Http (ca_certs = tests .CA_CERTS , tls_maximum_version = "TLSv1_2" )
103
110
with tests .server_const_http (tls = True ) as uri :
0 commit comments