test(logging): cover invalid worker config privacy

This commit is contained in:
moe-berri 2026-10-29 12:02:27 -07:00
parent a6f8d0e0b1
commit 56372ea04f

View file

@ -4105,6 +4105,37 @@ def test_worker_config_privacy_applies_before_global_setting(
assert "PRIVATE_SYSTEM_PROMPT" in str(result)
@pytest.mark.parametrize("as_json", [False, True])
def test_worker_config_invalid_privacy_setting_does_not_expose_content(
monkeypatch: pytest.MonkeyPatch, as_json: bool
) -> None:
from litellm.proxy.proxy_server import _redact_worker_config_for_logging
monkeypatch.setattr(litellm, "redact_messages_in_debug_logs", False)
config: Final = {
"litellm_settings": {"redact_messages_in_debug_logs": "invalid-boolean"},
"model_list": [{"litellm_params": {"messages": [{"content": "PRIVATE_SYSTEM_PROMPT"}]}}],
}
original: Final = json.dumps(config)
result: Final = _redact_worker_config_for_logging(original if as_json else config)
assert result == "redacted-by-litellm"
assert json.dumps(config) == original
assert litellm.redact_messages_in_debug_logs is False
@pytest.mark.parametrize("worker_config", ['{"messages": "PRIVATE_SYSTEM_PROMPT"', None])
@pytest.mark.parametrize("enabled", [False, True])
def test_worker_config_global_privacy_covers_unparseable_config(
monkeypatch: pytest.MonkeyPatch, worker_config: str | None, enabled: bool
) -> None:
from litellm.proxy.proxy_server import _redact_worker_config_for_logging
monkeypatch.setattr(litellm, "redact_messages_in_debug_logs", enabled)
assert _redact_worker_config_for_logging(worker_config) == ("redacted-by-litellm" if enabled else worker_config)
@pytest.mark.asyncio
async def test_queue_request_labels_an_upstream_failure_a_server_error_not_an_auth_error(
monkeypatch: pytest.MonkeyPatch,