test(redis): cover host/port Azure Entra config alongside credential_provider

The existing coverage for dropping username when an Azure AD
credential_provider is present (test_async_url_client_drops_username_alongside_credential_provider)
only exercised the REDIS_URL branch of get_redis_async_client. The
reported host/port config (REDIS_AZURE_AD_TOKEN + REDIS_USERNAME, no
REDIS_URL) goes through the same _async_auth_kwargs stripping, but
nothing asserted that path directly.

Verified the redis-py conflict error only surfaces once a Connection
is actually instantiated (pool.connection_class(**pool.connection_kwargs)),
and confirmed this test both passes against current code and fails if
the username-stripping step regresses.
This commit is contained in:
= 2026-08-20 23:57:26 -05:00
parent e17988f4fe
commit 06850050d3

View file

@ -986,6 +986,33 @@ def test_async_url_client_drops_username_alongside_credential_provider():
pool.connection_class(**pool.connection_kwargs)
def test_async_host_client_drops_username_alongside_credential_provider():
"""
Regression test for https://github.com/BerriAI/litellm/issues/37335
A host/port (non-URL) Azure Entra config -- e.g. REDIS_AZURE_AD_TOKEN=true with
REDIS_USERNAME set and no REDIS_PASSWORD -- must not reach redis-py with both
`username` and `credential_provider` set, since redis-py rejects that combination
outright. AzureADCredentialProvider already carries REDIS_USERNAME, so the plain
`username` kwarg must be dropped on this path too, not just the REDIS_URL one.
"""
redis_kwargs = {
"host": "redis-host",
"port": 6380,
"ssl": True,
"username": "redis-user",
"redis_connect_func": SimpleNamespace(**AZURE_AD_CONNECT_FUNC),
}
with patch("litellm._redis._get_redis_client_logic", return_value=redis_kwargs):
client = get_redis_async_client()
pool = client.connection_pool
assert pool.connection_kwargs.get("username") is None
assert isinstance(pool.connection_kwargs.get("credential_provider"), AzureADCredentialProvider)
pool.connection_class(**pool.connection_kwargs)
@pytest.mark.parametrize("build_pool", [False, True], ids=["client", "pool"])
def test_async_url_keeps_a_coroutine_connect_func(build_pool):
"""redis-py awaits a coroutine redis_connect_func on an async connection, so one we cannot