Send identity_headers through the wire

Change I09f70eee3e2777f52ce040296015d41649c2586a, introduced a bug where
the identity_headers are not added to the request headers anymore
causing the former to be completely ignored and useless.

This patch fixes that issue by restoring the previous code. A new test
has been added to avoid regressions.

Closes-bug: #1394965
Change-Id: I1b1633636448398cf3f41217f1d671b43ebd9946
This commit is contained in:
Flavio Percoco
2014-11-21 13:55:43 +01:00
committed by Flavio Percoco
parent 3b6754a8cc
commit 5080d10099
2 changed files with 30 additions and 0 deletions

View File

@@ -157,6 +157,10 @@ class HTTPClient(object):
headers = kwargs.pop("headers", {})
headers = headers and copy.deepcopy(headers) or {}
if self.identity_headers:
for k, v in six.iteritems(self.identity_headers):
headers.setdefault(k, v)
# Default Content-Type is octet-stream
content_type = headers.get('Content-Type', 'application/octet-stream')

View File

@@ -14,6 +14,7 @@
# under the License.
import json
import mock
from mox3 import mox
import requests
import six
@@ -91,6 +92,31 @@ class TestClient(testtools.TestCase):
self.assertIsNone(http_client_object.auth_token)
self.assertNotIn('X-Auth-Token', http_client_object.session.headers)
def test_identity_headers_are_passed(self):
# Tests that if token or X-Auth-Token are not provided in the kwargs
# when creating the http client, the session headers don't contain
# the X-Auth-Token key.
identity_headers = {
'X-User-Id': 'user',
'X-Tenant-Id': 'tenant',
'X-Roles': 'roles',
'X-Identity-Status': 'Confirmed',
'X-Service-Catalog': 'service_catalog',
}
kwargs = {'identity_headers': identity_headers}
http_client = http.HTTPClient(self.endpoint, **kwargs)
def check_headers(*args, **kwargs):
headers = kwargs.get('headers')
for k, v in six.iteritems(identity_headers):
self.assertEqual(v, headers[k])
return utils.FakeResponse({}, six.StringIO('{}'))
with mock.patch.object(http_client.session, 'request') as mreq:
mreq.side_effect = check_headers
http_client.get('http://example.com:9292/v1/images/my-image')
def test_connection_refused(self):
"""
Should receive a CommunicationError if connection refused.