Archived
Refactor UI assets and harden quality checks
This commit is contained in:
1 parent
23ab466c52
commit
4ecc8eb874
62 files changed
+3314
-3206
No files matched your search
@@ -55,6 +55,68 @@ def test_router_update_post_accepts_form_and_json(tmp_path: Path) -> None:
|
||||
assert store.list_records()[0]["ipv4"] == "203.0.113.10"
|
||||
|
||||
|
||||
def test_router_post_json_parser_keeps_only_string_values() -> None:
|
||||
from karldns.routers.updates import _json_post_values
|
||||
|
||||
values = _json_post_values(b'{"myip":"203.0.113.10","count":1,"empty":"","nested":{"x":1}}')
|
||||
|
||||
assert values == {"myip": "203.0.113.10", "empty": ""}
|
||||
|
||||
|
||||
def test_router_post_form_parser_handles_invalid_utf8_as_empty() -> None:
|
||||
from karldns.routers.updates import _form_post_values
|
||||
|
||||
assert _form_post_values(b"\xff") == {}
|
||||
|
||||
|
||||
def test_router_ip_params_merge_body_without_overriding_query_values() -> None:
|
||||
from karldns.routers.updates import _IpParams
|
||||
|
||||
params = _IpParams(myip="203.0.113.8", ipaddr=None, myipv6="", ip6addr=None)
|
||||
|
||||
merged = params.with_body_values(
|
||||
{
|
||||
"myip": "203.0.113.9",
|
||||
"ipaddr": "198.51.100.9",
|
||||
"myipv6": "2001:db8::9",
|
||||
}
|
||||
)
|
||||
|
||||
assert merged == _IpParams(
|
||||
myip="203.0.113.8",
|
||||
ipaddr="198.51.100.9",
|
||||
myipv6="2001:db8::9",
|
||||
ip6addr=None,
|
||||
)
|
||||
|
||||
|
||||
def test_router_ip_params_from_query_builds_domain_params() -> None:
|
||||
from karldns.routers.updates import _ip_params_from_query
|
||||
from karldns.services.ddns import UpdateIpParams
|
||||
|
||||
assert _ip_params_from_query(myip="203.0.113.8", ipaddr=None, myipv6=None, ip6addr="2001:db8::8") == (
|
||||
UpdateIpParams(myip="203.0.113.8", ipaddr=None, myipv6=None, ip6addr="2001:db8::8")
|
||||
)
|
||||
|
||||
|
||||
def test_registration_hostname_rejects_disabled_or_unmanaged_accounts() -> None:
|
||||
from fastapi import HTTPException
|
||||
|
||||
from karldns.routers.updates import _registration_hostname
|
||||
|
||||
class Service:
|
||||
def hostname_is_managed(self, hostname: str) -> bool:
|
||||
return hostname.endswith(".managed.example")
|
||||
|
||||
assert _registration_hostname({"hostname": "home.managed.example", "disabled": False}, Service()) == (
|
||||
"home.managed.example"
|
||||
)
|
||||
with pytest.raises(HTTPException):
|
||||
_registration_hostname({"hostname": "home.managed.example", "disabled": True}, Service())
|
||||
with pytest.raises(HTTPException):
|
||||
_registration_hostname({"hostname": "home.other.example", "disabled": False}, Service())
|
||||
|
||||
|
||||
def test_router_update_requires_registered_hostname(tmp_path: Path) -> None:
|
||||
database_path = tmp_path / "ddns.sqlite3"
|
||||
store = DdnsStore(database_path)
|
||||
|
||||
Reference in new issue
Block a user