Allow non-authenticated calls to supervisor logs during onboarding (#40617)

This commit is contained in:
Joakim Sørensen 2020-09-28 10:10:10 +02:00 committed by GitHub
parent 373a1cabe6
commit 953f6bad46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -34,6 +34,10 @@ NO_TIMEOUT = re.compile(
r")$"
)
NO_AUTH_ONBOARDING = re.compile(
r"^(?:" r"|supervisor/logs" r"|snapshots/[^/]+/.+" r")$"
)
NO_AUTH = re.compile(
r"^(?:" r"|app/.*" r"|addons/[^/]+/logo" r"|addons/[^/]+/icon" r")$"
)
@ -149,7 +153,7 @@ def _get_timeout(path: str) -> int:
def _need_auth(hass, path: str) -> bool:
"""Return if a path need authentication."""
if not async_is_onboarded(hass) and path.startswith("snapshots"):
if not async_is_onboarded(hass) and NO_AUTH_ONBOARDING.match(path):
return False
if NO_AUTH.match(path):
return False

View file

@ -155,6 +155,8 @@ def test_need_auth(hass):
"""Test if the requested path needs authentication."""
assert not _need_auth(hass, "addons/test/logo")
assert _need_auth(hass, "snapshots/new/upload")
assert _need_auth(hass, "supervisor/logs")
hass.data["onboarding"] = False
assert not _need_auth(hass, "snapshots/new/upload")
assert not _need_auth(hass, "supervisor/logs")