summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Martinelli <s.martinelli@gmail.com>2017-01-03 09:55:09 -0500
committerSteve Martinelli <s.martinelli@gmail.com>2017-01-09 20:06:44 +0000
commite5bc019840c2dd08a4e48fd26a23bff8d1ab644c (patch)
tree14bbdbe2e3ed6197707bc0485a88027857aa29cd
parent8f872e9a56e65ae06ef4dc561bc9fb01172d98d7 (diff)
downloadpython-keystoneclient-e5bc019840c2dd08a4e48fd26a23bff8d1ab644c.tar.gz
Do not log binary data during request
Do not log binary data during debug logging of a session. Replace the binary data with the string <binary_data> instead. sort of a backport of: I5184002f3a21c5e0ee510b21b9a7884c8dccd1e3 Change-Id: I07ddbc3967f297597542f1975004d94c490f6e6b Related-Bug: 1616105 (cherry picked from commit af770f17b705a66bd4292b2a54df46ec5fdaa12b)
-rw-r--r--keystoneclient/session.py5
-rw-r--r--keystoneclient/tests/unit/test_session.py11
2 files changed, 9 insertions, 7 deletions
diff --git a/keystoneclient/session.py b/keystoneclient/session.py
index 1e08213..cf3fe61 100644
--- a/keystoneclient/session.py
+++ b/keystoneclient/session.py
@@ -201,6 +201,11 @@ class Session(object):
% self._process_header(header))
if data:
+ if isinstance(data, six.binary_type):
+ try:
+ data = data.decode("ascii")
+ except UnicodeDecodeError:
+ data = "<binary_data>"
string_parts.append("-d '%s'" % data)
try:
logger.debug(' '.join(string_parts))
diff --git a/keystoneclient/tests/unit/test_session.py b/keystoneclient/tests/unit/test_session.py
index b72a185..499af42 100644
--- a/keystoneclient/tests/unit/test_session.py
+++ b/keystoneclient/tests/unit/test_session.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@@ -196,7 +198,7 @@ class SessionTests(utils.TestCase):
session = client_session.Session(verify=False)
body = 'RESP'
- data = u'unicode_data'
+ data = u'αβγδ'
self.stub_url('POST', text=body)
session.post(self.TEST_URL, data=data)
@@ -222,12 +224,7 @@ class SessionTests(utils.TestCase):
# raise a UnicodeDecodeError)
session.post(unicode(self.TEST_URL), data=data)
- self.assertIn("Replaced characters that could not be decoded"
- " in log output", self.logger.output)
-
- # Our data payload should have changed to
- # include the replacement char
- self.assertIn(u"-d 'my data\ufffd'", self.logger.output)
+ self.assertNotIn('my data', self.logger.output)
def test_logging_cacerts(self):
path_to_certs = '/path/to/certs'