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): create the key under the dashboard session key
Yuneng Jiang8741e8a1adc9
diff --git a/tests/e2e/management/management_client.py b/tests/e2e/management/management_client.pyindex d3be1e9f39c..387280c8023 100644--- a/tests/e2e/management/management_client.py+++ b/tests/e2e/management/management_client.py@@ -105,6 +105,20 @@ class ManagementClient:def llm_only_key(self) -> str:return self.proxy.generate_key(KeyGenerateBody(models=[], allowed_routes=["llm_api_routes"]))+ def generate_key(self, body: KeyGenerateBody, *, caller_key: str | None = None) -> Result[KeyGenerateResponse]:+ """POST /key/generate. `caller_key` is who is creating the key: the master+ key by default, or a virtual key (an admin filling in Create New Key on the+ dashboard creates it under the session key their sign-in minted). Returns+ the outcome rather than unwrapping it, so a caller can poll a route that is+ only transiently refusing."""+ headers = self.proxy.transport.master if caller_key is None else self.proxy.transport.bearer(caller_key)+ return self.proxy.transport.post(+ "/key/generate",+ headers=headers,+ json=body,+ response_type=KeyGenerateResponse,+ )+def update_key(self, body: KeyUpdateBody, *, caller_key: str | None = None) -> Result[NoBody]:"""POST /key/update. `caller_key` is who is editing: the master key bydefault, or a virtual key (the dashboard edits under the session key itsdiff --git a/tests/e2e/management/test_management_e2e.py b/tests/e2e/management/test_management_e2e.pyindex a381f320cdc..a56eb853823 100644--- a/tests/e2e/management/test_management_e2e.py+++ b/tests/e2e/management/test_management_e2e.py@@ -24,7 +24,21 @@ from management_client import (ROUTE_NOT_ALLOWED_MARKER,ManagementClient,)-from models import KeyGenerateBody, KeyUpdateBody, OrgInfoResponse, OrgNewBody, OrgUpdateBody, TagListEntry, TagNewBody, TeamNewBody, TeamUpdateBody, UserNewBody, UserUpdateBody, LiteLLMParamsBody, ModelInfoEntry+from models import (+ KeyGenerateBody,+ KeyUpdateBody,+ LiteLLMParamsBody,+ ModelInfoEntry,+ OrgInfoResponse,+ OrgNewBody,+ OrgUpdateBody,+ TagListEntry,+ TagNewBody,+ TeamNewBody,+ TeamUpdateBody,+ UserNewBody,+ UserUpdateBody,+)pytestmark = pytest.mark.e2e@@ -209,12 +223,9 @@ class TestDashboardKeyRoutes:are the same routes the API-surface tests cover with a different caller."""@pytest.mark.covers("mgmt.key.generate.happy_path")- def test_sign_in_mints_a_session_key_that_drives_the_dashboard(+ def test_creating_a_key_from_the_dashboard_persists_and_works(self, client: ManagementClient, resources: ResourceManager) -> None:- alias = f"e2e-mgmt-uisession-{unique_marker()}"- _ = _generate_key(client, resources, KeyGenerateBody(models=["gemini-2.5-flash"], key_alias=alias))-session = client.dashboard_login(UI_USERNAME, UI_PASSWORD)resources.defer(lambda: client.proxy.delete_key(session.session_key))@@ -222,18 +233,50 @@ class TestDashboardKeyRoutes:f"/v2/login reports login_method {session.claims.login_method!r} for a username/password sign-in")assert session.claims.user_role == "proxy_admin", (- f"/v2/login reports user_role {session.claims.user_role!r} for the admin credentials, expected 'proxy_admin'"+ f"/v2/login reports user_role {session.claims.user_role!r} for the admin credentials, "+ "expected 'proxy_admin'")assert session.redirect_url.endswith("/ui?login=success"), (f"/v2/login sends the browser to {session.redirect_url!r} instead of the dashboard")- info = client.proxy.key_info(session.session_key)- assert info.team_id == DASHBOARD_SESSION_TEAM_ID, (- f"the minted session key reports team_id {info.team_id!r}, expected the dashboard's "+ session_info = client.proxy.key_info(session.session_key)+ assert session_info.team_id == DASHBOARD_SESSION_TEAM_ID, (+ f"the minted session key reports team_id {session_info.team_id!r}, expected the dashboard's "f"{DASHBOARD_SESSION_TEAM_ID!r}")+ alias = f"e2e-mgmt-uicreate-{unique_marker()}"++ def dashboard_creates_the_key() -> str | None:+ match client.generate_key(+ KeyGenerateBody(models=["gemini-2.5-flash"], key_alias=alias, tpm_limit=100),+ caller_key=session.session_key,+ ):+ case Success(data=created):+ return created.key+ case _:+ return None++ created = _poll(+ client,+ dashboard_creates_the_key,+ "the dashboard session key was never accepted on /key/generate before the deadline",+ )+ resources.defer(lambda: client.proxy.delete_key(created))++ created_info = client.proxy.key_info(created)+ assert created_info.key_alias == alias, (+ f"/key/info reports key_alias {created_info.key_alias!r} for the key the dashboard created, "+ f"expected {alias!r}"+ )+ assert created_info.models == ["gemini-2.5-flash"], (+ f"/key/info reports models {created_info.models} for the key the dashboard created"+ )+ assert created_info.tpm_limit == 100, (+ f"/key/info reports tpm_limit {created_info.tpm_limit} for the key the dashboard created, expected 100"+ )+def dashboard_lists_the_key() -> bool | None:match client.key_list(alias, caller_key=session.session_key):case Success(data=listing) if listing.total_count == 1:@@ -248,6 +291,9 @@ class TestDashboardKeyRoutes:"would render no keys",)+ _poll_chat_ok(client, created, "gemini-2.5-flash")+ _assert_model_denied(client.chat_status(created, "gpt-5.5", f"say hi {unique_marker()}"), "gpt-5.5")+@pytest.mark.covers("mgmt.key.update.happy_path")def test_editing_a_key_from_the_dashboard_persists_and_is_enforced(self, client: ManagementClient, resources: ResourceManager