From 81444c8f4a500d085d93d6142958c7a84049285d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Bed=C5=99ich?= Date: Fri, 2 May 2025 13:49:33 +0200 Subject: [PATCH] Disable S3 checksums (#144092) Disable S3 checksums (#143995) --- homeassistant/components/s3/__init__.py | 7 +++++++ tests/components/s3/test_init.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/homeassistant/components/s3/__init__.py b/homeassistant/components/s3/__init__.py index 95e5e7d738c..ea6b8e244b1 100644 --- a/homeassistant/components/s3/__init__.py +++ b/homeassistant/components/s3/__init__.py @@ -7,6 +7,7 @@ from typing import cast from aiobotocore.client import AioBaseClient as S3Client from aiobotocore.session import AioSession +from botocore.config import Config from botocore.exceptions import ClientError, ConnectionError, ParamValidationError from homeassistant.config_entries import ConfigEntry @@ -32,6 +33,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: S3ConfigEntry) -> bool: """Set up S3 from a config entry.""" data = cast(dict, entry.data) + # due to https://github.com/home-assistant/core/issues/143995 + config = Config( + request_checksum_calculation="when_required", + response_checksum_validation="when_required", + ) try: session = AioSession() # pylint: disable-next=unnecessary-dunder-call @@ -40,6 +46,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: S3ConfigEntry) -> bool: endpoint_url=data.get(CONF_ENDPOINT_URL), aws_secret_access_key=data[CONF_SECRET_ACCESS_KEY], aws_access_key_id=data[CONF_ACCESS_KEY_ID], + config=config, ).__aenter__() await client.head_bucket(Bucket=data[CONF_BUCKET]) except ClientError as err: diff --git a/tests/components/s3/test_init.py b/tests/components/s3/test_init.py index afa11f5cf72..8255bbd0c66 100644 --- a/tests/components/s3/test_init.py +++ b/tests/components/s3/test_init.py @@ -2,6 +2,7 @@ from unittest.mock import AsyncMock, patch +from botocore.config import Config from botocore.exceptions import ( ClientError, EndpointConnectionError, @@ -73,3 +74,19 @@ async def test_setup_entry_head_bucket_error( ) await setup_integration(hass, mock_config_entry) assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR + + +async def test_checksum_settings_present( + hass: HomeAssistant, mock_config_entry: MockConfigEntry +) -> None: + """Test that checksum validation is set to be compatible with third-party S3 providers.""" + # due to https://github.com/home-assistant/core/issues/143995 + with patch( + "homeassistant.components.s3.AioSession.create_client" + ) as mock_create_client: + await setup_integration(hass, mock_config_entry) + + config_arg = mock_create_client.call_args[1]["config"] + assert isinstance(config_arg, Config) + assert config_arg.request_checksum_calculation == "when_required" + assert config_arg.response_checksum_validation == "when_required"