fix: don't auto-populate non-existing secret entries
This commit is contained in:
@@ -37,8 +37,10 @@ def sanitize_config(config: Config, *, show_sensitive: bool = False) -> Config:
|
|||||||
nested_config = config
|
nested_config = config
|
||||||
for nested_key in nested_keys[:-1]:
|
for nested_key in nested_keys[:-1]:
|
||||||
nested_config = nested_config.get(nested_key, {})
|
nested_config = nested_config.get(nested_key, {})
|
||||||
nested_config[nested_keys[-1]] = "REDACTED"
|
if nested_keys[-1] in nested_config:
|
||||||
|
nested_config[nested_keys[-1]] = "REDACTED"
|
||||||
else:
|
else:
|
||||||
config[key] = "REDACTED"
|
if key in config:
|
||||||
|
config[key] = "REDACTED"
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|||||||
@@ -1653,9 +1653,12 @@ def test_sanitize_config(default_conf_usdt):
|
|||||||
res = sanitize_config(default_conf_usdt)
|
res = sanitize_config(default_conf_usdt)
|
||||||
# Didn't modify original dict
|
# Didn't modify original dict
|
||||||
assert default_conf_usdt["exchange"]["key"] != "REDACTED"
|
assert default_conf_usdt["exchange"]["key"] != "REDACTED"
|
||||||
|
assert "accountId" not in default_conf_usdt["exchange"]
|
||||||
|
|
||||||
assert res["exchange"]["key"] == "REDACTED"
|
assert res["exchange"]["key"] == "REDACTED"
|
||||||
assert res["exchange"]["secret"] == "REDACTED"
|
assert res["exchange"]["secret"] == "REDACTED"
|
||||||
|
# Didn't add a non-existing key
|
||||||
|
assert "accountId" not in res["exchange"]
|
||||||
|
|
||||||
res = sanitize_config(default_conf_usdt, show_sensitive=True)
|
res = sanitize_config(default_conf_usdt, show_sensitive=True)
|
||||||
assert res["exchange"]["key"] == default_conf_usdt["exchange"]["key"]
|
assert res["exchange"]["key"] == default_conf_usdt["exchange"]["key"]
|
||||||
|
|||||||
Reference in New Issue
Block a user