mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-14 04:36:31 +00:00
Only support IPv4 for DNS (#2040)
This commit is contained in:
parent
0675f66ee6
commit
4565b01eeb
@ -74,9 +74,13 @@ def dns_url(url: str) -> str:
|
|||||||
raise vol.Invalid("Doesn't start with dns://") from None
|
raise vol.Invalid("Doesn't start with dns://") from None
|
||||||
address: str = url[6:] # strip the dns:// off
|
address: str = url[6:] # strip the dns:// off
|
||||||
try:
|
try:
|
||||||
ipaddress.ip_address(address) # matches ipv4 or ipv6 addresses
|
ip = ipaddress.ip_address(address) # matches ipv4 or ipv6 addresses
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise vol.Invalid(f"Invalid DNS URL: {url}") from None
|
raise vol.Invalid(f"Invalid DNS URL: {url}") from None
|
||||||
|
|
||||||
|
# Currently only IPv4 work with docker network
|
||||||
|
if ip.version != 4:
|
||||||
|
raise vol.Invalid(f"Only IPv4 is working for DNS: {url}") from None
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ async def test_dns_url_v4_good():
|
|||||||
|
|
||||||
def test_dns_url_v6_good():
|
def test_dns_url_v6_good():
|
||||||
"""Test the DNS validator with known-good ipv6 DNS URLs."""
|
"""Test the DNS validator with known-good ipv6 DNS URLs."""
|
||||||
|
with pytest.raises(vol.error.Invalid):
|
||||||
for url in DNS_GOOD_V6:
|
for url in DNS_GOOD_V6:
|
||||||
assert validate.dns_url(url)
|
assert validate.dns_url(url)
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ def test_dns_server_list_v4():
|
|||||||
|
|
||||||
def test_dns_server_list_v6():
|
def test_dns_server_list_v6():
|
||||||
"""Test a list with v6 addresses."""
|
"""Test a list with v6 addresses."""
|
||||||
|
with pytest.raises(vol.error.Invalid):
|
||||||
assert validate.dns_server_list(DNS_GOOD_V6)
|
assert validate.dns_server_list(DNS_GOOD_V6)
|
||||||
|
|
||||||
|
|
||||||
@ -44,9 +46,11 @@ def test_dns_server_list_combined():
|
|||||||
"""Test a list with both v4 and v6 addresses."""
|
"""Test a list with both v4 and v6 addresses."""
|
||||||
combined = DNS_GOOD_V4 + DNS_GOOD_V6
|
combined = DNS_GOOD_V4 + DNS_GOOD_V6
|
||||||
# test the matches
|
# test the matches
|
||||||
assert validate.dns_server_list(combined)
|
with pytest.raises(vol.error.Invalid):
|
||||||
|
validate.dns_server_list(combined)
|
||||||
# test max_length is OK still
|
# test max_length is OK still
|
||||||
assert validate.dns_server_list(combined)
|
with pytest.raises(vol.error.Invalid):
|
||||||
|
validate.dns_server_list(combined)
|
||||||
# test that it fails when the list is too long
|
# test that it fails when the list is too long
|
||||||
with pytest.raises(vol.error.Invalid):
|
with pytest.raises(vol.error.Invalid):
|
||||||
validate.dns_server_list(combined + combined + combined + combined)
|
validate.dns_server_list(combined + combined + combined + combined)
|
||||||
@ -72,6 +76,7 @@ def test_version_complex():
|
|||||||
"""Test version simple with good version."""
|
"""Test version simple with good version."""
|
||||||
for version in (
|
for version in (
|
||||||
"landingpage",
|
"landingpage",
|
||||||
|
"dev",
|
||||||
"1c002dd",
|
"1c002dd",
|
||||||
"1.1.1",
|
"1.1.1",
|
||||||
"1.0",
|
"1.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user