summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-04-20 21:27:33 +0000
committerGerrit Code Review <review@openstack.org>2018-04-20 21:27:33 +0000
commitcd919f5d1fa3864c3fb5a4b80cdf7723a2a95285 (patch)
tree56433041f2098a6108caed60171b61d0731c82ed
parent2d080a9956f55c8100f98ed910b7e4d5f340be0d (diff)
parente503fbd9412d94be43962af3b3ef7067d7f7f49b (diff)
Merge "Only include response body if there's a response"
-rw-r--r--keystonemiddleware/auth_token/_identity.py7
-rw-r--r--keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py19
2 files changed, 23 insertions, 3 deletions
diff --git a/keystonemiddleware/auth_token/_identity.py b/keystonemiddleware/auth_token/_identity.py
index b7f2eff..c07eb45 100644
--- a/keystonemiddleware/auth_token/_identity.py
+++ b/keystonemiddleware/auth_token/_identity.py
@@ -234,9 +234,10 @@ class IdentityServer(object):
234 raise ksm_exceptions.ServiceError(msg) 234 raise ksm_exceptions.ServiceError(msg)
235 except ksa_exceptions.HttpError as e: 235 except ksa_exceptions.HttpError as e:
236 self._LOG.error( 236 self._LOG.error(
237 'Bad response code while validating token: %s', 237 'Bad response code while validating token: %s %s',
238 e.http_status) 238 e.http_status, e.message)
239 self._LOG.warning('Identity response: %s', e.response.text) 239 if hasattr(e.response, 'text'):
240 self._LOG.warning('Identity response: %s', e.response.text)
240 msg = _('Failed to fetch token data from identity server') 241 msg = _('Failed to fetch token data from identity server')
241 raise ksm_exceptions.ServiceError(msg) 242 raise ksm_exceptions.ServiceError(msg)
242 else: 243 else:
diff --git a/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py b/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py
index 9eb86c0..fdda195 100644
--- a/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py
+++ b/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py
@@ -98,6 +98,7 @@ VERSION_LIST_v3 = fixture.DiscoveryList(href=BASE_URI)
98VERSION_LIST_v2 = fixture.DiscoveryList(v3=False, href=BASE_URI) 98VERSION_LIST_v2 = fixture.DiscoveryList(v3=False, href=BASE_URI)
99 99
100ERROR_TOKEN = '7ae290c2a06244c4b41692eb4e9225f2' 100ERROR_TOKEN = '7ae290c2a06244c4b41692eb4e9225f2'
101TIMEOUT_TOKEN = '4ed1c5e53beee59458adcf8261a8cae2'
101 102
102 103
103def cleanup_revoked_file(filename): 104def cleanup_revoked_file(filename):
@@ -1083,6 +1084,12 @@ class CommonAuthTokenMiddlewareTest(object):
1083 1084
1084 self.assertEqual(mock_obj.call_count, times_retry) 1085 self.assertEqual(mock_obj.call_count, times_retry)
1085 1086
1087 def test_request_timeout(self):
1088 self.call_middleware(headers={'X-Auth-Token': TIMEOUT_TOKEN},
1089 expected_status=503)
1090 self.assertIsNone(self._get_cached_token(TIMEOUT_TOKEN))
1091 self.assert_valid_last_url(TIMEOUT_TOKEN)
1092
1086 def test_nocatalog(self): 1093 def test_nocatalog(self):
1087 conf = { 1094 conf = {
1088 'include_service_catalog': 'False' 1095 'include_service_catalog': 'False'
@@ -1545,6 +1552,11 @@ def network_error_response(request, context):
1545 raise ksa_exceptions.ConnectFailure("Network connection refused.") 1552 raise ksa_exceptions.ConnectFailure("Network connection refused.")
1546 1553
1547 1554
1555def request_timeout_response(request, context):
1556 raise ksa_exceptions.RequestTimeout(
1557 "Request to https://host/token/path timed out")
1558
1559
1548class v2AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest, 1560class v2AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
1549 CommonAuthTokenMiddlewareTest, 1561 CommonAuthTokenMiddlewareTest,
1550 testresources.ResourcedTestCase): 1562 testresources.ResourcedTestCase):
@@ -1618,6 +1630,9 @@ class v2AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
1618 url = '%s/v2.0/tokens/%s' % (BASE_URI, ERROR_TOKEN) 1630 url = '%s/v2.0/tokens/%s' % (BASE_URI, ERROR_TOKEN)
1619 self.requests_mock.get(url, text=network_error_response) 1631 self.requests_mock.get(url, text=network_error_response)
1620 1632
1633 url = '%s/v2.0/tokens/%s' % (BASE_URI, TIMEOUT_TOKEN)
1634 self.requests_mock.get(url, text=request_timeout_response)
1635
1621 self.set_middleware() 1636 self.set_middleware()
1622 1637
1623 def assert_unscoped_default_tenant_auto_scopes(self, token): 1638 def assert_unscoped_default_tenant_auto_scopes(self, token):
@@ -1824,6 +1839,8 @@ class v3AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
1824 if token_id == ERROR_TOKEN: 1839 if token_id == ERROR_TOKEN:
1825 msg = "Network connection refused." 1840 msg = "Network connection refused."
1826 raise ksa_exceptions.ConnectFailure(msg) 1841 raise ksa_exceptions.ConnectFailure(msg)
1842 elif token_id == TIMEOUT_TOKEN:
1843 request_timeout_response(request, context)
1827 1844
1828 try: 1845 try:
1829 response = self.examples.JSON_TOKEN_RESPONSES[token_id] 1846 response = self.examples.JSON_TOKEN_RESPONSES[token_id]
@@ -2372,6 +2389,8 @@ class v3CompositeAuthTests(BaseAuthTokenMiddlewareTest,
2372 if token_id == ERROR_TOKEN: 2389 if token_id == ERROR_TOKEN:
2373 msg = "Network connection refused." 2390 msg = "Network connection refused."
2374 raise ksc_exceptions.ConnectionRefused(msg) 2391 raise ksc_exceptions.ConnectionRefused(msg)
2392 elif token_id == TIMEOUT_TOKEN:
2393 request_timeout_response(request, context)
2375 2394
2376 try: 2395 try:
2377 response = self.examples.JSON_TOKEN_RESPONSES[token_id] 2396 response = self.examples.JSON_TOKEN_RESPONSES[token_id]