You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2014/08/21 18:14:32 UTC

[2/2] git commit: Improve URL validation, update docstring.

Improve URL validation, update docstring.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/bef5399b
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/bef5399b
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/bef5399b

Branch: refs/heads/trunk
Commit: bef5399b5bb9b539c40c3770ae28546468c6b6cc
Parents: a3a0959
Author: Tomaz Muraus <to...@apache.org>
Authored: Thu Aug 21 18:02:25 2014 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Aug 21 18:05:33 2014 +0200

----------------------------------------------------------------------
 libcloud/common/base.py          |  7 +++++--
 libcloud/httplib_ssl.py          |  2 +-
 libcloud/test/test_connection.py | 12 ++++++++++++
 3 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/bef5399b/libcloud/common/base.py
----------------------------------------------------------------------
diff --git a/libcloud/common/base.py b/libcloud/common/base.py
index 78a9a13..f559c22 100644
--- a/libcloud/common/base.py
+++ b/libcloud/common/base.py
@@ -485,9 +485,12 @@ class Connection(object):
 
     def set_http_proxy(self, proxy_url):
         """
-        Set an HTTP proxy which will be used for all the outgoing HTTP requests.
+        Set a HTTP proxy which will be used with this connection.
 
-        :param proxy_url: Proxy URL.
+        :param proxy_url: Proxy URL (e.g. http://<hostname>:<port> without
+                          authentication and
+                          http://<username>:<password>@<hostname>:<port> for
+                          basic auth authentication information.
         :type proxy_url: ``str``
         """
         self.proxy_url = proxy_url

http://git-wip-us.apache.org/repos/asf/libcloud/blob/bef5399b/libcloud/httplib_ssl.py
----------------------------------------------------------------------
diff --git a/libcloud/httplib_ssl.py b/libcloud/httplib_ssl.py
index 4497da3..104bf34 100644
--- a/libcloud/httplib_ssl.py
+++ b/libcloud/httplib_ssl.py
@@ -107,7 +107,7 @@ class LibcloudBaseConnection(object):
             username_password = netloc.split('@', 1)[0]
             split = username_password.split(':', 1)
 
-            if len(split) == 0:
+            if len(split) < 2:
                 raise ValueError('URL is in an invalid format')
 
             proxy_username, proxy_password = split[0], split[1]

http://git-wip-us.apache.org/repos/asf/libcloud/blob/bef5399b/libcloud/test/test_connection.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_connection.py b/libcloud/test/test_connection.py
index c97cfb4..821425d 100644
--- a/libcloud/test/test_connection.py
+++ b/libcloud/test/test_connection.py
@@ -59,6 +59,18 @@ class BaseConnectionClassTestCase(unittest.TestCase):
                                 conn._parse_proxy_url,
                                 proxy_url=proxy_url)
 
+        proxy_url = 'http://@127.0.0.1:3128'
+        expected_msg = 'URL is in an invalid format'
+        self.assertRaisesRegexp(ValueError, expected_msg,
+                                conn._parse_proxy_url,
+                                proxy_url=proxy_url)
+
+        proxy_url = 'http://user@127.0.0.1:3128'
+        expected_msg = 'URL is in an invalid format'
+        self.assertRaisesRegexp(ValueError, expected_msg,
+                                conn._parse_proxy_url,
+                                proxy_url=proxy_url)
+
     def test_constructor(self):
         conn = LibcloudHTTPConnection(host='localhost', port=80)
         self.assertEqual(conn.proxy_scheme, None)