diff --git a/tests/app/aws/test_s3.py b/tests/app/aws/test_s3.py index fe838cd1f..8d5e4eec3 100644 --- a/tests/app/aws/test_s3.py +++ b/tests/app/aws/test_s3.py @@ -603,15 +603,36 @@ def test_get_s3_files_handles_exception(mocker): ) -def test_get_s3_client_with_env_credentials(): +def test_get_s3_client_default_credentials(): + with patch.dict(os.environ, {}, clear=True): + client = get_s3_client() + assert client is not None, "Client should be created with default credentials" + assert client.client_config.region_name, "Client should have a region" + + +def test_get_s3_client_invalid_credentials(): with patch.dict( os.environ, { - "AWS_ACCESS_KEY_ID": "test-key", - "AWS_SECRET_ACCESS_KEY": "test-sekret", # pragma: allowlist secret + "AWS_ACCESS_KEY_ID": "invalid-key", + "AWS_SECRET_ACCESS_KEY": "invalid-secret", # pragma: allowlist secret "AWS_DEFAULT_REGION": "us-north-1", }, ): - client = get_s3_client() - assert client is not None, "Client should be created with env credentials" - assert client._client_config.region_name == "us-north-1" + with patch( + "boto3.client", + side_effect=botocore.exceptions.ClientError( + { + "Error": { + "Code": "InvalidClientTokenId", + "Message": "Invalid credentials", + } + }, + "HeadBucket", + ), + ): + try: + get_s3_client() + assert 1 == 0, "Should raise ClientError for invalid credentials" + except botocore.exceptions.ClientError as e: + assert e.response["Error"]["Code"] == "InvalidClientTokenId"