Add concept of allowed external URLs to config (#36988)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Aaron BachandPaulus Schoutsen authored and GitHub committed 2020-06-24 17:37:01 -07:00
1 parent cbb76be9d0
commit 7968cd650a
6 files changed
+66 -7

No files matched your search

+2
View File
@@ -212,6 +212,8 @@ async def test_api_get_config(hass, mock_api_client):
result["components"] = set(result["components"])
if "whitelist_external_dirs" in result:
result["whitelist_external_dirs"] = set(result["whitelist_external_dirs"])
if "allowlist_external_urls" in result:
result["allowlist_external_urls"] = set(result["allowlist_external_urls"])
assert hass.config.as_dict() == result
@@ -234,6 +234,10 @@ async def test_get_config(hass, websocket_client):
msg["result"]["whitelist_external_dirs"] = set(
msg["result"]["whitelist_external_dirs"]
)
if "allowlist_external_urls" in msg["result"]:
msg["result"]["allowlist_external_urls"] = set(
msg["result"]["allowlist_external_urls"]
)
assert msg["result"] == hass.config.as_dict()
+28
View File
@@ -915,6 +915,7 @@ class TestConfig(unittest.TestCase):
"components": set(),
"config_dir": "/test/ha-config",
"whitelist_external_dirs": set(),
"allowlist_external_urls": set(),
"version": __version__,
"config_source": "default",
"safe_mode": False,
@@ -955,6 +956,33 @@ class TestConfig(unittest.TestCase):
with pytest.raises(AssertionError):
self.config.is_allowed_path(None)
def test_is_allowed_external_url(self):
"""Test is_allowed_external_url method."""
self.config.allowlist_external_urls = [
"http://x.com/",
"https://y.com/bla/",
"https://z.com/images/1.jpg/",
]
valid = [
"http://x.com/1.jpg",
"http://x.com",
"https://y.com/bla/",
"https://y.com/bla/2.png",
"https://z.com/images/1.jpg",
]
for url in valid:
assert self.config.is_allowed_external_url(url)
invalid = [
"https://a.co",
"https://y.com/bla_wrong",
"https://y.com/bla/../image.jpg",
"https://z.com/images",
]
for url in invalid:
assert not self.config.is_allowed_external_url(url)
async def test_event_on_update(hass):
"""Test that event is fired on update."""