mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-04-02 08:12:47 +01:00
* Use verbose log output for plug-ins All three plug-ins which support logging (dns, multicast and audio) should use the verbose log format by default to make sure the log lines are annotated with timestamp. Introduce a new flag default_verbose for advanced logs. * Use default_verbose for host logs as well Use the new default_verbose flag for advanced logs, to make it more explicit that we want timestamps for host logs as well.
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
"""Test DNS API."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from aiohttp.test_utils import TestClient
|
|
|
|
from supervisor.coresys import CoreSys
|
|
from supervisor.dbus.resolved import Resolved
|
|
from supervisor.host.const import LogFormatter
|
|
|
|
from tests.dbus_service_mocks.base import DBusServiceMock
|
|
from tests.dbus_service_mocks.resolved import Resolved as ResolvedService
|
|
|
|
|
|
async def test_llmnr_mdns_info(
|
|
api_client: TestClient,
|
|
coresys: CoreSys,
|
|
all_dbus_services: dict[str, DBusServiceMock | dict[str, DBusServiceMock]],
|
|
):
|
|
"""Test llmnr and mdns in info api."""
|
|
resolved_service: ResolvedService = all_dbus_services["resolved"]
|
|
|
|
# pylint: disable=protected-access
|
|
coresys.host.sys_dbus._resolved = Resolved()
|
|
# pylint: enable=protected-access
|
|
|
|
resp = await api_client.get("/dns/info")
|
|
result = await resp.json()
|
|
assert result["data"]["llmnr"] is False
|
|
assert result["data"]["mdns"] is False
|
|
|
|
await coresys.dbus.resolved.connect(coresys.dbus.bus)
|
|
resp = await api_client.get("/dns/info")
|
|
result = await resp.json()
|
|
assert result["data"]["llmnr"] is True
|
|
assert result["data"]["mdns"] is True
|
|
|
|
resolved_service.emit_properties_changed({"LLMNR": "no", "MulticastDNS": "no"})
|
|
await resolved_service.ping()
|
|
|
|
resp = await api_client.get("/dns/info")
|
|
result = await resp.json()
|
|
assert result["data"]["llmnr"] is False
|
|
assert result["data"]["mdns"] is False
|
|
|
|
|
|
async def test_options(api_client: TestClient, coresys: CoreSys):
|
|
"""Test options api."""
|
|
assert coresys.plugins.dns.servers == []
|
|
assert coresys.plugins.dns.fallback is True
|
|
|
|
with patch.object(type(coresys.plugins.dns), "restart") as restart:
|
|
await api_client.post(
|
|
"/dns/options", json={"servers": ["dns://8.8.8.8"], "fallback": False}
|
|
)
|
|
|
|
assert coresys.plugins.dns.servers == ["dns://8.8.8.8"]
|
|
assert coresys.plugins.dns.fallback is False
|
|
restart.assert_called_once()
|
|
|
|
restart.reset_mock()
|
|
await api_client.post("/dns/options", json={"fallback": True})
|
|
|
|
assert coresys.plugins.dns.servers == ["dns://8.8.8.8"]
|
|
assert coresys.plugins.dns.fallback is True
|
|
restart.assert_called_once()
|
|
|
|
|
|
async def test_api_dns_logs(advanced_logs_tester):
|
|
"""Test dns logs."""
|
|
await advanced_logs_tester("/dns", "hassio_dns", LogFormatter.VERBOSE)
|