From 06850050d3efdabe1aab2e86c46696c3c2d8af28 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 20 Aug 2026 23:57:26 -0500 Subject: [PATCH] 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. --- tests/test_litellm/test_redis.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_litellm/test_redis.py b/tests/test_litellm/test_redis.py index c645a67ef84..98415a81c17 100644 --- a/tests/test_litellm/test_redis.py +++ b/tests/test_litellm/test_redis.py @@ -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