Skip to content

Commit 2f09c11

Browse files
will single test cause issues
1 parent ec70889 commit 2f09c11

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/snowflake/connector/aio/_connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,7 @@ async def connect(self, **kwargs) -> None:
10631063
proxy_password=self.proxy_password,
10641064
snowflake_ocsp_mode=self._ocsp_mode(),
10651065
ocsp_root_certs_dict_lock_timeout=self._ocsp_root_certs_dict_lock_timeout,
1066+
ocsp_response_cache_file_name=self._ocsp_response_cache_filename,
10661067
trust_env=True, # Required for proxy support via environment variables
10671068
)
10681069
self._session_manager = SessionManagerFactory.get_manager(self._http_config)

src/snowflake/connector/aio/_session_manager.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from .. import OperationalError
1313
from ..constants import OCSP_ROOT_CERTS_DICT_LOCK_TIMEOUT_DEFAULT_NO_TIMEOUT
1414
from ..errorcode import ER_OCSP_RESPONSE_CERT_STATUS_REVOKED
15-
from ..ssl_wrap_socket import FEATURE_OCSP_RESPONSE_CACHE_FILE_NAME
1615
from ._ocsp_asn1crypto import SnowflakeOCSPAsn1Crypto
1716

1817
if TYPE_CHECKING:
@@ -47,10 +46,12 @@ def __init__(
4746
snowflake_ocsp_mode: OCSPMode = OCSPMode.FAIL_OPEN,
4847
session_manager: SessionManager | None = None,
4948
ocsp_root_certs_dict_lock_timeout: int = OCSP_ROOT_CERTS_DICT_LOCK_TIMEOUT_DEFAULT_NO_TIMEOUT,
49+
ocsp_response_cache_file_name: str | None = None,
5050
**kwargs,
5151
):
5252
self._snowflake_ocsp_mode = snowflake_ocsp_mode
5353
self._ocsp_root_certs_dict_lock_timeout = ocsp_root_certs_dict_lock_timeout
54+
self._ocsp_response_cache_file_name = ocsp_response_cache_file_name
5455
if session_manager is None:
5556
logger.warning(
5657
"SessionManager instance was not passed to SSLConnector - OCSP will use default settings which may be distinct from the customer's specific one. Code should always pass such instance - verify why it isn't true in the current context"
@@ -102,12 +103,14 @@ async def validate_ocsp(
102103
):
103104

104105
v = await SnowflakeOCSPAsn1Crypto(
105-
ocsp_response_cache_uri=FEATURE_OCSP_RESPONSE_CACHE_FILE_NAME,
106+
ocsp_response_cache_uri=self._ocsp_response_cache_file_name,
106107
use_fail_open=self._snowflake_ocsp_mode == OCSPMode.FAIL_OPEN,
107108
hostname=hostname,
108109
root_certs_dict_lock_timeout=self._ocsp_root_certs_dict_lock_timeout,
109110
).validate(hostname, protocol, session_manager=session_manager)
110-
if not v:
111+
# In fail_open mode, if validation returns None (certificate extraction failed),
112+
# allow the connection to proceed. Otherwise, raise an error.
113+
if not v and self._snowflake_ocsp_mode != OCSPMode.FAIL_OPEN:
111114
raise OperationalError(
112115
msg=(
113116
"The certificate is revoked or "
@@ -147,6 +150,7 @@ class AioHttpConfig(BaseHttpConfig):
147150
ocsp_root_certs_dict_lock_timeout: int = (
148151
OCSP_ROOT_CERTS_DICT_LOCK_TIMEOUT_DEFAULT_NO_TIMEOUT
149152
)
153+
ocsp_response_cache_file_name: str | None = None
150154

151155
trust_env: bool = True
152156
"""Trust environment variables for proxy configuration (HTTP_PROXY, HTTPS_PROXY, NO_PROXY).
@@ -161,7 +165,11 @@ def get_connector(
161165
# We pass here only chosen attributes as kwargs to make the arguments received by the factory as compliant with the BaseConnector constructor interface as possible.
162166
# We could consider passing the whole HttpConfig as kwarg to the factory if necessary in the future.
163167
attributes_for_connector_factory = frozenset(
164-
{"snowflake_ocsp_mode", "ocsp_root_certs_dict_lock_timeout"}
168+
{
169+
"snowflake_ocsp_mode",
170+
"ocsp_root_certs_dict_lock_timeout",
171+
"ocsp_response_cache_file_name",
172+
}
165173
)
166174

167175
self_kwargs_for_connector_factory = {

src/snowflake/connector/ssl_wrap_socket.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ def ssl_wrap_socket_with_ocsp(*args: Any, **kwargs: Any) -> WrappedSocket:
184184
hostname=server_hostname,
185185
root_certs_dict_lock_timeout=FEATURE_ROOT_CERTS_DICT_LOCK_TIMEOUT,
186186
).validate(server_hostname, ret.connection)
187-
if not v:
187+
# In fail_open mode, if validation returns None (certificate extraction failed),
188+
# allow the connection to proceed. Otherwise, raise an error.
189+
if not v and FEATURE_OCSP_MODE != OCSPMode.FAIL_OPEN:
188190
raise OperationalError(
189191
msg=f"The certificate is revoked or could not be validated: hostname={server_hostname}",
190192
errno=ER_OCSP_RESPONSE_CERT_STATUS_REVOKED,

test/unit/aio/test_session_manager_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ def mock_connector_with_factory():
373373
"pool_connections": 10,
374374
"snowflake_ocsp_mode": OCSPMode.FAIL_OPEN,
375375
"ocsp_root_certs_dict_lock_timeout": -1,
376+
"ocsp_response_cache_file_name": None,
376377
},
377378
),
378379
# Test with OCSPMode.FAIL_CLOSED + no extra kwargs
@@ -382,6 +383,7 @@ def mock_connector_with_factory():
382383
{
383384
"snowflake_ocsp_mode": OCSPMode.FAIL_CLOSED,
384385
"ocsp_root_certs_dict_lock_timeout": -1,
386+
"ocsp_response_cache_file_name": None,
385387
},
386388
),
387389
# Checks that None values also cause kwargs name to occur
@@ -391,6 +393,7 @@ def mock_connector_with_factory():
391393
{
392394
"snowflake_ocsp_mode": None,
393395
"ocsp_root_certs_dict_lock_timeout": -1,
396+
"ocsp_response_cache_file_name": None,
394397
},
395398
),
396399
# Test override by extra kwargs: config has FAIL_OPEN but extra_kwargs override with FAIL_CLOSED
@@ -400,6 +403,7 @@ def mock_connector_with_factory():
400403
{
401404
"snowflake_ocsp_mode": OCSPMode.FAIL_CLOSED,
402405
"ocsp_root_certs_dict_lock_timeout": -1,
406+
"ocsp_response_cache_file_name": None,
403407
},
404408
),
405409
],

0 commit comments

Comments
 (0)