mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Skip signing URL that we know requires no auth (#71208)
This commit is contained in:
parent
0cdcdec809
commit
0926470ef0
@ -20,6 +20,9 @@ from homeassistant.helpers.network import (
|
|||||||
|
|
||||||
from .const import CONTENT_AUTH_EXPIRY_TIME, MEDIA_CLASS_DIRECTORY
|
from .const import CONTENT_AUTH_EXPIRY_TIME, MEDIA_CLASS_DIRECTORY
|
||||||
|
|
||||||
|
# Paths that we don't need to sign
|
||||||
|
PATHS_WITHOUT_AUTH = ("/api/tts_proxy/",)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_process_play_media_url(
|
def async_process_play_media_url(
|
||||||
@ -46,6 +49,10 @@ def async_process_play_media_url(
|
|||||||
logging.getLogger(__name__).debug(
|
logging.getLogger(__name__).debug(
|
||||||
"Not signing path for content with query param"
|
"Not signing path for content with query param"
|
||||||
)
|
)
|
||||||
|
elif parsed.path.startswith(PATHS_WITHOUT_AUTH):
|
||||||
|
# We don't sign this path if it doesn't need auth. Although signing itself can't hurt,
|
||||||
|
# some devices are unable to handle long URLs and the auth signature might push it over.
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
signed_path = async_sign_path(
|
signed_path = async_sign_path(
|
||||||
hass,
|
hass,
|
||||||
|
@ -73,6 +73,18 @@ async def test_process_play_media_url(hass, mock_sign_path):
|
|||||||
== "http://192.168.123.123:8123/path?hello=world"
|
== "http://192.168.123.123:8123/path?hello=world"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Test skip signing URLs if they are known to require no auth
|
||||||
|
assert (
|
||||||
|
async_process_play_media_url(hass, "/api/tts_proxy/bla")
|
||||||
|
== "http://example.local:8123/api/tts_proxy/bla"
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
async_process_play_media_url(
|
||||||
|
hass, "http://example.local:8123/api/tts_proxy/bla"
|
||||||
|
)
|
||||||
|
== "http://example.local:8123/api/tts_proxy/bla"
|
||||||
|
)
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
async_process_play_media_url(hass, "hello")
|
async_process_play_media_url(hass, "hello")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user