Merge "Fix password masking result"
This commit is contained in:
@@ -1264,8 +1264,10 @@ class LogTracingTestCase(test.TestCase):
|
|||||||
self.assertEqual(2, mock_log.debug.call_count)
|
self.assertEqual(2, mock_log.debug.call_count)
|
||||||
|
|
||||||
def test_utils_trace_method_with_password_dict(self):
|
def test_utils_trace_method_with_password_dict(self):
|
||||||
mock_log = self.patch('cinder.utils.logging.getLogger')
|
mock_logging = self.mock_object(utils, 'logging')
|
||||||
mock_log().isEnabledFor.return_value = True
|
mock_log = mock.Mock()
|
||||||
|
mock_log.isEnabledFor = lambda x: True
|
||||||
|
mock_logging.getLogger = mock.Mock(return_value=mock_log)
|
||||||
|
|
||||||
@utils.trace_method
|
@utils.trace_method
|
||||||
def _trace_test_method(*args, **kwargs):
|
def _trace_test_method(*args, **kwargs):
|
||||||
@@ -1273,28 +1275,33 @@ class LogTracingTestCase(test.TestCase):
|
|||||||
'password': 'Now you see me'}
|
'password': 'Now you see me'}
|
||||||
|
|
||||||
utils.setup_tracing(['method'])
|
utils.setup_tracing(['method'])
|
||||||
|
|
||||||
result = _trace_test_method(self)
|
result = _trace_test_method(self)
|
||||||
|
expected_unmasked_dict = {'something': 'test',
|
||||||
|
'password': 'Now you see me'}
|
||||||
|
|
||||||
expected_masked_dict = {'password': '***', 'something': 'test'}
|
self.assertEqual(expected_unmasked_dict, result)
|
||||||
|
self.assertEqual(2, mock_log.debug.call_count)
|
||||||
self.assertEqual(expected_masked_dict, result)
|
self.assertIn("'password': '***'",
|
||||||
|
str(mock_log.debug.call_args_list[1]))
|
||||||
|
|
||||||
def test_utils_trace_method_with_password_str(self):
|
def test_utils_trace_method_with_password_str(self):
|
||||||
mock_log = self.patch('cinder.utils.logging.getLogger')
|
mock_logging = self.mock_object(utils, 'logging')
|
||||||
mock_log().isEnabledFor.return_value = True
|
mock_log = mock.Mock()
|
||||||
|
mock_log.isEnabledFor = lambda x: True
|
||||||
|
mock_logging.getLogger = mock.Mock(return_value=mock_log)
|
||||||
|
|
||||||
@utils.trace_method
|
@utils.trace_method
|
||||||
def _trace_test_method(*args, **kwargs):
|
def _trace_test_method(*args, **kwargs):
|
||||||
return "'adminPass': 'Now you see me'"
|
return "'adminPass': 'Now you see me'"
|
||||||
|
|
||||||
utils.setup_tracing(['method'])
|
utils.setup_tracing(['method'])
|
||||||
|
|
||||||
result = _trace_test_method(self)
|
result = _trace_test_method(self)
|
||||||
|
expected_unmasked_str = "'adminPass': 'Now you see me'"
|
||||||
|
|
||||||
expected_masked_str = "'adminPass': '***'"
|
self.assertEqual(expected_unmasked_str, result)
|
||||||
|
self.assertEqual(2, mock_log.debug.call_count)
|
||||||
self.assertEqual(expected_masked_str, result)
|
self.assertIn("'adminPass': '***'",
|
||||||
|
str(mock_log.debug.call_args_list[1]))
|
||||||
|
|
||||||
def test_utils_calculate_virtual_free_capacity_with_thick(self):
|
def test_utils_calculate_virtual_free_capacity_with_thick(self):
|
||||||
host_stat = {'total_capacity_gb': 30.01,
|
host_stat = {'total_capacity_gb': 30.01,
|
||||||
|
|||||||
@@ -871,14 +871,16 @@ def trace(f):
|
|||||||
total_time = int(round(time.time() * 1000)) - start_time
|
total_time = int(round(time.time() * 1000)) - start_time
|
||||||
|
|
||||||
if isinstance(result, dict):
|
if isinstance(result, dict):
|
||||||
result = strutils.mask_dict_password(result)
|
mask_result = strutils.mask_dict_password(result)
|
||||||
elif isinstance(result, six.string_types):
|
elif isinstance(result, six.string_types):
|
||||||
result = strutils.mask_password(result)
|
mask_result = strutils.mask_password(result)
|
||||||
|
else:
|
||||||
|
mask_result = result
|
||||||
|
|
||||||
logger.debug('<== %(func)s: return (%(time)dms) %(result)r',
|
logger.debug('<== %(func)s: return (%(time)dms) %(result)r',
|
||||||
{'func': func_name,
|
{'func': func_name,
|
||||||
'time': total_time,
|
'time': total_time,
|
||||||
'result': result})
|
'result': mask_result})
|
||||||
return result
|
return result
|
||||||
return trace_logging_wrapper
|
return trace_logging_wrapper
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user