60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import pytest
|
|
|
|
from fastmcp.server.mixins.transport import (
|
|
_format_host_for_url,
|
|
_resolve_allowed_hosts_for_run,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"host, expected",
|
|
[
|
|
("127.0.0.1", "127.0.0.1"),
|
|
("localhost", "localhost"),
|
|
("0.0.0.0", "0.0.0.0"),
|
|
("::1", "[::1]"),
|
|
("::", "[::]"),
|
|
("fe80::1", "[fe80::1]"),
|
|
("[::1]", "[::1]"),
|
|
],
|
|
)
|
|
def test_format_host_for_url(host: str, expected: str):
|
|
"""IPv6 hosts are bracketed for use in a URL; everything else is unchanged."""
|
|
assert _format_host_for_url(host) == expected
|
|
|
|
|
|
def test_resolve_allowed_hosts_for_run_merges_configured_hosts_with_loopback_host():
|
|
assert _resolve_allowed_hosts_for_run(
|
|
host="127.0.0.1",
|
|
host_origin_protection="auto",
|
|
allowed_hosts=None,
|
|
configured_allowed_hosts=["mcp.example.com"],
|
|
) == ["mcp.example.com", "127.0.0.1"]
|
|
|
|
|
|
def test_resolve_allowed_hosts_for_run_preserves_configured_hosts_when_disabled():
|
|
assert _resolve_allowed_hosts_for_run(
|
|
host="127.0.0.1",
|
|
host_origin_protection=False,
|
|
allowed_hosts=None,
|
|
configured_allowed_hosts=["mcp.example.com"],
|
|
) == ["mcp.example.com"]
|
|
|
|
|
|
def test_resolve_allowed_hosts_for_run_preserves_explicit_hosts():
|
|
assert _resolve_allowed_hosts_for_run(
|
|
host="127.0.0.1",
|
|
host_origin_protection="auto",
|
|
allowed_hosts=["mcp.example.com"],
|
|
configured_allowed_hosts=["settings.example.com"],
|
|
) == ["mcp.example.com"]
|