Normalize url entered in fibaro integration setup dialog (#81996)

* Normalize url entered in fibaro integration setup dialog

* Improvements as suggested in code review

* Fix spelling in comments
This commit is contained in:
rappenze 2022-11-16 10:44:34 +01:00 committed by GitHub
parent 93401df73f
commit ff1ec7a028
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View file

@ -6,6 +6,7 @@ import pytest
from homeassistant import config_entries
from homeassistant.components.fibaro import DOMAIN
from homeassistant.components.fibaro.config_flow import _normalize_url
from homeassistant.components.fibaro.const import CONF_IMPORT_PLUGINS
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME
@ -362,3 +363,23 @@ async def test_reauth_auth_failure(hass):
assert result["type"] == "form"
assert result["step_id"] == "reauth_confirm"
assert result["errors"] == {"base": "invalid_auth"}
async def test_normalize_url_does_not_touch_valid_url():
"""Test that a correctly entered url is not touched."""
assert _normalize_url(TEST_URL) == TEST_URL
async def test_normalize_url_add_missing_slash_at_the_end():
"""Test that a / is added at the end."""
assert _normalize_url("http://192.168.1.1/api") == "http://192.168.1.1/api/"
async def test_normalize_url_add_api():
"""Test that api/ is added."""
assert _normalize_url("http://192.168.1.1/") == "http://192.168.1.1/api/"
async def test_normalize_url_add_api_with_leading_slash():
"""Test that /api/ is added."""
assert _normalize_url("http://192.168.1.1") == "http://192.168.1.1/api/"