Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/gateway/test_multiplex_credential_isolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,41 @@ def worker():
t.join()

assert seen["home"] == str(prof_b)


class TestApiServerEnvIsScoped:
"""_apply_env_overrides must read API_SERVER_* through the profile scope,
not the global os.environ, so a secondary profile is not falsely enabled
by the default profile's key loaded into os.environ (#52307)."""

def test_secondary_profile_scope_without_key_does_not_enable(self, monkeypatch):
from gateway.config import _apply_env_overrides, GatewayConfig, Platform

# Default profile's key is in the global process env (loaded at import).
monkeypatch.setenv("API_SERVER_KEY", "global-default-key")
ss.set_multiplex_active(True)

# Secondary profile scope has NO api_server credential.
tok = ss.set_secret_scope({"OPENAI_API_KEY": "sk-secondary"})
try:
config = GatewayConfig()
_apply_env_overrides(config)
api = config.platforms.get(Platform.API_SERVER)
assert api is None or api.enabled is False
finally:
ss.reset_secret_scope(tok)

def test_profile_scope_with_key_enables(self, monkeypatch):
from gateway.config import _apply_env_overrides, GatewayConfig, Platform

monkeypatch.delenv("API_SERVER_KEY", raising=False)
ss.set_multiplex_active(True)
tok = ss.set_secret_scope({"API_SERVER_KEY": "profile-scoped-key"})
try:
config = GatewayConfig()
_apply_env_overrides(config)
api = config.platforms.get(Platform.API_SERVER)
assert api is not None and api.enabled is True
assert api.extra.get("key") == "profile-scoped-key"
finally:
ss.reset_secret_scope(tok)
Loading