mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Fix domain validation in Tesla Fleet (#148555)
This commit is contained in:
parent
e6702d2392
commit
193b32218f
@ -226,5 +226,7 @@ class OAuth2FlowHandler(
|
|||||||
def _is_valid_domain(self, domain: str) -> bool:
|
def _is_valid_domain(self, domain: str) -> bool:
|
||||||
"""Validate domain format."""
|
"""Validate domain format."""
|
||||||
# Basic domain validation regex
|
# Basic domain validation regex
|
||||||
domain_pattern = re.compile(r"^(?:[a-zA-Z0-9]+\.)+[a-zA-Z0-9-]+$")
|
domain_pattern = re.compile(
|
||||||
|
r"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$"
|
||||||
|
)
|
||||||
return bool(domain_pattern.match(domain))
|
return bool(domain_pattern.match(domain))
|
||||||
|
@ -713,8 +713,11 @@ async def test_reauth_confirm_form(hass: HomeAssistant) -> None:
|
|||||||
("domain", "expected_valid"),
|
("domain", "expected_valid"),
|
||||||
[
|
[
|
||||||
("example.com", True),
|
("example.com", True),
|
||||||
|
("exa-mple.com", True),
|
||||||
("test.example.com", True),
|
("test.example.com", True),
|
||||||
|
("tes-t.example.com", True),
|
||||||
("sub.domain.example.org", True),
|
("sub.domain.example.org", True),
|
||||||
|
("su-b.dom-ain.exam-ple.org", True),
|
||||||
("https://example.com", False),
|
("https://example.com", False),
|
||||||
("invalid-domain", False),
|
("invalid-domain", False),
|
||||||
("", False),
|
("", False),
|
||||||
@ -722,6 +725,8 @@ async def test_reauth_confirm_form(hass: HomeAssistant) -> None:
|
|||||||
("example.", False),
|
("example.", False),
|
||||||
(".example.com", False),
|
(".example.com", False),
|
||||||
("exam ple.com", False),
|
("exam ple.com", False),
|
||||||
|
("-example.com", False),
|
||||||
|
("domain-.example.com", False),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_is_valid_domain(domain: str, expected_valid: bool) -> None:
|
def test_is_valid_domain(domain: str, expected_valid: bool) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user