Merge "Handle non-string keys appropriately"
This commit is contained in:
commit
7f8397091f
@ -403,15 +403,21 @@ def mask_dict_password(dictionary, secret="***"): # nosec
|
|||||||
continue
|
continue
|
||||||
# NOTE(jlvillal): Check to see if anything in the dictionary 'key'
|
# NOTE(jlvillal): Check to see if anything in the dictionary 'key'
|
||||||
# contains any key specified in _SANITIZE_KEYS.
|
# contains any key specified in _SANITIZE_KEYS.
|
||||||
for sani_key in _SANITIZE_KEYS:
|
k_matched = False
|
||||||
if sani_key in k:
|
if isinstance(k, six.string_types):
|
||||||
out[k] = secret
|
for sani_key in _SANITIZE_KEYS:
|
||||||
break
|
if sani_key in k:
|
||||||
else:
|
out[k] = secret
|
||||||
|
k_matched = True
|
||||||
|
break
|
||||||
|
if not k_matched:
|
||||||
# We did not find a match for the key name in the
|
# We did not find a match for the key name in the
|
||||||
# _SANITIZE_KEYS, so we fall through to here
|
# _SANITIZE_KEYS, so we fall through to here
|
||||||
if isinstance(v, six.string_types):
|
if isinstance(v, six.string_types):
|
||||||
out[k] = mask_password(v, secret=secret)
|
out[k] = mask_password(v, secret=secret)
|
||||||
|
else:
|
||||||
|
# Just leave it alone.
|
||||||
|
out[k] = v
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
@ -660,6 +660,13 @@ class MaskDictionaryPasswordTestCase(test_base.BaseTestCase):
|
|||||||
self.assertEqual(expected,
|
self.assertEqual(expected,
|
||||||
strutils.mask_dict_password(payload))
|
strutils.mask_dict_password(payload))
|
||||||
|
|
||||||
|
def test_do_an_int(self):
|
||||||
|
payload = {}
|
||||||
|
payload[1] = 2
|
||||||
|
expected = payload.copy()
|
||||||
|
self.assertEqual(expected,
|
||||||
|
strutils.mask_dict_password(payload))
|
||||||
|
|
||||||
def test_mask_values(self):
|
def test_mask_values(self):
|
||||||
payload = {'somekey': 'test = cmd --password my\xe9\x80\x80pass'}
|
payload = {'somekey': 'test = cmd --password my\xe9\x80\x80pass'}
|
||||||
expected = {'somekey': 'test = cmd --password ***'}
|
expected = {'somekey': 'test = cmd --password ***'}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user