strato_check_dns: klarer Status (match, local_override, mismatch, not_resolvable, not_in_zone)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cd734a6de2
commit
c1391cfb69
2 files changed
+45
-10
No files matched your search
+32
-10
@@ -242,25 +242,47 @@ def strato_check_dns(name: str) -> str:
|
|||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
resolved = {"error": f"not resolvable: {exc.strerror or exc}"}
|
resolved = {"error": f"not resolvable: {exc.strerror or exc}"}
|
||||||
target = expected[0].value.rstrip(".").lower() if expected else None
|
target = expected[0].value.rstrip(".").lower() if expected else None
|
||||||
matches: bool | None = None
|
if not target:
|
||||||
if target and "addresses" in resolved:
|
status = "not_in_zone"
|
||||||
names = [resolved["canonical_name"], *resolved["aliases"]]
|
elif "addresses" not in resolved:
|
||||||
matches = any(n.rstrip(".").lower() == target for n in names) or _resolves_same(
|
status = "not_resolvable"
|
||||||
target, resolved["addresses"]
|
elif any(n.rstrip(".").lower() == target for n in [resolved["canonical_name"], *resolved["aliases"]]):
|
||||||
)
|
status = "match"
|
||||||
elif target:
|
elif _resolves_same(target, resolved["addresses"]):
|
||||||
matches = False
|
status = "match"
|
||||||
|
elif all(_is_private(ip) for ip in resolved["addresses"]):
|
||||||
|
status = "local_override"
|
||||||
|
else:
|
||||||
|
status = "mismatch"
|
||||||
return _json({
|
return _json({
|
||||||
"name": host,
|
"name": host,
|
||||||
"zone_cname_target": target,
|
"zone_cname_target": target,
|
||||||
"resolver": resolved,
|
"resolver": resolved,
|
||||||
"matches_zone": matches,
|
"status": status,
|
||||||
"note": "Uses the MCP host's resolver; local DNS overrides or caches can differ from public DNS.",
|
"explanation": {
|
||||||
|
"match": "The resolver follows the STRATO CNAME.",
|
||||||
|
"local_override": (
|
||||||
|
"The resolver answers with a private address instead of following the CNAME "
|
||||||
|
"(local DNS / split-horizon). Public resolution cannot be judged from here."
|
||||||
|
),
|
||||||
|
"mismatch": "The resolver returns something else than the STRATO CNAME (cache/TTL or wrong record).",
|
||||||
|
"not_resolvable": "The name does not resolve (yet).",
|
||||||
|
"not_in_zone": "There is no CNAME for this name in the STRATO zone.",
|
||||||
|
}[status],
|
||||||
})
|
})
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise _fail(exc) from None
|
raise _fail(exc) from None
|
||||||
|
|
||||||
|
|
||||||
|
def _is_private(address: str) -> bool:
|
||||||
|
import ipaddress
|
||||||
|
|
||||||
|
try:
|
||||||
|
return ipaddress.ip_address(address).is_private
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _resolves_same(target: str, addresses: list[str]) -> bool:
|
def _resolves_same(target: str, addresses: list[str]) -> bool:
|
||||||
try:
|
try:
|
||||||
return bool(set(socket.gethostbyname_ex(target)[2]) & set(addresses))
|
return bool(set(socket.gethostbyname_ex(target)[2]) & set(addresses))
|
||||||
|
|||||||
@@ -247,6 +247,19 @@ class McpTicketTests(unittest.TestCase):
|
|||||||
self.mcp.strato_apply_change("create", "CNAME", "chat", ticket, True, value="gw.example.net")
|
self.mcp.strato_apply_change("create", "CNAME", "chat", ticket, True, value="gw.example.net")
|
||||||
self.assertNotIn("POST", [r.method for r in self.opener.requests])
|
self.assertNotIn("POST", [r.method for r in self.opener.requests])
|
||||||
|
|
||||||
|
def test_check_dns_statuses(self) -> None:
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
self.opener.responses[:0] = []
|
||||||
|
table = {
|
||||||
|
"media.example.de": ("media.example.de", [], ["192.168.1.2"]),
|
||||||
|
"proxy.example.net": ("proxy.example.net", [], ["203.0.113.5"]),
|
||||||
|
}
|
||||||
|
with mock.patch.object(self.mcp.socket, "gethostbyname_ex", side_effect=lambda h: table[h]):
|
||||||
|
result = json.loads(self.mcp.strato_check_dns("media"))
|
||||||
|
self.assertEqual(result["status"], "local_override")
|
||||||
|
self.assertEqual(result["zone_cname_target"], "proxy.example.net")
|
||||||
|
|
||||||
def test_errors_are_tool_errors(self) -> None:
|
def test_errors_are_tool_errors(self) -> None:
|
||||||
from mcp.server.fastmcp.exceptions import ToolError
|
from mcp.server.fastmcp.exceptions import ToolError
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user