Commit 5a8899ae authored by Jason Madden's avatar Jason Madden

Fix the pywsgi SSLContext tests on Python 2.7

Don't define them on 2.7.8.

Add a changelog entry.

Fixes #904
parent 4bead9db
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
on non-Windows systems for ease of development on BSD systems where on non-Windows systems for ease of development on BSD systems where
``make`` is BSD make and ``gmake`` is GNU make (gevent requires GNU ``make`` is BSD make and ``gmake`` is GNU make (gevent requires GNU
make). See :issue:`888`. make). See :issue:`888`.
- Let :class:`gevent.server.StreamServer` accept an ``SSLContext`` on
Python versions that support it. Added in :pr:`904` by Arcadiy Ivanov.
1.2a1 (Oct 27, 2016) 1.2a1 (Oct 27, 2016)
==================== ====================
......
...@@ -741,11 +741,24 @@ class HttpsTestCase(TestCase): ...@@ -741,11 +741,24 @@ class HttpsTestCase(TestCase):
start_response('200 OK', [('Content-Type', 'text/plain')]) start_response('200 OK', [('Content-Type', 'text/plain')])
return [environ['wsgi.input'].read(10)] return [environ['wsgi.input'].read(10)]
try:
from ssl import create_default_context as _
except ImportError:
HAVE_SSLCONTEXT = False
else:
HAVE_SSLCONTEXT = True
class HttpsSslContextTestCase(HttpsTestCase): class HttpsSslContextTestCase(HttpsTestCase):
def init_server(self, application): def init_server(self, application):
from ssl import create_default_context # On 2.7, our certs don't line up with hostname.
context = create_default_context() # If we just use create_default_context as-is, we get
# `ValueError: check_hostname requires server_hostname`.
# If we set check_hostname to False, we get
# `SSLError: [SSL: PEER_DID_NOT_RETURN_A_CERTIFICATE] peer did not return a certificate`
# (Neither of which happens in Python 3.) But the unverified context
# works both places. See also test___example_servers.py
from ssl import _create_unverified_context
context = _create_unverified_context()
context.load_cert_chain(certfile=self.certfile, keyfile=self.keyfile) context.load_cert_chain(certfile=self.certfile, keyfile=self.keyfile)
self.server = pywsgi.WSGIServer(('127.0.0.1', 0), application, ssl_context=context) self.server = pywsgi.WSGIServer(('127.0.0.1', 0), application, ssl_context=context)
...@@ -761,7 +774,8 @@ class TestHttps(HttpsTestCase): ...@@ -761,7 +774,8 @@ class TestHttps(HttpsTestCase):
result = self.urlopen() result = self.urlopen()
self.assertEquals(result.body, '') self.assertEquals(result.body, '')
class TestHttpsWithContext(HttpsSslContextTestCase, TestHttps): if HAVE_SSLCONTEXT:
class TestHttpsWithContext(HttpsSslContextTestCase, TestHttps):
pass pass
class TestInternational(TestCase): class TestInternational(TestCase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment