Release 1.1.0

* protect against http_proxy confusing interceptors
* pep8
This commit is contained in:
Chris Dent 2016-01-22 14:41:46 +00:00
parent 05b6772a0a
commit 16e18ad7db
9 changed files with 29 additions and 17 deletions

View File

@ -64,7 +64,7 @@ def test_app_error():
def test_http_not_intercepted():
with InstalledApp(wsgi_app.raises_app, host=HOST, port=80) as app:
with InstalledApp(wsgi_app.raises_app, host=HOST, port=80):
http_client = http_lib.HTTPConnection('google.com')
http_client.request('GET', '/')
response = http_client.getresponse()

View File

@ -44,7 +44,8 @@ def test_bogus_domain():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80):
py.test.raises(
gaierror,
'httplib2_intercept.HTTP_WSGIInterceptorWithTimeout("_nonexistant_domain_").connect()')
'httplib2_intercept.HTTP_WSGIInterceptorWithTimeout('
'"_nonexistant_domain_").connect()')
def test_proxy_handling():
@ -61,14 +62,16 @@ def test_proxy_handling():
def test_https():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
http = httplib2.Http()
resp, content = http.request('https://some_hopefully_nonexistant_domain:443/')
resp, content = http.request(
'https://some_hopefully_nonexistant_domain:443/')
assert app.success()
def test_https_default_port():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
http = httplib2.Http()
resp, content = http.request('https://some_hopefully_nonexistant_domain/')
resp, content = http.request(
'https://some_hopefully_nonexistant_domain/')
assert app.success()
environ = app.get_internals()

View File

@ -19,7 +19,7 @@ def setup_module(module):
def teardown_module(module):
intercept.uninstall_intercept()
module.intercept.uninstall_intercept()
def test_simple_request():

View File

@ -67,12 +67,12 @@ def test_app_error():
def test_http_not_intercepted():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80) as app:
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80):
response = url_lib.urlopen('http://google.com/')
assert 200 <= int(response.code) < 400
def test_https_not_intercepted():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443):
response = url_lib.urlopen('https://google.com/')
assert 200 <= int(response.code) < 400

View File

@ -41,7 +41,10 @@ def test_https_in_environ():
def test_more_interesting():
expected_uri = '/%E4%B8%96%E4%B8%8A%E5%8E%9F%E4%BE%86%E9%82%84%E6%9C%89%E3%80%8C%E7%BE%9A%E7%89%9B%E3%80%8D%E9%80%99%E7%A8%AE%E5%8B%95%E7%89%A9%EF%BC%81%2Fbarney?bar=baz%20zoom'
expected_uri = ('/%E4%B8%96%E4%B8%8A%E5%8E%9F%E4%BE%86%E9%82%84%E6'
'%9C%89%E3%80%8C%E7%BE%9A%E7%89%9B%E3%80%8D%E9%80%99'
'%E7%A8%AE%E5%8B%95%E7%89%A9%EF%BC%81%2Fbarney'
'?bar=baz%20zoom')
with InstalledApp(wsgi_app.more_interesting_app, host=HOST) as app:
http = httplib2.Http()
resp, content = http.request(
@ -58,9 +61,11 @@ def test_more_interesting():
# Do the rather painful wsgi encoding dance.
if sys.version_info[0] > 2:
assert internal_env['PATH_INFO'].encode('latin-1').decode('UTF-8') == expected_path_info
assert internal_env['PATH_INFO'].encode('latin-1').decode(
'UTF-8') == expected_path_info
else:
assert internal_env['PATH_INFO'].decode('UTF-8') == expected_path_info.decode('UTF-8')
assert internal_env['PATH_INFO'].decode(
'UTF-8') == expected_path_info.decode('UTF-8')
def test_script_name():

View File

@ -51,7 +51,7 @@ application; ``script_name`` becomes ``SCRIPT_NAME`` in the WSGI app's
environment, if set.
Note also that if ``http_proxy`` or ``https_proxy`` is set in the environment
this can cause difficulties with some of the intercepted libraries. If
this can cause difficulties with some of the intercepted libraries. If
requests or urllib is being used, these will raise an exception if one of
those variables is set.
@ -120,7 +120,7 @@ Additional documentation is available on `Read The Docs`_.
"""
from __future__ import print_function
__version__ = '1.0.1'
__version__ = '1.1.0'
import sys
@ -604,8 +604,9 @@ class WSGI_HTTPSConnection(HTTPSConnection, WSGI_HTTPConnection):
self._context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
self._context.options |= ssl.OP_NO_SSLv2
if not hasattr(self, 'check_hostname'):
self._check_hostname = (self._context.verify_mode
!= ssl.CERT_NONE)
self._check_hostname = (
self._context.verify_mode != ssl.CERT_NONE
)
else:
self._check_hostname = self.check_hostname
except (ImportError, AttributeError):

View File

@ -1,4 +1,5 @@
"""Intercept HTTP connections that use `httplib2 <https://github.com/jcgregorio/httplib2>`_.
"""Intercept HTTP connections that use
`httplib2 <https://github.com/jcgregorio/httplib2>`_.
"""
import sys

View File

@ -1,4 +1,5 @@
"""Intercept HTTP connections that use `requests <http://docs.python-requests.org/en/latest/>`_.
"""Intercept HTTP connections that use
`requests <http://docs.python-requests.org/en/latest/>`_.
"""
import os

View File

@ -1,4 +1,5 @@
"""Intercept HTTP connections that use urllib.request (Py3) aka urllib2 (Python 2).
"""Intercept HTTP connections that use urllib.request (Python 3)
aka urllib2 (Python 2).
"""
import os