summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDougal Matthews <dougal@dougalmatthews.com>2019-11-21 10:09:20 +0000
committerCédric Jeanneret (Tengu) <cjeanner@redhat.com>2019-11-22 12:45:08 +0000
commit39870f6807e07811bd5d98d82bb8799feeca73d6 (patch)
tree9aa0329266f930051b128849a3c8956bcd967686
parent05ab20cca22e2a15ec14881ac03aee7efb7fcf11 (diff)
downloadoslo-utils-39870f6807e07811bd5d98d82bb8799feeca73d6.tar.gz
Verify the sanitize keys are lowered3.41.4
This change is preventative to ensure any keys added in the future are all lowercase. Change-Id: Ib843fe59a80b081d9d0193717ff5a980e22c81b0 (cherry picked from commit 577da7f00b36f23a95c0fa9beb6c4c702ad82f92)
-rw-r--r--oslo_utils/strutils.py6
-rw-r--r--oslo_utils/tests/test_strutils.py6
2 files changed, 9 insertions, 3 deletions
diff --git a/oslo_utils/strutils.py b/oslo_utils/strutils.py
index 40c45dd..b7ad5b8 100644
--- a/oslo_utils/strutils.py
+++ b/oslo_utils/strutils.py
@@ -55,7 +55,7 @@ SLUGIFY_HYPHENATE_RE = re.compile(r"[-\s]+")
# NOTE(flaper87): The following globals are used by `mask_password` and
-# `mask_dict_password`
+# `mask_dict_password`. They must all be lowercase.
_SANITIZE_KEYS = ['adminpass', 'admin_pass', 'password', 'admin_password',
'auth_token', 'new_pass', 'auth_password', 'secret_uuid',
'secret', 'sys_pswd', 'token', 'configdrive',
@@ -337,7 +337,7 @@ def mask_password(message, secret="***"): # nosec
# specified in _SANITIZE_KEYS, if not then just return the message since
# we don't have to mask any passwords.
for key in _SANITIZE_KEYS:
- if key.lower() in message.lower():
+ if key in message.lower():
for pattern in _SANITIZE_PATTERNS_2[key]:
message = re.sub(pattern, substitute2, message)
for pattern in _SANITIZE_PATTERNS_1[key]:
@@ -413,7 +413,7 @@ def mask_dict_password(dictionary, secret="***"): # nosec
k_matched = False
if isinstance(k, six.string_types):
for sani_key in _SANITIZE_KEYS:
- if sani_key.lower() in k.lower():
+ if sani_key in k.lower():
out[k] = secret
k_matched = True
break
diff --git a/oslo_utils/tests/test_strutils.py b/oslo_utils/tests/test_strutils.py
index 7ed8c54..25e974c 100644
--- a/oslo_utils/tests/test_strutils.py
+++ b/oslo_utils/tests/test_strutils.py
@@ -296,6 +296,12 @@ StringToBytesTest.generate_scenarios()
class MaskPasswordTestCase(test_base.BaseTestCase):
+ def test_sanitize_keys(self):
+
+ lowered = [k.lower() for k in strutils._SANITIZE_KEYS]
+ message = "The _SANITIZE_KEYS must all be lowercase."
+ self.assertEqual(strutils._SANITIZE_KEYS, lowered, message)
+
def test_json(self):
# Test 'adminPass' w/o spaces
payload = """{'adminPass':'TL0EfN33'}"""