Files
Nexus/tests/test_site_host.py
T
2026-07-08 22:31:31 +08:00

59 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""site_host resolution helpers."""
from server.domain.models import Server
from server.utils.site_host import (
is_ip_host,
parse_site_host_from_target_path,
resolve_server_site_host,
resolve_server_site_host_from_server,
)
def test_is_ip_host():
assert is_ip_host("192.168.1.1") is True
assert is_ip_host("example.com") is False
assert is_ip_host(" ") is False
def test_parse_site_host_from_target_path():
assert parse_site_host_from_target_path("/www/wwwroot/shop.crmeb.com") == "shop.crmeb.com"
assert parse_site_host_from_target_path("/www/wwwroot/shop") is None
assert parse_site_host_from_target_path("/www/wwwroot/1.2.3.4") is None
def test_resolve_server_site_host_extra_attrs():
host = resolve_server_site_host(extra_attrs={"site_url": "https://Foo.COM/path"})
assert host == "foo.com"
def test_resolve_server_site_host_from_server_ip_only():
server = Server(
name="s1",
domain="10.0.0.1",
extra_attrs=None,
target_path="/www/wwwroot",
)
assert resolve_server_site_host_from_server(server) is None
def test_description_chinese_remark_not_site_host():
"""tonex 备注写入 description 时不得解析为 punycode 假域名。"""
host = resolve_server_site_host(
description="A8-昂翊-主6.261+2",
target_path="/www/wwwroot/zi_hbangxiang.com/crmeb",
)
assert host == "zi_hbangxiang.com"
def test_server_needs_site_domain():
from server.application.services import ip_domain_detect_schedule as sched
ip_only = Server(name="a", domain="1.2.3.4")
assert sched.server_needs_site_domain(ip_only) is True
with_site = Server(name="b", domain="1.2.3.4", extra_attrs={"site_url": "x.com"})
assert sched.server_needs_site_domain(with_site) is False
domain_ssh = Server(name="c", domain="x.com")
assert sched.server_needs_site_domain(domain_ssh) is False