From 09765fe53dcc1f9cb8cd84d479a79cec88872e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Bregu=C5=82a?= Date: Wed, 25 Feb 2026 18:17:04 +0100 Subject: [PATCH] Fix AWS S3 config flow endpoint URL validation (#164085) Co-authored-by: mik-laj <12058428+mik-laj@users.noreply.github.com> --- homeassistant/components/aws_s3/config_flow.py | 5 ++--- tests/components/aws_s3/test_config_flow.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/aws_s3/config_flow.py b/homeassistant/components/aws_s3/config_flow.py index a4de192e513..3d8f3479aa3 100644 --- a/homeassistant/components/aws_s3/config_flow.py +++ b/homeassistant/components/aws_s3/config_flow.py @@ -60,9 +60,8 @@ class S3ConfigFlow(ConfigFlow, domain=DOMAIN): } ) - if not urlparse(user_input[CONF_ENDPOINT_URL]).hostname.endswith( - AWS_DOMAIN - ): + hostname = urlparse(user_input[CONF_ENDPOINT_URL]).hostname + if not hostname or not hostname.endswith(AWS_DOMAIN): errors[CONF_ENDPOINT_URL] = "invalid_endpoint_url" else: try: diff --git a/tests/components/aws_s3/test_config_flow.py b/tests/components/aws_s3/test_config_flow.py index 593eea5cdb9..58c634f6917 100644 --- a/tests/components/aws_s3/test_config_flow.py +++ b/tests/components/aws_s3/test_config_flow.py @@ -122,12 +122,19 @@ async def test_abort_if_already_configured( assert result["reason"] == "already_configured" +@pytest.mark.parametrize( + ("endpoint_url"), + [ + ("@@@"), + ("http://example.com"), + ], +) async def test_flow_create_not_aws_endpoint( - hass: HomeAssistant, + hass: HomeAssistant, endpoint_url: str ) -> None: """Test config flow with a not aws endpoint should raise an error.""" result = await _async_start_flow( - hass, USER_INPUT | {CONF_ENDPOINT_URL: "http://example.com"} + hass, USER_INPUT | {CONF_ENDPOINT_URL: endpoint_url} ) assert result["type"] is FlowResultType.FORM