Skip to content

Commit df35306

Browse files
fixup! NO-SNOW: Add more tests for async crl
1 parent 2fa8873 commit df35306

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/snowflake/connector/aio/_session_manager.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from ..crl import CertRevocationCheckMode, CRLValidator
1515
from ..errorcode import ER_OCSP_RESPONSE_CERT_STATUS_REVOKED
1616
from ..ssl_wrap_socket import (
17-
FEATURE_CRL_CONFIG,
1817
FEATURE_OCSP_RESPONSE_CACHE_FILE_NAME,
18+
get_feature_crl_config,
1919
load_trusted_certificates,
2020
resolve_cafile,
2121
)
@@ -79,15 +79,16 @@ async def connect(
7979
connection = await super().connect(req, traces, timeout)
8080
protocol = connection.protocol
8181

82+
feature_crl_config = get_feature_crl_config()
8283
logger.debug(
8384
"CRL Check Mode: %s",
84-
FEATURE_CRL_CONFIG.cert_revocation_check_mode.name,
85+
feature_crl_config.cert_revocation_check_mode.name,
8586
)
8687
if (
87-
FEATURE_CRL_CONFIG.cert_revocation_check_mode
88+
feature_crl_config.cert_revocation_check_mode
8889
!= CertRevocationCheckMode.DISABLED
8990
):
90-
self.validate_crl(protocol, req)
91+
self.validate_crl(feature_crl_config, protocol, req)
9192
logger.debug(
9293
"The certificate revocation check was successful. No additional checks will be performed."
9394
)
@@ -111,11 +112,13 @@ async def connect(
111112
protocol._snowflake_ocsp_validated = True
112113
return connection
113114

114-
def validate_crl(self, protocol: ResponseHandler, req: ClientRequest):
115+
def validate_crl(
116+
self, feature_crl_config, protocol: ResponseHandler, req: ClientRequest
117+
):
115118
# Resolve CA file path from environment variables or use certifi default
116119
cafile_for_ctx = resolve_cafile({"ca_certs": certifi.where()})
117120
crl_validator = CRLValidator.from_config(
118-
FEATURE_CRL_CONFIG,
121+
feature_crl_config,
119122
self._session_manager,
120123
trusted_certificates=load_trusted_certificates(cafile_for_ctx),
121124
)

src/snowflake/connector/ssl_wrap_socket.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,7 @@ def _openssl_connect(
271271
time.sleep(sleeping_time)
272272
if err:
273273
raise err
274+
275+
276+
def get_feature_crl_config() -> CRLConfig:
277+
return FEATURE_CRL_CONFIG

test/integ/aio_it/test_crl_async.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import pytest
1313

14+
from snowflake.connector.ssl_wrap_socket import get_feature_crl_config
15+
1416

1517
@pytest.mark.skipolddriver
1618
async def test_crl_validation_enabled_mode(conn_cnx):
@@ -25,6 +27,10 @@ async def test_crl_validation_enabled_mode(conn_cnx):
2527
disable_ocsp_checks=True,
2628
) as cnx:
2729
assert cnx, "Connection should succeed with CRL validation in ENABLED mode"
30+
assert (
31+
get_feature_crl_config().cert_revocation_check_mode.value
32+
== cnx.cert_revocation_check_mode
33+
)
2834

2935
# Verify we can execute a simple query
3036
cur = cnx.cursor()
@@ -51,6 +57,10 @@ async def test_crl_validation_advisory_mode(conn_cnx):
5157
crl_cache_validity_hours=1, # Cache for 1 hour
5258
) as cnx:
5359
assert cnx, "Connection should succeed with CRL validation in ADVISORY mode"
60+
assert (
61+
get_feature_crl_config().cert_revocation_check_mode.value
62+
== cnx.cert_revocation_check_mode
63+
)
5464

5565
# Verify we can execute a simple query
5666
cur = cnx.cursor()
@@ -77,6 +87,10 @@ async def test_crl_validation_disabled_mode(conn_cnx):
7787
cert_revocation_check_mode="DISABLED",
7888
) as cnx:
7989
assert cnx, "Connection should succeed with CRL validation in DISABLED mode"
90+
assert (
91+
get_feature_crl_config().cert_revocation_check_mode.value
92+
== cnx.cert_revocation_check_mode
93+
)
8094

8195
# Verify we can execute a simple query
8296
cur = cnx.cursor()
@@ -112,6 +126,10 @@ async def test_crl_validation_modes_parametrized(
112126
crl_connection_timeout_ms=5000,
113127
crl_read_timeout_ms=5000,
114128
) as cnx:
129+
assert (
130+
get_feature_crl_config().cert_revocation_check_mode.value
131+
== cnx.cert_revocation_check_mode
132+
)
115133
if should_succeed:
116134
assert (
117135
cnx

0 commit comments

Comments
 (0)