diff options
| author | Tobias Diaz <tobias.deb@gmail.com> | 2016-08-23 17:13:24 +0200 |
|---|---|---|
| committer | Steve Martinelli <s.martinelli@gmail.com> | 2017-01-11 05:10:06 +0000 |
| commit | a0c67b860b3c5ff6f5fbb0e406dcbc3fd7aa9f88 (patch) | |
| tree | 76d4be9a9c006fc9e9c0ac42da1cc775e71a55fe /keystoneclient/tests/unit/test_http.py | |
| parent | a71593b19e52bb4469432d682bacecfb80843d73 (diff) | |
| download | python-keystoneclient-2.3.2.tar.gz | |
Only log application/json content typemitaka-eol2.3.2stable/mitaka
This is a combination of 2 commits. The first commit's
message is:
Prevent MemoryError when logging response bodies
Response bodies are loaded into memory prior to
being logged.
Loading huge response bodies may result in a
MemoryError.
This patch proposes that only JSON and TEXT
responses be logged, i.e when the Content-Type
header is application/json or application/text.
Responses that do not include or have a different
Content-Type header will have their body omitted.
This is a sort of backport of the fix for
keystoneauth sessions, see
I93b6fff73368c4f58bdebf8566c4948b50980cee
Co-Authored-By: Samuel de Medeiros Queiroz <samueldmq@gmail.com>
Closes-bug: 1616105
Change-Id: I8f43eee3a0b35041c6cf672e476f8151cf2f8d14
(cherry-picked from: 3e56e0d7e5e1a76d806a3bc1f6d5ef9070f95771)
Only log application/json in session to start
When whitelisting content types to debug print from session we chose
application/json and application/text. application/text is not a real
mime type, text is typically text/plain.
Rather than guess at mime types only print application/json to start
with, but make it easy for additional types to be added later.
Adapted from keystoneauth: Ica5fee076cdab8b1d5167161d28af7313fad9477
Related-Bug: 1616105
Change-Id: Ieaa8fb3ea8d25e09b89498f23b70b18c0f6153f1
(cherry-picked from: 51d16fa344829aadf454faf5e0c4535a8f96a7c8)
Diffstat (limited to 'keystoneclient/tests/unit/test_http.py')
| -rw-r--r-- | keystoneclient/tests/unit/test_http.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/keystoneclient/tests/unit/test_http.py b/keystoneclient/tests/unit/test_http.py index 56f116c..6e0070a 100644 --- a/keystoneclient/tests/unit/test_http.py +++ b/keystoneclient/tests/unit/test_http.py @@ -166,22 +166,24 @@ class BasicRequestTests(utils.TestCase): self.addCleanup(self.logger.setLevel, level) def request(self, method='GET', response='Test Response', status_code=200, - url=None, **kwargs): + url=None, headers={}, **kwargs): if not url: url = self.url self.requests_mock.register_uri(method, url, text=response, - status_code=status_code) + status_code=status_code, + headers=headers) with self.deprecations.expect_deprecations_here(): - return httpclient.request(url, method, **kwargs) + return httpclient.request(url, method, headers=headers, **kwargs) def test_basic_params(self): method = 'GET' response = 'Test Response' status = 200 - self.request(method=method, status_code=status, response=response) + self.request(method=method, status_code=status, response=response, + headers={'Content-Type': 'application/json'}) self.assertEqual(self.requests_mock.last_request.method, method) @@ -209,7 +211,8 @@ class BasicRequestTests(utils.TestCase): def test_body(self): data = "BODY DATA" - self.request(response=data) + self.request(response=data, + headers={'Content-Type': 'application/json'}) logger_message = self.logger_message.getvalue() self.assertThat(logger_message, matchers.Contains('BODY:')) self.assertThat(logger_message, matchers.Contains(data)) |
