Skip to content

Commit

Permalink
Merge "Do not log binary data during request"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jan 8, 2017
2 parents 272f60d + af770f1 commit 1112abe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions keystoneclient/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ def _http_log_request(self, url, method=None, data=None,
% 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))
Expand Down
11 changes: 4 additions & 7 deletions keystoneclient/tests/unit/test_session.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -239,7 +241,7 @@ def test_unicode_data_in_debug_output(self):
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)

Expand All @@ -264,12 +266,7 @@ def test_binary_data_not_in_debug_output(self):
# 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'
Expand Down

0 comments on commit 1112abe

Please sign in to comment.