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