Fix local media browser source conflicting with local www folder (#40151)

This commit is contained in:
Franck Nijhof authored and GitHub committed 2020-09-16 21:38:40 +02:00
1 parent 5ea04d64f6
commit f83f3c927a
6 files changed
+23 -23

No files matched your search

+3 -3
View File
@@ -65,7 +65,7 @@ async def test_async_resolve_media(hass):
media = await media_source.async_resolve_media(
hass,
media_source.generate_media_source_id(const.DOMAIN, "media/test.mp3"),
media_source.generate_media_source_id(const.DOMAIN, "local/test.mp3"),
)
assert isinstance(media, media_source.models.PlayMedia)
@@ -140,7 +140,7 @@ async def test_websocket_resolve_media(hass, hass_ws_client):
client = await hass_ws_client(hass)
media = media_source.models.PlayMedia("/local_source/media/test.mp3", "audio/mpeg")
media = media_source.models.PlayMedia("/media/local/test.mp3", "audio/mpeg")
with patch(
"homeassistant.components.media_source.async_resolve_media",
@@ -150,7 +150,7 @@ async def test_websocket_resolve_media(hass, hass_ws_client):
{
"id": 1,
"type": "media_source/resolve_media",
"media_content_id": f"{const.URI_SCHEME}{const.DOMAIN}/media/test.mp3",
"media_content_id": f"{const.URI_SCHEME}{const.DOMAIN}/local/test.mp3",
}
)
@@ -11,7 +11,7 @@ async def test_async_browse_media(hass):
"""Test browse media."""
local_media = hass.config.path("media")
await async_process_ha_core_config(
hass, {"media_dirs": {"media": local_media, "recordings": local_media}}
hass, {"media_dirs": {"local": local_media, "recordings": local_media}}
)
await hass.async_block_till_done()
@@ -21,14 +21,14 @@ async def test_async_browse_media(hass):
# Test path not exists
with pytest.raises(media_source.BrowseError) as excinfo:
await media_source.async_browse_media(
hass, f"{const.URI_SCHEME}{const.DOMAIN}/media/test/not/exist"
hass, f"{const.URI_SCHEME}{const.DOMAIN}/local/test/not/exist"
)
assert str(excinfo.value) == "Path does not exist."
# Test browse file
with pytest.raises(media_source.BrowseError) as excinfo:
await media_source.async_browse_media(
hass, f"{const.URI_SCHEME}{const.DOMAIN}/media/test.mp3"
hass, f"{const.URI_SCHEME}{const.DOMAIN}/local/test.mp3"
)
assert str(excinfo.value) == "Path is not a directory."
@@ -42,7 +42,7 @@ async def test_async_browse_media(hass):
# Test directory traversal
with pytest.raises(media_source.BrowseError) as excinfo:
await media_source.async_browse_media(
hass, f"{const.URI_SCHEME}{const.DOMAIN}/media/../configuration.yaml"
hass, f"{const.URI_SCHEME}{const.DOMAIN}/local/../configuration.yaml"
)
assert str(excinfo.value) == "Invalid path."
@@ -53,7 +53,7 @@ async def test_async_browse_media(hass):
assert media
media = await media_source.async_browse_media(
hass, f"{const.URI_SCHEME}{const.DOMAIN}/media/."
hass, f"{const.URI_SCHEME}{const.DOMAIN}/local/."
)
assert media
@@ -67,7 +67,7 @@ async def test_media_view(hass, hass_client):
"""Test media view."""
local_media = hass.config.path("media")
await async_process_ha_core_config(
hass, {"media_dirs": {"media": local_media, "recordings": local_media}}
hass, {"media_dirs": {"local": local_media, "recordings": local_media}}
)
await hass.async_block_till_done()
@@ -77,23 +77,23 @@ async def test_media_view(hass, hass_client):
client = await hass_client()
# Protects against non-existent files
resp = await client.get("/local_source/media/invalid.txt")
resp = await client.get("/media/local/invalid.txt")
assert resp.status == 404
resp = await client.get("/local_source/recordings/invalid.txt")
resp = await client.get("/media/recordings/invalid.txt")
assert resp.status == 404
# Protects against non-media files
resp = await client.get("/local_source/media/not_media.txt")
resp = await client.get("/media/local/not_media.txt")
assert resp.status == 404
# Protects against unknown local media sources
resp = await client.get("/local_source/unknown_source/not_media.txt")
resp = await client.get("/media/unknown_source/not_media.txt")
assert resp.status == 404
# Fetch available media
resp = await client.get("/local_source/media/test.mp3")
resp = await client.get("/media/local/test.mp3")
assert resp.status == 200
resp = await client.get("/local_source/recordings/test.mp3")
resp = await client.get("/media/recordings/test.mp3")
assert resp.status == 200