Fix wsgi/SSL/ipv6 tests for wsgi module under python 3
Previously some tests were ignored under python 3 environment, this was due to some design changes introduced by python 3.7 [1] in the SSL module of the stdlib. These changes reactivate some of them (some other are still skipped and needs further works). Indeed, when we try to use requests with SSL in a monkey patched environment we faced the following issue: ``` TypeError: wrap_socket() got an unexpected keyword argument '_context' ``` This is due to the fact that we are in a monkey patched environment where `requests` is monkey patched too. We don't need `request` for our needs. Indeed we can easily send http requests through low level socket. Our main goal is to test our wsgi server and not to test the `requests` library, and `requests` was just used to make the code more simpler. In our case we can implement a code dedicated to send request to our green server, unlock our tests and move away from this bug/side effect. These changes move away from `requests` which is badly monkey patched by eventlet [1]. Now we use monkey patched socket and ssl to request the green server which is executed in background. Low level (monkey patched) modules could help us to skirt layers that are possibly badly monkey patched on higher level modules (urllib, requests, etc...). [1] https://github.com/eventlet/eventlet/issues/526#issuecomment-482694279 [2] https://github.com/eventlet/eventlet/issues/526 Change-Id: Iacdde51d2d923bafa3263fa3dc12de8d501d471a Partial-Bug: #1482633
This commit is contained in:
parent
bfc8172942
commit
ebc2d8a42f
|
@ -266,9 +266,10 @@ class TestWSGIServer(WsgiTestCase):
|
|||
|
||||
|
||||
def requesting(host, port, ca_certs, method="POST",
|
||||
content_type="application/x-www-form-urlencoded"):
|
||||
content_type="application/x-www-form-urlencoded",
|
||||
address_familly=socket.AF_INET):
|
||||
frame = bytes("{verb} / HTTP/1.1\r\n\r\n".format(verb=method), "utf-8")
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
with socket.socket(address_familly, socket.SOCK_STREAM) as sock:
|
||||
with eventlet.wrap_ssl(sock, ca_certs=ca_certs) as wrappedSocket:
|
||||
wrappedSocket.connect((host, port))
|
||||
wrappedSocket.send(frame)
|
||||
|
@ -364,9 +365,6 @@ class TestWSGIServerWithSSL(WsgiTestCase):
|
|||
server.stop()
|
||||
server.wait()
|
||||
|
||||
@testtools.skipIf(not netutils.is_ipv6_enabled(), "no ipv6 support")
|
||||
@testtools.skip("bug/1482633: test hangs on Python 3")
|
||||
@testtools.skip("using raw IPv6 addresses with SSL certs is broken")
|
||||
def test_app_using_ipv6_and_ssl(self):
|
||||
greetings = 'Hello, World!!!'
|
||||
|
||||
|
@ -382,9 +380,14 @@ class TestWSGIServerWithSSL(WsgiTestCase):
|
|||
|
||||
server.start()
|
||||
|
||||
response = requests.get('https://[::1]:%d/' % server.port,
|
||||
verify=os.path.join(SSL_CERT_DIR, 'ca.crt'))
|
||||
self.assertEqual(greetings, response.text)
|
||||
response = requesting(
|
||||
method='GET',
|
||||
host='::1',
|
||||
port=server.port,
|
||||
ca_certs=os.path.join(SSL_CERT_DIR, 'ca.crt'),
|
||||
address_familly=socket.AF_INET6
|
||||
)
|
||||
self.assertEqual(greetings, response[-15:])
|
||||
|
||||
server.stop()
|
||||
server.wait()
|
||||
|
|
Loading…
Reference in New Issue