Commit e4e3d173 authored by Jason Madden's avatar Jason Madden

Fix #801

Make _sslgte279.py preserve the create_connection function from
gevent.socket instead of from stdlib ssl.
parent 93e4352a
...@@ -95,6 +95,10 @@ Other Changes ...@@ -95,6 +95,10 @@ Other Changes
chunked, potentially reducing overhead for large responses. chunked, potentially reducing overhead for large responses.
- :class:`~.PriorityQueue` now ensures that an initial items list is a - :class:`~.PriorityQueue` now ensures that an initial items list is a
valid heap. Fixed in :pr:`793` by X.C.Dong. valid heap. Fixed in :pr:`793` by X.C.Dong.
- On Python 2.7.9 and above (more generally, when the SSL backport is
present in Python 2), :func:`gevent.ssl.get_server_certificate`
would raise a :exc:`ValueError` if the system wasn't monkey-patched.
Reported in :issue:`801` by Gleb Dubovik.
1.1.1 (Apr 4, 2016) 1.1.1 (Apr 4, 2016)
=================== ===================
......
...@@ -20,6 +20,7 @@ _ssl = __ssl__._ssl # pylint:disable=no-member ...@@ -20,6 +20,7 @@ _ssl = __ssl__._ssl # pylint:disable=no-member
import errno import errno
from gevent._socket2 import socket from gevent._socket2 import socket
from gevent.socket import timeout_default from gevent.socket import timeout_default
from gevent.socket import create_connection
from gevent.socket import error as socket_error from gevent.socket import error as socket_error
from gevent.socket import timeout as _socket_timeout from gevent.socket import timeout as _socket_timeout
from gevent._compat import PYPY from gevent._compat import PYPY
...@@ -39,8 +40,8 @@ __implements__ = [ ...@@ -39,8 +40,8 @@ __implements__ = [
# Import all symbols from Python's ssl.py, except those that we are implementing # Import all symbols from Python's ssl.py, except those that we are implementing
# and "private" symbols. # and "private" symbols.
__imports__ = copy_globals(__ssl__, globals(), __imports__ = copy_globals(__ssl__, globals(),
# SSLSocket *must* subclass gevent.socket.socket; see issue 597 # SSLSocket *must* subclass gevent.socket.socket; see issue 597 and 801
names_to_ignore=__implements__ + ['socket'], names_to_ignore=__implements__ + ['socket', 'create_connection'],
dunder_names_to_keep=()) dunder_names_to_keep=())
try: try:
......
-----BEGIN CERTIFICATE-----
MIICYzCCAcwCCQD5jx1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ew/0D6/R1+2rT8xwdGQ/Nt31q98WwkqLEjxctlbKPd
J2PLIUomf0955BhhFH4JoSwjiHJQ6uishY7srjQQDX/Dxdi5wZAyxYCIVW/kAA9N
/u2s75hSD3s/rqAwOZ182DwAPIqJc4KQoYzvlKERSMDT1PJhAkEA5SUFsiSzBEMX
FyZ++ZMMs1vHrTu5oTK7WHznh9lk7dvsnp9BoUPqhiu8iJ7Q23zj0u5asz2czu11
nnczXgU6XwJBAORM5Ib4I7nAsoUWn9wDiTwVQeE+D9P1ac9p7EHm7XXuf8o2irRZ
wYYfpXXsjk496YfyQFcQRMk0tU0gegCP7hECQFWRWqwoajUoPIInnPjjwbVki48U
I4CfqjgkBG3Fb5wnKRgezmpDK1vJD1FRRRsBay4EVhhi5KCdKfPv/V2ZxC8CQQCu
U5SxBytofJ8UhxkcTErvaR/8GYLGi//21GAGVop+YdaMlydE3cCrZODYcgCb+CSp
nS7KDG8p4KiMMz9VzJGxAkEAv85K6Sa3H8g9h7LwopBZ5tFNZUaFWo7lEP7DDMH0
eckZTb1JVpyT/8zrDtsis4WlV9zVkVHxkIaad503BjqvEQ==
-----END RSA PRIVATE KEY-----
...@@ -84,7 +84,7 @@ class TestCase(greentest.TestCase): ...@@ -84,7 +84,7 @@ class TestCase(greentest.TestCase):
sock.listen(5) sock.listen(5)
return sock return sock
def makefile(self, timeout=_DEFAULT_SOCKET_TIMEOUT, bufsize=1): def get_server_host_port_family(self):
server_host = self.server.server_host server_host = self.server.server_host
if not server_host or server_host == '::': if not server_host or server_host == '::':
server_host = 'localhost' server_host = 'localhost'
...@@ -94,10 +94,15 @@ class TestCase(greentest.TestCase): ...@@ -94,10 +94,15 @@ class TestCase(greentest.TestCase):
# server deletes socket when closed # server deletes socket when closed
family = socket.AF_INET family = socket.AF_INET
return server_host, self.server.server_port, family
def makefile(self, timeout=_DEFAULT_SOCKET_TIMEOUT, bufsize=1):
server_host, server_port, family = self.get_server_host_port_family()
sock = socket.socket(family=family) sock = socket.socket(family=family)
try: try:
sock.connect((server_host, self.server.server_port)) sock.connect((server_host, server_port))
except Exception as e: except Exception:
# avoid ResourceWarning under Py3 # avoid ResourceWarning under Py3
sock.close() sock.close()
raise raise
...@@ -184,8 +189,11 @@ class TestCase(greentest.TestCase): ...@@ -184,8 +189,11 @@ class TestCase(greentest.TestCase):
os.system('sudo netstat -anp | grep %s' % os.getpid()) os.system('sudo netstat -anp | grep %s' % os.getpid())
print('^^^^^') print('^^^^^')
def _create_server(self):
return self.ServerSubClass(('', 0))
def init_server(self): def init_server(self):
self.server = self.ServerSubClass(('', 0)) self.server = self._create_server()
self.server.start() self.server.start()
gevent.sleep(0.01) gevent.sleep(0.01)
...@@ -314,7 +322,7 @@ class TestDefaultSpawn(TestCase): ...@@ -314,7 +322,7 @@ class TestDefaultSpawn(TestCase):
self.stop_server() self.stop_server()
def init_server(self): def init_server(self):
self.server = self.ServerSubClass(('', 0)) self.server = self._create_server()
self.server.start() self.server.start()
gevent.sleep(0.01) gevent.sleep(0.01)
...@@ -438,6 +446,33 @@ if hasattr(socket, 'ssl'): ...@@ -438,6 +446,33 @@ if hasattr(socket, 'ssl'):
listener = ssl(listener) listener = ssl(listener)
self.assertRaises(TypeError, self.ServerSubClass, listener) self.assertRaises(TypeError, self.ServerSubClass, listener)
try:
__import__('ssl')
except ImportError:
pass
else:
class TestSSLGetCertificate(TestCase):
def _create_server(self):
return self.ServerSubClass(('', 0),
keyfile='server.key',
certfile='server.crt')
def get_spawn(self):
return gevent.spawn
def test_certificate(self):
# Issue 801
from gevent import monkey, ssl
# only broken if *not* monkey patched
self.assertFalse(monkey.is_module_patched('ssl'))
self.assertFalse(monkey.is_module_patched('socket'))
self.init_server()
server_host, server_port, _family = self.get_server_host_port_family()
ssl.get_server_certificate((server_host, server_port))
# test non-socket.error exception in accept call: fatal # test non-socket.error exception in accept call: fatal
# test error in spawn(): non-fatal # test error in spawn(): non-fatal
......
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