Ignore http_proxy while connecting to test WSGI server

urllib2.urlopen uses $http_proxy/$HTTP_PROXY environment variables by
default.  If set (and pointing to a remote host), then the WSGI tests
that spin up a local server and connect to it using
http://127.0.0.1:$port/ instead connect to $port *on the proxy*,
and (hopefully) fail.

This change uses urllib2 in a way that ignores proxy settings.

Change-Id: I4d94fcc06925d0c947345a07ae20352e1898e46d
Closes-Bug: #1356665
This commit is contained in:
Angus Lees 2014-07-31 15:27:18 +10:00
parent 009725f9b3
commit 0fde41a90c

View File

@ -35,6 +35,11 @@ TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', 'var'))
def open_no_proxy(*args, **kwargs):
opener = urllib2.build_opener(urllib2.ProxyHandler({}))
return opener.open(*args, **kwargs)
class TestWSGIServer(base.BaseTestCase):
"""WSGI server tests."""
@ -120,7 +125,8 @@ class TestWSGIServer(base.BaseTestCase):
server = wsgi.Server("test_app")
server.start(hello_world, 0, host="127.0.0.1")
response = urllib2.urlopen('http://127.0.0.1:%d/' % server.port)
response = open_no_proxy('http://127.0.0.1:%d/' % server.port)
self.assertEqual(greetings, response.read())
server.stop()
@ -1088,7 +1094,8 @@ class TestWSGIServerWithSSL(base.BaseTestCase):
server = wsgi.Server("test_app")
server.start(hello_world, 0, host="127.0.0.1")
response = urllib2.urlopen('https://127.0.0.1:%d/' % server.port)
response = open_no_proxy('https://127.0.0.1:%d/' % server.port)
self.assertEqual(greetings, response.read())
server.stop()
@ -1107,7 +1114,8 @@ class TestWSGIServerWithSSL(base.BaseTestCase):
server = wsgi.Server("test_app")
server.start(hello_world, 0, host="127.0.0.1")
response = urllib2.urlopen('https://127.0.0.1:%d/' % server.port)
response = open_no_proxy('https://127.0.0.1:%d/' % server.port)
self.assertEqual(greetings, response.read())
server.stop()
@ -1128,7 +1136,8 @@ class TestWSGIServerWithSSL(base.BaseTestCase):
server = wsgi.Server("test_app")
server.start(hello_world, 0, host="::1")
response = urllib2.urlopen('https://[::1]:%d/' % server.port)
response = open_no_proxy('https://[::1]:%d/' % server.port)
self.assertEqual(greetings, response.read())
server.stop()