From fbbfd46fb831e06b96adef91edfed35295ae98fa Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 3 Sep 2020 18:13:33 +0200 Subject: [PATCH] Add .well-known/password-change (#39613) --- homeassistant/components/frontend/__init__.py | 4 ++++ homeassistant/components/http/__init__.py | 4 ++-- tests/components/frontend/test_init.py | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index 90089d50340..2a741afcfbc 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -284,6 +284,10 @@ async def async_setup(hass, config): hass.http.register_static_path( "/auth/authorize", str(root_path / "authorize.html"), False ) + # https://wicg.github.io/change-password-url/ + hass.http.register_redirect( + "/.well-known/change-password", "/profile", redirect_exc=web.HTTPFound + ) local = hass.config.path("www") if os.path.isdir(local): diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index cb0ecec8a2b..421b17e47cc 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -345,7 +345,7 @@ class HomeAssistantHTTP: view.register(self.app, self.app.router) - def register_redirect(self, url, redirect_to): + def register_redirect(self, url, redirect_to, *, redirect_exc=HTTPMovedPermanently): """Register a redirect with the server. If given this must be either a string or callable. In case of a @@ -357,7 +357,7 @@ class HomeAssistantHTTP: async def redirect(request): """Redirect to location.""" - raise HTTPMovedPermanently(redirect_to) + raise redirect_exc(redirect_to) self.app.router.add_route("GET", url, redirect) diff --git a/tests/components/frontend/test_init.py b/tests/components/frontend/test_init.py index 5e6bbe8b2d4..a7ecbb0e5fe 100644 --- a/tests/components/frontend/test_init.py +++ b/tests/components/frontend/test_init.py @@ -484,3 +484,12 @@ async def test_get_version(hass, hass_ws_client): assert msg["type"] == TYPE_RESULT assert msg["success"] assert msg["result"] == {"version": cur_version} + + +async def test_static_paths(hass, mock_http_client): + """Test static paths.""" + resp = await mock_http_client.get( + "/.well-known/change-password", allow_redirects=False + ) + assert resp.status == 302 + assert resp.headers["location"] == "/profile"