Skip to content

Commit

Permalink
Strip trailing / from OTBR url (#124223)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Aug 19, 2024
1 parent c76d685 commit 110ee9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/otbr/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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})
Expand Down
16 changes: 12 additions & 4 deletions tests/components/otbr/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] == {}
Expand Down

0 comments on commit 110ee9f

Please sign in to comment.