The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(e2e): cover key regeneration rotating to a working new key (#34000)
Yassin Kortam51df80115994
diff --git a/tests/e2e/management/management_client.py b/tests/e2e/management/management_client.pyindex e967fb7b504..6ce6405c2be 100644--- a/tests/e2e/management/management_client.py+++ b/tests/e2e/management/management_client.py@@ -16,8 +16,10 @@ from models import (ChatMessage,KeyDeleteBody,KeyGenerateBody,+ KeyGenerateResponse,KeyListParams,KeyListResponse,+ KeyRegenerateBody,KeyUpdateBody,OrgDeleteBody,OrgInfoParams,@@ -89,6 +91,16 @@ class ManagementClient:))+ def regenerate_key(self, key: str) -> str:+ return unwrap(+ self.proxy.transport.post(+ "/key/regenerate",+ headers=self.proxy.transport.master,+ json=KeyRegenerateBody(key=key),+ response_type=KeyGenerateResponse,+ )+ ).key+def key_alias_count(self, key_alias: str) -> int:return unwrap(self.proxy.transport.get(diff --git a/tests/e2e/management/test_management_e2e.py b/tests/e2e/management/test_management_e2e.pyindex adbf3e8b065..de34ee69ded 100644--- a/tests/e2e/management/test_management_e2e.py+++ b/tests/e2e/management/test_management_e2e.py@@ -169,6 +169,32 @@ class TestKeyRoutes:_ = _poll(client, rejected, "deleted key was still accepted on chat (never rejected 401) at the deadline")+class TestKeyRegeneration:+ @pytest.mark.covers("mgmt.key.regenerate.happy_path")+ def test_regenerate_rotates_to_a_working_new_key(+ self, client: ManagementClient, resources: ResourceManager+ ) -> None:+ old_key = _generate_key(client, resources, KeyGenerateBody(models=["gpt-5.5"]))++ new_key = client.regenerate_key(old_key)+ resources.defer(lambda: client.proxy.delete_key(new_key))+ assert new_key != old_key, "regenerate returned the same key string, so no rotation happened"++ def new_accepted() -> bool | None:+ outcome = client.chat_status(new_key, "gpt-5.5", f"say hi {unique_marker()}")+ return True if outcome.status_code != 401 else None++ _ = _poll(client, new_accepted, "regenerated key was never accepted at auth (still 401) at the deadline")++ def old_rejected() -> bool | None:+ outcome = client.chat_status(old_key, "gpt-5.5", f"say hi {unique_marker()}")+ return True if outcome.status_code == 401 else None++ _ = _poll(+ client, old_rejected, "old key was still accepted after regeneration (never rejected 401) at the deadline"+ )++class TestTeamRoutes:@pytest.mark.covers("mgmt.team.new.persists")def test_new_persists_to_team_info_and_binds_keys(diff --git a/tests/e2e/models.py b/tests/e2e/models.pyindex 2e7bfe41e30..bdcfd080b8e 100644--- a/tests/e2e/models.py+++ b/tests/e2e/models.py@@ -73,6 +73,10 @@ class KeyGenerateResponse(BaseModel):key: str+class KeyRegenerateBody(BaseModel):+ key: str++class KeyDeleteBody(BaseModel):keys: list[str]