diff options
author | Daniel Lindsley <daniel@toastdriven.com> | 2013-07-23 14:13:12 -0700 |
---|---|---|
committer | Daniel Lindsley <daniel@toastdriven.com> | 2013-07-23 14:13:12 -0700 |
commit | aaef5a94eb3d688b054b5bd2d5c890570ea61605 (patch) | |
tree | 3958703a99d3a812cac39f05ee0fb1e6c448bd9a | |
parent | e76180d1c51160d2e5d214df3a30542feee20cdd (diff) | |
parent | ee15920af7871e58ccba0381d4c487a6b77d101f (diff) | |
download | boto-aaef5a94eb3d688b054b5bd2d5c890570ea61605.tar.gz |
Merge remote-tracking branch 'holzman/issue/1600' into develop
-rw-r--r-- | boto/connection.py | 23 | ||||
-rw-r--r-- | tests/unit/test_connection.py | 44 |
2 files changed, 65 insertions, 2 deletions
diff --git a/boto/connection.py b/boto/connection.py index 375a9ca7..a66dba8b 100644 --- a/boto/connection.py +++ b/boto/connection.py @@ -673,6 +673,8 @@ class AWSAuthConnection(object): print "http_proxy environment variable does not specify " \ "a port, using default" self.proxy_port = self.port + + self.no_proxy = os.environ.get('no_proxy', '') or os.environ.get('NO_PROXY', '') self.use_proxy = (self.proxy != None) def get_http_connection(self, host, is_secure): @@ -682,8 +684,25 @@ class AWSAuthConnection(object): else: return self.new_http_connection(host, is_secure) + def skip_proxy(self, host): + if not self.no_proxy: + return False + + if self.no_proxy == "*": + return True + + hostonly = host + hostonly = host.split(':')[0] + + for name in self.no_proxy.split(','): + if name and (hostonly.endswith(name) or host.endswith(name)): + return True + + return False + def new_http_connection(self, host, is_secure): - if self.use_proxy and not is_secure: + if self.use_proxy and not is_secure and \ + not self.skip_proxy(host): host = '%s:%d' % (self.proxy, int(self.proxy_port)) if host is None: host = self.server_name() @@ -691,7 +710,7 @@ class AWSAuthConnection(object): boto.log.debug( 'establishing HTTPS connection: host=%s, kwargs=%s', host, self.http_connection_kwargs) - if self.use_proxy: + if self.use_proxy and not self.skip_proxy(host): connection = self.proxy_ssl(host, is_secure and 443 or 80) elif self.https_connection_factory: connection = self.https_connection_factory(host) diff --git a/tests/unit/test_connection.py b/tests/unit/test_connection.py index d71587fc..35dd7259 100644 --- a/tests/unit/test_connection.py +++ b/tests/unit/test_connection.py @@ -19,6 +19,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # +import os import urlparse from tests.unit import unittest from httpretty import HTTPretty @@ -134,6 +135,49 @@ class TestAWSQueryConnectionSimple(TestAWSQueryConnection): self.assertEqual(conn.host, 'mockservice.cc-zone-1.amazonaws.com') + def test_query_connection_noproxy(self): + HTTPretty.register_uri(HTTPretty.POST, + 'https://%s/' % self.region.endpoint, + json.dumps({'test': 'secure'}), + content_type='application/json') + + os.environ['no_proxy'] = self.region.endpoint + + conn = self.region.connect(aws_access_key_id='access_key', + aws_secret_access_key='secret', + proxy="NON_EXISTENT_HOSTNAME", + proxy_port="3128") + + resp = conn.make_request('myCmd', + {'par1': 'foo', 'par2': 'baz'}, + "/", + "POST") + del os.environ['no_proxy'] + args = urlparse.parse_qs(HTTPretty.last_request.body) + self.assertEqual(args['AWSAccessKeyId'], ['access_key']) + + def test_query_connection_noproxy_nosecure(self): + HTTPretty.register_uri(HTTPretty.POST, + 'https://%s/' % self.region.endpoint, + json.dumps({'test': 'insecure'}), + content_type='application/json') + + os.environ['no_proxy'] = self.region.endpoint + + conn = self.region.connect(aws_access_key_id='access_key', + aws_secret_access_key='secret', + proxy="NON_EXISTENT_HOSTNAME", + proxy_port="3128", + is_secure = False) + + resp = conn.make_request('myCmd', + {'par1': 'foo', 'par2': 'baz'}, + "/", + "POST") + del os.environ['no_proxy'] + args = urlparse.parse_qs(HTTPretty.last_request.body) + self.assertEqual(args['AWSAccessKeyId'], ['access_key']) + def test_single_command(self): HTTPretty.register_uri(HTTPretty.POST, 'https://%s/' % self.region.endpoint, |