Merge "Mask passwords in utils.trace for func params"

This commit is contained in:
Zuul 2019-02-06 23:24:56 +00:00 committed by Gerrit Code Review
commit fe57c2cc9a
2 changed files with 26 additions and 1 deletions

View File

@ -1359,6 +1359,29 @@ class LogTracingTestCase(test.TestCase):
self.assertIn("'adminPass': '***'",
str(mock_log.debug.call_args_list[1]))
def test_utils_trace_method_with_password_in_formal_params(self):
mock_logging = self.mock_object(utils, 'logging')
mock_log = mock.Mock()
mock_log.isEnabledFor = lambda x: True
mock_logging.getLogger = mock.Mock(return_value=mock_log)
@utils.trace
def _trace_test_method(*args, **kwargs):
self.assertEqual('verybadpass',
kwargs['test_args']['data']['password'])
pass
test_args = {
'data': {
'password': 'verybadpass'
}
}
_trace_test_method(self, test_args=test_args)
self.assertEqual(2, mock_log.debug.call_count)
self.assertIn("'password': '***'",
str(mock_log.debug.call_args_list[0]))
@ddt.data(
{'total': 30.01, 'free': 28.01, 'provisioned': 2.0, 'max_ratio': 1.0,
'thin_support': False, 'thick_support': True,

View File

@ -911,7 +911,9 @@ def trace(*dec_args, **dec_kwargs):
if pass_filter:
logger.debug('==> %(func)s: call %(all_args)r',
{'func': func_name, 'all_args': all_args})
{'func': func_name,
'all_args': strutils.mask_password(
six.text_type(all_args))})
start_time = time.time() * 1000
try: