Browse Source

Merge "Only include response body if there's a response"

tags/5.1.0
Zuul 1 year ago
parent
commit
cd919f5d1f

+ 4
- 3
keystonemiddleware/auth_token/_identity.py View File

@@ -234,9 +234,10 @@ class IdentityServer(object):
234 234
             raise ksm_exceptions.ServiceError(msg)
235 235
         except ksa_exceptions.HttpError as e:
236 236
             self._LOG.error(
237
-                'Bad response code while validating token: %s',
238
-                e.http_status)
239
-            self._LOG.warning('Identity response: %s', e.response.text)
237
+                'Bad response code while validating token: %s %s',
238
+                e.http_status, e.message)
239
+            if hasattr(e.response, 'text'):
240
+                self._LOG.warning('Identity response: %s', e.response.text)
240 241
             msg = _('Failed to fetch token data from identity server')
241 242
             raise ksm_exceptions.ServiceError(msg)
242 243
         else:

+ 19
- 0
keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py View File

@@ -98,6 +98,7 @@ VERSION_LIST_v3 = fixture.DiscoveryList(href=BASE_URI)
98 98
 VERSION_LIST_v2 = fixture.DiscoveryList(v3=False, href=BASE_URI)
99 99
 
100 100
 ERROR_TOKEN = '7ae290c2a06244c4b41692eb4e9225f2'
101
+TIMEOUT_TOKEN = '4ed1c5e53beee59458adcf8261a8cae2'
101 102
 
102 103
 
103 104
 def cleanup_revoked_file(filename):
@@ -1083,6 +1084,12 @@ class CommonAuthTokenMiddlewareTest(object):
1083 1084
 
1084 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 1093
     def test_nocatalog(self):
1087 1094
         conf = {
1088 1095
             'include_service_catalog': 'False'
@@ -1545,6 +1552,11 @@ def network_error_response(request, context):
1545 1552
     raise ksa_exceptions.ConnectFailure("Network connection refused.")
1546 1553
 
1547 1554
 
1555
+def request_timeout_response(request, context):
1556
+    raise ksa_exceptions.RequestTimeout(
1557
+        "Request to https://host/token/path timed out")
1558
+
1559
+
1548 1560
 class v2AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
1549 1561
                                 CommonAuthTokenMiddlewareTest,
1550 1562
                                 testresources.ResourcedTestCase):
@@ -1618,6 +1630,9 @@ class v2AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
1618 1630
         url = '%s/v2.0/tokens/%s' % (BASE_URI, ERROR_TOKEN)
1619 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 1636
         self.set_middleware()
1622 1637
 
1623 1638
     def assert_unscoped_default_tenant_auto_scopes(self, token):
@@ -1824,6 +1839,8 @@ class v3AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
1824 1839
         if token_id == ERROR_TOKEN:
1825 1840
             msg = "Network connection refused."
1826 1841
             raise ksa_exceptions.ConnectFailure(msg)
1842
+        elif token_id == TIMEOUT_TOKEN:
1843
+            request_timeout_response(request, context)
1827 1844
 
1828 1845
         try:
1829 1846
             response = self.examples.JSON_TOKEN_RESPONSES[token_id]
@@ -2372,6 +2389,8 @@ class v3CompositeAuthTests(BaseAuthTokenMiddlewareTest,
2372 2389
         if token_id == ERROR_TOKEN:
2373 2390
             msg = "Network connection refused."
2374 2391
             raise ksc_exceptions.ConnectionRefused(msg)
2392
+        elif token_id == TIMEOUT_TOKEN:
2393
+            request_timeout_response(request, context)
2375 2394
 
2376 2395
         try:
2377 2396
             response = self.examples.JSON_TOKEN_RESPONSES[token_id]

Loading…
Cancel
Save