diff options
author | Joel Wright <joel.wright@sohonet.com> | 2016-02-25 17:13:35 +0000 |
---|---|---|
committer | Joel Wright <joel.wright@sohonet.com> | 2016-02-26 11:36:45 +0000 |
commit | 46d817828082105a69d4da53fef2f2fbefc54809 (patch) | |
tree | 017638b3977b74350b95cd3aa28ff5b00a93c993 | |
parent | ee905477ac6fad7c43e875d7e52b22a494ef3d6f (diff) | |
download | python-swiftclient-46d817828082105a69d4da53fef2f2fbefc54809.tar.gz |
Fix test for redacting sensitive data in client.http_log()
The test should have included utf8 encoded unicode data to
test that encoded unicode data stored in headers was parsed
correctly.
Also fixes the docstring for swiftclient.safe_value()
Change-Id: Id0def0b3af7a364f1257cc22f67b71c0cc5d8479
-rw-r--r-- | swiftclient/client.py | 2 | ||||
-rw-r--r-- | tests/unit/test_swiftclient.py | 23 |
2 files changed, 15 insertions, 10 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py index 8375fed..f65d4bb 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -103,7 +103,7 @@ def safe_value(name, value): :param name: Header name :param value: Header value - :return: Safe (header, value) pair + :return: Safe header value """ if name.lower() in LOGGER_SENSITIVE_HEADERS: prefix_length = logger_settings.get('reveal_sensitive_prefix', 16) diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py index ae144e2..331e804 100644 --- a/tests/unit/test_swiftclient.py +++ b/tests/unit/test_swiftclient.py @@ -2191,23 +2191,26 @@ class TestLogging(MockHttpTest): def test_redact_token(self): with mock.patch('swiftclient.client.logger.debug') as mock_log: token_value = 'tkee96b40a8ca44fc5ad72ec5a7c90d9b' + token_encoded = token_value.encode('utf8') unicode_token_value = (u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' u'\u5929\u7a7a\u4e2d\u7684\u4e4c') + unicode_token_encoded = unicode_token_value.encode('utf8') set_cookie_value = 'X-Auth-Token=%s' % token_value + set_cookie_encoded = set_cookie_value.encode('utf8') c.http_log( ['GET'], {'headers': { - 'X-Auth-Token': token_value, - 'X-Storage-Token': unicode_token_value + 'X-Auth-Token': token_encoded, + 'X-Storage-Token': unicode_token_encoded }}, MockHttpResponse( status=200, headers={ - 'X-Auth-Token': token_value, - 'X-Storage-Token': unicode_token_value, + 'X-Auth-Token': token_encoded, + 'X-Storage-Token': unicode_token_encoded, 'Etag': b'mock_etag', - 'Set-Cookie': set_cookie_value + 'Set-Cookie': set_cookie_encoded } ), '' @@ -2230,21 +2233,23 @@ class TestLogging(MockHttpTest): def test_show_token(self): with mock.patch('swiftclient.client.logger.debug') as mock_log: token_value = 'tkee96b40a8ca44fc5ad72ec5a7c90d9b' + token_encoded = token_value.encode('utf8') unicode_token_value = (u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' u'\u5929\u7a7a\u4e2d\u7684\u4e4c') c.logger_settings['redact_sensitive_headers'] = False + unicode_token_encoded = unicode_token_value.encode('utf8') c.http_log( ['GET'], {'headers': { - 'X-Auth-Token': token_value, - 'X-Storage-Token': unicode_token_value + 'X-Auth-Token': token_encoded, + 'X-Storage-Token': unicode_token_encoded }}, MockHttpResponse( status=200, headers=[ - ('X-Auth-Token', token_value), - ('X-Storage-Token', unicode_token_value), + ('X-Auth-Token', token_encoded), + ('X-Storage-Token', unicode_token_encoded), ('Etag', b'mock_etag') ] ), |