From 110ee9ff35481b429107adfb2c36051743d97b47 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 19 Aug 2024 16:06:20 +0200 Subject: [PATCH] Strip trailing / from OTBR url (#124223) --- homeassistant/components/otbr/config_flow.py | 4 ++-- tests/components/otbr/test_config_flow.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/otbr/config_flow.py b/homeassistant/components/otbr/config_flow.py index 8342a965bd308..c13a3f36f9992 100644 --- a/homeassistant/components/otbr/config_flow.py +++ b/homeassistant/components/otbr/config_flow.py @@ -111,7 +111,7 @@ async def async_step_user( errors = {} if user_input is not None: - url = user_input[CONF_URL] + url = user_input[CONF_URL].rstrip("/") try: await self._connect_and_set_dataset(url) except ( @@ -124,7 +124,7 @@ async def async_step_user( await self.async_set_unique_id(DOMAIN) return self.async_create_entry( title="Open Thread Border Router", - data=user_input, + data={CONF_URL: url}, ) data_schema = vol.Schema({CONF_URL: str}) diff --git a/tests/components/otbr/test_config_flow.py b/tests/components/otbr/test_config_flow.py index 224f77931e5a3..b3f829eb4f019 100644 --- a/tests/components/otbr/test_config_flow.py +++ b/tests/components/otbr/test_config_flow.py @@ -49,17 +49,25 @@ def addon_info_fixture(): yield addon_info +@pytest.mark.parametrize( + "url", + [ + "http://custom_url:1234", + "http://custom_url:1234/", + "http://custom_url:1234//", + ], +) async def test_user_flow( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, url: str ) -> None: """Test the user flow.""" - url = "http://custom_url:1234" - aioclient_mock.get(f"{url}/node/dataset/active", text="aa") + stripped_url = "http://custom_url:1234" + aioclient_mock.get(f"{stripped_url}/node/dataset/active", text="aa") result = await hass.config_entries.flow.async_init( otbr.DOMAIN, context={"source": "user"} ) - expected_data = {"url": url} + expected_data = {"url": stripped_url} assert result["type"] is FlowResultType.FORM assert result["errors"] == {}