diff options
author | Zuul <zuul@review.openstack.org> | 2018-07-18 03:43:01 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2018-07-18 03:43:01 +0000 |
commit | 7f8397091f63488f314f4dea49d83d6947f9fc27 (patch) | |
tree | f8e2a57f1d58276f6ec6e2d86eedd204da4f4bea /oslo_utils | |
parent | 0812f94a2367cf16d8379a6432f1a60a46c89616 (diff) | |
parent | 4e2abfeec4ef6fa9d7830b56a49091dec489a376 (diff) | |
download | oslo-utils-7f8397091f63488f314f4dea49d83d6947f9fc27.tar.gz |
Merge "Handle non-string keys appropriately"3.36.4
Diffstat (limited to 'oslo_utils')
-rw-r--r-- | oslo_utils/strutils.py | 16 | ||||
-rw-r--r-- | oslo_utils/tests/test_strutils.py | 7 |
2 files changed, 18 insertions, 5 deletions
diff --git a/oslo_utils/strutils.py b/oslo_utils/strutils.py index c7d0f55..922ad22 100644 --- a/oslo_utils/strutils.py +++ b/oslo_utils/strutils.py @@ -403,15 +403,21 @@ def mask_dict_password(dictionary, secret="***"): # nosec continue # NOTE(jlvillal): Check to see if anything in the dictionary 'key' # contains any key specified in _SANITIZE_KEYS. - for sani_key in _SANITIZE_KEYS: - if sani_key in k: - out[k] = secret - break - else: + k_matched = False + if isinstance(k, six.string_types): + for sani_key in _SANITIZE_KEYS: + if sani_key in k: + out[k] = secret + k_matched = True + break + if not k_matched: # We did not find a match for the key name in the # _SANITIZE_KEYS, so we fall through to here if isinstance(v, six.string_types): out[k] = mask_password(v, secret=secret) + else: + # Just leave it alone. + out[k] = v return out diff --git a/oslo_utils/tests/test_strutils.py b/oslo_utils/tests/test_strutils.py index af1faf1..301b619 100644 --- a/oslo_utils/tests/test_strutils.py +++ b/oslo_utils/tests/test_strutils.py @@ -660,6 +660,13 @@ class MaskDictionaryPasswordTestCase(test_base.BaseTestCase): self.assertEqual(expected, 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): payload = {'somekey': 'test = cmd --password my\xe9\x80\x80pass'} expected = {'somekey': 'test = cmd --password ***'} |