Skip signing URL that we know requires no auth (#71208)
This commit is contained in:
parent
0cdcdec809
commit
0926470ef0
2 changed files with 19 additions and 0 deletions
|
@ -20,6 +20,9 @@ from homeassistant.helpers.network import (
|
|||
|
||||
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
|
||||
def async_process_play_media_url(
|
||||
|
@ -46,6 +49,10 @@ def async_process_play_media_url(
|
|||
logging.getLogger(__name__).debug(
|
||||
"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:
|
||||
signed_path = async_sign_path(
|
||||
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"
|
||||
)
|
||||
|
||||
# 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):
|
||||
async_process_play_media_url(hass, "hello")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue