Browse Source

Merge "Correctly Omit Response Body in Debug Mode"

tags/2.18.0^0
Jenkins 2 years ago
parent
commit
9365dbeb6d
2 changed files with 19 additions and 2 deletions
  1. 9
    2
      keystoneauth1/session.py
  2. 10
    0
      keystoneauth1/tests/unit/test_session.py

+ 9
- 2
keystoneauth1/session.py View File

@@ -366,8 +366,15 @@ class Session(object):
366 366
                 # stream of bytes and getting an unexpected MemoryError. See
367 367
                 # bug 1616105 for further details.
368 368
                 content_type = response.headers.get('content-type', None)
369
-                if content_type in _LOG_CONTENT_TYPES:
370
-                    text = self._remove_service_catalog(response.text)
369
+
370
+                # NOTE(lamt): Per [1], the Content-Type header can be of the
371
+                # form Content-Type := type "/" subtype *[";" parameter]
372
+                # [1] https://www.w3.org/Protocols/rfc1341/4_Content-Type.html
373
+                for log_type in _LOG_CONTENT_TYPES:
374
+                    if content_type is not None and content_type.startswith(
375
+                            log_type):
376
+                        text = self._remove_service_catalog(response.text)
377
+                        break
371 378
                 else:
372 379
                     text = ('Omitted, Content-Type is set to %s. Only '
373 380
                             '%s responses have their bodies logged.')

+ 10
- 0
keystoneauth1/tests/unit/test_session.py View File

@@ -292,6 +292,16 @@ class SessionTests(utils.TestCase):
292 292
         self.assertIn(body, self.logger.output)
293 293
         self.assertNotIn(OMITTED_BODY % 'application/json', self.logger.output)
294 294
 
295
+        # Content-Type is set to application/json; charset=UTF-8
296
+        body = json.dumps({'token': {'id': '...'}})
297
+        self.stub_url(
298
+            'POST', text=body,
299
+            headers={'Content-Type': 'application/json; charset=UTF-8'})
300
+        session.post(self.TEST_URL)
301
+        self.assertIn(body, self.logger.output)
302
+        self.assertNotIn(OMITTED_BODY % 'application/json; charset=UTF-8',
303
+                         self.logger.output)
304
+
295 305
     def test_logging_cacerts(self):
296 306
         path_to_certs = '/path/to/certs'
297 307
         session = client_session.Session(verify=path_to_certs)

Loading…
Cancel
Save