Serve MCP and hooks with a secret through the portal tunnel
The connector now serves /mcp, its OAuth documents and /hooks/ besides /api/v1/, refuses any dot segment (httpx resolves them, which carried /api/v1/../../mcp onto the MCP mount), addresses calls to the hub's host, and bridges served sockets by calling the app with a websocket scope. A hook without a secret answers the tunnel with the 404 (or 1008) of a wrong secret. Requests through the hub get the hub's issuer, resource and consent page in the OAuth metadata and the 401, and the MCP host check admits the hub while enrolled.
This commit is contained in:
@@ -97,6 +97,55 @@ def test_the_resource_metadata_names_the_authorization_server(over_mcp) -> None:
|
||||
assert settings.oauth_issuer in listed
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enrolled")
|
||||
def test_through_the_hub_an_agent_is_shown_the_hubs_addresses(
|
||||
over_mcp,
|
||||
client: TestClient,
|
||||
superuser_token_headers: dict[str, str],
|
||||
agent: uuid.UUID,
|
||||
) -> None:
|
||||
"""What the connector sends: its marker, and the hub as the Host."""
|
||||
from fluksio.cloud import config as cloud_config
|
||||
from tests.utils.portal import INSTANCE_ID, ISSUER
|
||||
|
||||
via = {cloud_config.VIA_HEADER: cloud_config.VIA_PORTAL, "Host": "hub.example.test"}
|
||||
base = f"{ISSUER}/i/{INSTANCE_ID}"
|
||||
me = client.get(
|
||||
f"{settings.API_V1_STR}/users/me", headers=superuser_token_headers
|
||||
).json()
|
||||
token = mcp_token(uuid.UUID(me["id"]), agent)
|
||||
|
||||
async def block(http: httpx.AsyncClient) -> list[httpx.Response]:
|
||||
anonymous = rpc(None, "tools/list")
|
||||
signed = rpc(token, "tools/list")
|
||||
return [
|
||||
await http.post(
|
||||
"/mcp", json=anonymous["json"], headers={**anonymous["headers"], **via}
|
||||
),
|
||||
await http.get("/.well-known/oauth-protected-resource/mcp", headers=via),
|
||||
await http.post(
|
||||
"/mcp", json=signed["json"], headers={**signed["headers"], **via}
|
||||
),
|
||||
# Any other name is still refused.
|
||||
await http.post(
|
||||
"/mcp",
|
||||
json=signed["json"],
|
||||
headers={**signed["headers"], "Host": "elsewhere.test"},
|
||||
),
|
||||
]
|
||||
|
||||
unauthenticated, document, listed, elsewhere = over_mcp(block)
|
||||
assert unauthenticated.status_code == 401
|
||||
assert (
|
||||
f'resource_metadata="{ISSUER}/.well-known/oauth-protected-resource/i/{INSTANCE_ID}/mcp"'
|
||||
in unauthenticated.headers["www-authenticate"]
|
||||
)
|
||||
assert document.json()["resource"] == f"{base}/mcp"
|
||||
assert document.json()["authorization_servers"] == [base]
|
||||
assert listed.status_code == 200
|
||||
assert elsewhere.status_code == 421
|
||||
|
||||
|
||||
def test_a_browser_token_is_not_an_agent_token(
|
||||
over_mcp, superuser_token_headers: dict[str, str]
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user