mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-28 06:23:07 +00:00
test(cache): isolate namespace regression test
This commit is contained in:
parent
e736c9402e
commit
d1acdfaf9a
3 changed files with 21 additions and 20 deletions
|
|
@ -657,11 +657,7 @@ class Cache:
|
|||
metadata_namespace,
|
||||
)
|
||||
namespace: Final[str | None] = (
|
||||
":".join(
|
||||
value
|
||||
for value in namespace_parts
|
||||
if isinstance(value, str) and value
|
||||
)
|
||||
":".join(value for value in namespace_parts if isinstance(value, str) and value)
|
||||
if authenticated_namespace is not None
|
||||
else requested_namespace or metadata_namespace or self.namespace
|
||||
)
|
||||
|
|
|
|||
20
tests/unit/caching/test_authenticated_namespace_cache_key.py
Normal file
20
tests/unit/caching/test_authenticated_namespace_cache_key.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from typing import Final
|
||||
|
||||
from litellm.caching.caching import Cache
|
||||
from litellm.proxy._types import UserAPIKeyAuth
|
||||
from litellm.types.caching import LiteLLMCacheType
|
||||
|
||||
|
||||
def test_authenticated_cache_keys_preserve_request_and_metadata_namespaces() -> None:
|
||||
cache: Final = Cache(type=LiteLLMCacheType.LOCAL, namespace="instance")
|
||||
caller: Final = UserAPIKeyAuth(api_key="fixture", token="hashed-key", team_id="team")
|
||||
|
||||
key: Final = cache._add_namespace_to_cache_key(
|
||||
"hashed-response",
|
||||
cache={"namespace": "request"},
|
||||
metadata={"user_api_key_auth": caller, "redis_namespace": "metadata"},
|
||||
)
|
||||
|
||||
assert key is not None
|
||||
assert key.startswith("instance:caller:")
|
||||
assert key.endswith(":request:metadata:hashed-response")
|
||||
|
|
@ -55,21 +55,6 @@ def test_authenticated_proxy_callers_get_distinct_exact_cache_keys() -> None:
|
|||
assert key_a != key_b
|
||||
|
||||
|
||||
def test_authenticated_cache_keys_preserve_request_and_metadata_namespaces() -> None:
|
||||
cache: Final = Cache(type=LiteLLMCacheType.LOCAL, namespace="instance")
|
||||
caller: Final = UserAPIKeyAuth(api_key="fixture", token="hashed-key", team_id="team")
|
||||
|
||||
key: Final = cache._add_namespace_to_cache_key(
|
||||
"hashed-response",
|
||||
cache={"namespace": "request"},
|
||||
metadata={"user_api_key_auth": caller, "redis_namespace": "metadata"},
|
||||
)
|
||||
|
||||
assert key is not None
|
||||
assert key.startswith("instance:caller:")
|
||||
assert key.endswith(":request:metadata:hashed-response")
|
||||
|
||||
|
||||
def test_authenticated_callers_without_server_token_fail_closed_for_all_key_forms() -> None:
|
||||
cache: Final = Cache(type=LiteLLMCacheType.LOCAL, namespace="qa")
|
||||
caller_a: Final = UserAPIKeyAuth(api_key="raw-a", team_id="team-a", user_id="user-a").model_copy(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue