From 96f82566f9d361b4057bd6245d4f34d3e6493b7f Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Sun, 18 May 2025 23:51:21 -0700 Subject: [PATCH 1/3] test(ssl bug repro): adds minimal repro test --- .../test_rest_aiohttp_ssl_verify.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/unit/openapi_support/test_rest_aiohttp_ssl_verify.py diff --git a/tests/unit/openapi_support/test_rest_aiohttp_ssl_verify.py b/tests/unit/openapi_support/test_rest_aiohttp_ssl_verify.py new file mode 100644 index 000000000..d41ffdbe6 --- /dev/null +++ b/tests/unit/openapi_support/test_rest_aiohttp_ssl_verify.py @@ -0,0 +1,22 @@ +import pytest +import asyncio +import os +import mock +from unittest.mock import patch, MagicMock +from pinecone import Pinecone +from pinecone.openapi_support.rest_aiohttp import AiohttpRestClient +from pinecone.config.openapi_configuration import Configuration + +@pytest.mark.asyncio +async def test_ssl_verify_false_causes_error(): + """Test that using ssl_verify=False causes an error due to the mutually exclusive + parameters in aiohttp.TCPConnector constructor.""" + + # Create a mock configuration with verify_ssl=False + config = Configuration() + config.verify_ssl = False + + # This will fail with ValueError because both verify_ssl and ssl parameters + # are passed to aiohttp.TCPConnector constructor + with pytest.raises(ValueError, match="verify_ssl, ssl_context, fingerprint and ssl parameters are mutually exclusive"): + rest_client = AiohttpRestClient(config) From 4a7a5bba065faaac9cea26fa87499860c3b4a92b Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Mon, 19 May 2025 19:53:40 -0700 Subject: [PATCH 2/3] fix(rest aiohttp): patch attempt --- pinecone/openapi_support/rest_aiohttp.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pinecone/openapi_support/rest_aiohttp.py b/pinecone/openapi_support/rest_aiohttp.py index 8b84e850a..8ce33fd9c 100644 --- a/pinecone/openapi_support/rest_aiohttp.py +++ b/pinecone/openapi_support/rest_aiohttp.py @@ -16,14 +16,15 @@ def __init__(self, configuration: Configuration) -> None: "Additional dependencies are required to use Pinecone with asyncio. Include these extra dependencies in your project by installing `pinecone[asyncio]`." ) from None - if configuration.ssl_ca_cert is not None: - ca_certs = configuration.ssl_ca_cert + if configuration.verify_ssl: + if configuration.ssl_ca_cert is not None: + ca_certs = configuration.ssl_ca_cert + else: + ca_certs = certifi.where() + ssl_context = ssl.create_default_context(cafile=ca_certs) + conn = aiohttp.TCPConnector(ssl=ssl_context) else: - ca_certs = certifi.where() - - ssl_context = ssl.create_default_context(cafile=ca_certs) - - conn = aiohttp.TCPConnector(verify_ssl=configuration.verify_ssl, ssl=ssl_context) + conn = aiohttp.TCPConnector(verify_ssl=False) if configuration.proxy: self._session = aiohttp.ClientSession(connector=conn, proxy=configuration.proxy) From c3f3696aa114c2d5e892494a61d8e17970f3b6fe Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Mon, 19 May 2025 20:09:25 -0700 Subject: [PATCH 3/3] test(rest aiohttp sll verify): inverts pass/fail --- .../openapi_support/test_rest_aiohttp_ssl_verify.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/unit/openapi_support/test_rest_aiohttp_ssl_verify.py b/tests/unit/openapi_support/test_rest_aiohttp_ssl_verify.py index d41ffdbe6..66295957c 100644 --- a/tests/unit/openapi_support/test_rest_aiohttp_ssl_verify.py +++ b/tests/unit/openapi_support/test_rest_aiohttp_ssl_verify.py @@ -16,7 +16,11 @@ async def test_ssl_verify_false_causes_error(): config = Configuration() config.verify_ssl = False - # This will fail with ValueError because both verify_ssl and ssl parameters - # are passed to aiohttp.TCPConnector constructor - with pytest.raises(ValueError, match="verify_ssl, ssl_context, fingerprint and ssl parameters are mutually exclusive"): + # Passes if no error is thrown, and fails if an error occurs + try: rest_client = AiohttpRestClient(config) + # If we get here, no error was thrown, so the test passes + assert True + except ValueError as e: + # If we get here, an error was thrown, so the test fails + pytest.fail(f"Expected no error but got: {str(e)}")