Ensure domain is correct format (#58429)

This commit is contained in:
Paulus Schoutsen 2021-10-25 15:56:07 -07:00 committed by GitHub
parent a813608185
commit cd3e51b3e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -576,6 +576,9 @@ async def async_get_integration(hass: HomeAssistant, domain: str) -> Integration
async def _async_get_integration(hass: HomeAssistant, domain: str) -> Integration:
if "." in domain:
raise ValueError(f"Invalid domain {domain}")
# Instead of using resolve_from_root we use the cache of custom
# components to find the integration.
if integration := (await async_get_custom_components(hass)).get(domain):

View file

@ -540,3 +540,9 @@ async def test_custom_integration_missing(hass, caplog):
with pytest.raises(loader.IntegrationNotFound):
await loader.async_get_integration(hass, "test1")
async def test_validation(hass):
"""Test we raise if invalid domain passed in."""
with pytest.raises(ValueError):
await loader.async_get_integration(hass, "some.thing")