Ignore non-object settings scrub inputs (#1645)
This commit is contained in:
parent
b409b20940
commit
d1309f3bd6
2 changed files with 7 additions and 0 deletions
|
|
@ -47,4 +47,6 @@ def _scrub_value(key, value):
|
|||
|
||||
def scrub_settings(settings: dict) -> dict:
|
||||
"""Return a copy of ``settings`` with secret-shaped values masked (deep)."""
|
||||
if not isinstance(settings, dict):
|
||||
return {}
|
||||
return {k: _scrub_value(k, v) for k, v in (settings or {}).items()}
|
||||
|
|
|
|||
|
|
@ -59,3 +59,8 @@ def test_empty_and_nonstring_secret_values_untouched():
|
|||
def test_exact_name_matches():
|
||||
out = scrub_settings({"password": "p", "token": "t", "secret": "s", "apikey": "a", "key": "k"})
|
||||
assert all(v == "" for v in out.values()), out
|
||||
|
||||
|
||||
def test_non_object_settings_return_empty_mapping():
|
||||
assert scrub_settings(["not", "settings"]) == {}
|
||||
assert scrub_settings("not settings") == {}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue