diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index 028946df..8a1f1721 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -62,7 +62,9 @@ class HTTPClient(object): self.session = requests.Session() self.session.headers["User-Agent"] = USER_AGENT - self.session.headers["X-Auth-Token"] = self.auth_token + + if self.auth_token: + self.session.headers["X-Auth-Token"] = self.auth_token self.timeout = float(kwargs.get('timeout', 600)) diff --git a/tests/test_http.py b/tests/test_http.py index 114481ad..31cd6d53 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -75,6 +75,22 @@ class TestClient(testtools.TestCase): self.assertTrue(http_client_object.identity_headers. get('X-Auth-Token') is None) + def test_identity_headers_and_no_token_in_session_header(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_object = http.HTTPClient(self.endpoint, **kwargs) + self.assertIsNone(http_client_object.auth_token) + self.assertNotIn('X-Auth-Token', http_client_object.session.headers) + def test_connection_refused(self): """ Should receive a CommunicationError if connection refused.