1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 12:29:08 +00:00

Make IPv4 and IPv6 parse errors raise an API error (#5282)

* Make IPv4 and IPv6 parse errors raise an API error

Currently, IP address parsing errors lead to an execption which is not
handled by the `api_validate()` call. By using concrete IPv4 and IPv6
types and `vol.Coerce()` parsing errors are properly handled.

* ruff format

* ruff check
This commit is contained in:
Stefan Agner
2024-08-30 18:20:20 +02:00
committed by GitHub
parent c0e35376f3
commit 00d217b5f7
2 changed files with 36 additions and 7 deletions

View File

@@ -292,6 +292,26 @@ async def test_api_network_interface_update_invalid(api_client: TestClient):
== "expected a list for dictionary value @ data['ipv4']['nameservers']. Got '1.1.1.1'"
)
resp = await api_client.post(
f"/network/interface/{TEST_INTERFACE_ETH_NAME}/update",
json={"ipv4": {"gateway": "invalid"}},
)
result = await resp.json()
assert (
result["message"]
== "expected IPv4Address for dictionary value @ data['ipv4']['gateway']. Got 'invalid'"
)
resp = await api_client.post(
f"/network/interface/{TEST_INTERFACE_ETH_NAME}/update",
json={"ipv6": {"gateway": "invalid"}},
)
result = await resp.json()
assert (
result["message"]
== "expected IPv6Address for dictionary value @ data['ipv6']['gateway']. Got 'invalid'"
)
async def test_api_network_wireless_scan(api_client: TestClient):
"""Test network manager api."""