summaryrefslogtreecommitdiff
path: root/ceilometerclient
diff options
context:
space:
mode:
authorMehdi Abaakouk <mehdi.abaakouk@enovance.com>2014-01-31 17:16:30 +0100
committerGerrit Code Review <review@openstack.org>2014-02-13 09:51:19 +0000
commit85c80f0fc5f02ed406d662ddb390d71bd32ee34e (patch)
treedff494a9fbeea5d6b6a9aad6b5fd53deb165c081 /ceilometerclient
parent0eed59f4b5579625ae082d8d46ec24cdf538620e (diff)
downloadpython-ceilometerclient-85c80f0fc5f02ed406d662ddb390d71bd32ee34e.tar.gz
Ensure url sent to proxy don't have redundant /
When a proxy is set, the url requested to the proxy have a double // after the domain, but for ceilometer this kind of url is not valid. So, this patch ensures the url have only one / Closes-bug: #1274981 Change-Id: Id6fc5cf7ab7a3866bc23af7102785a9cede593fe
Diffstat (limited to 'ceilometerclient')
-rw-r--r--ceilometerclient/common/http.py3
-rw-r--r--ceilometerclient/tests/test_http.py26
2 files changed, 28 insertions, 1 deletions
diff --git a/ceilometerclient/common/http.py b/ceilometerclient/common/http.py
index d57bf0e..bb650b4 100644
--- a/ceilometerclient/common/http.py
+++ b/ceilometerclient/common/http.py
@@ -143,7 +143,8 @@ class HTTPClient(object):
try:
if self.proxy_url:
- conn_url = self.endpoint + self._make_connection_url(url)
+ conn_url = (self.endpoint.rstrip('/') +
+ self._make_connection_url(url))
else:
conn_url = self._make_connection_url(url)
conn.request(method, conn_url, **kwargs)
diff --git a/ceilometerclient/tests/test_http.py b/ceilometerclient/tests/test_http.py
index 2c6767c..0c3c091 100644
--- a/ceilometerclient/tests/test_http.py
+++ b/ceilometerclient/tests/test_http.py
@@ -13,6 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
+import contextlib
+import mock
+
from ceilometerclient.common import http
from ceilometerclient.tests import utils
@@ -44,6 +47,29 @@ class HttpClientTest(utils.BaseTestCase):
client = http.HTTPClient(self.url)
self.assertIsNotNone(client.get_connection())
+ def test_url_generation_with_proxy(self):
+ client = http.HTTPClient(self.url)
+ client.proxy_url = "http://localhost:3128/"
+ conn = mock.MagicMock()
+ with contextlib.nested(
+ mock.patch.object(client, 'get_connection'),
+ mock.patch.object(client, 'auth_token')
+ ) as (get_conn, auth_token):
+ conn.request.side_effect = Exception("stop")
+ get_conn.return_value = conn
+ auth_token.return_value = "token"
+ try:
+ client._http_request('/v1/resources', 'GET')
+ except Exception:
+ pass
+ conn.request.assert_called_once_with('GET', (self.url.rstrip('/') +
+ '/v1/resources'),
+ headers=mock.ANY)
+
class HttpsClientTest(HttpClientTest):
url = 'https://localhost'
+
+
+class HttpEndingSlashClientTest(HttpClientTest):
+ url = 'http://localhost/'