mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
test(mcp): cover static-prefix issuer discovery
This commit is contained in:
parent
da61fa3564
commit
f66239a50f
1 changed files with 47 additions and 0 deletions
|
|
@ -11234,3 +11234,50 @@ def test_named_resource_discovery_follows_matching_authorization_issuer(
|
|||
authorization = client.get(f"{prefix}/.well-known/oauth-authorization-server/{issuer_path}")
|
||||
assert authorization.status_code == 200
|
||||
assert authorization.json()["issuer"] == resource["authorization_servers"][0]
|
||||
|
||||
|
||||
def test_static_root_path_authorization_discovery_preserves_issuer(monkeypatch):
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
monkeypatch.setenv("SERVER_ROOT_PATH", "/gateway")
|
||||
monkeypatch.setenv("PROXY_BASE_URL", "http://testserver/gateway")
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-c",
|
||||
"""
|
||||
import json
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router
|
||||
from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager
|
||||
from litellm.types.mcp import MCPAuth, MCPTransport
|
||||
from litellm.types.mcp_server.mcp_server_manager import MCPServer
|
||||
|
||||
global_mcp_server_manager.registry['example'] = MCPServer(
|
||||
server_id='example', name='example', server_name='example', alias='example',
|
||||
transport=MCPTransport.http, auth_type=MCPAuth.oauth2,
|
||||
authorization_url='https://idp.example.com/authorize', token_url='https://idp.example.com/token',
|
||||
)
|
||||
app = FastAPI(root_path='/gateway')
|
||||
app.include_router(router)
|
||||
with TestClient(app) as client:
|
||||
responses = {
|
||||
path: client.get('/.well-known/oauth-authorization-server/gateway/' + path)
|
||||
for path in ('mcp/example', 'example/mcp', 'example', 'mcp')
|
||||
}
|
||||
print(json.dumps({path: {'status': response.status_code, 'body': response.json()}
|
||||
for path, response in responses.items()}))
|
||||
""",
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
timeout=60,
|
||||
)
|
||||
responses = json.loads(result.stdout)
|
||||
for path in ("mcp/example", "example/mcp", "example", "mcp"):
|
||||
assert responses[path]["status"] == 200, responses[path]
|
||||
assert responses[path]["body"]["issuer"] == f"http://testserver/gateway/{path}"
|
||||
assert responses["example/mcp"]["body"]["token_endpoint"] == "http://testserver/gateway/example/token"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue