@@ -207,7 +207,7 @@ async def test_ocsp_wo_cache_file(session_manager):
207207 OCSPCache .reset_cache_dir ()
208208
209209
210- async def test_ocsp_fail_open_w_single_endpoint (session_manager ):
210+ async def test_ocsp_fail_open_w_single_endpoint (session_manager , monkeypatch ):
211211 SnowflakeOCSP .clear_cache ()
212212
213213 try :
@@ -216,33 +216,28 @@ async def test_ocsp_fail_open_w_single_endpoint(session_manager):
216216 # File doesn't exist, which is fine for this test
217217 pass
218218
219- environ [ "SF_OCSP_TEST_MODE" ] = "true"
220- environ [ "SF_TEST_OCSP_URL" ] = "http://httpbin.org/delay/10"
221- environ [ "SF_TEST_CA_OCSP_RESPONDER_CONNECTION_TIMEOUT" ] = "5"
219+ monkeypatch . setenv ( "SF_OCSP_TEST_MODE" , "true" )
220+ monkeypatch . setenv ( "SF_TEST_OCSP_URL" , "http://httpbin.org/delay/10" )
221+ monkeypatch . setenv ( "SF_TEST_CA_OCSP_RESPONDER_CONNECTION_TIMEOUT" , "5" )
222222
223223 ocsp = SFOCSP (use_ocsp_cache_server = False )
224224
225- try :
226- async with _asyncio_connect ("snowflake.okta.com" ) as connection :
227- assert await ocsp .validate (
228- "snowflake.okta.com" , connection , session_manager = session_manager
229- ), "Failed to validate: {}" .format ("snowflake.okta.com" )
230- finally :
231- del environ ["SF_OCSP_TEST_MODE" ]
232- del environ ["SF_TEST_OCSP_URL" ]
233- del environ ["SF_TEST_CA_OCSP_RESPONDER_CONNECTION_TIMEOUT" ]
225+ async with _asyncio_connect ("snowflake.okta.com" ) as connection :
226+ assert await ocsp .validate (
227+ "snowflake.okta.com" , connection , session_manager = session_manager
228+ ), "Failed to validate: {}" .format ("snowflake.okta.com" )
234229
235230
236231@pytest .mark .skipif (
237232 ER_OCSP_RESPONSE_CERT_STATUS_REVOKED is None ,
238233 reason = "No ER_OCSP_RESPONSE_CERT_STATUS_REVOKED is available." ,
239234)
240- async def test_ocsp_fail_close_w_single_endpoint (session_manager ):
235+ async def test_ocsp_fail_close_w_single_endpoint (session_manager , monkeypatch ):
241236 SnowflakeOCSP .clear_cache ()
242237
243- environ [ "SF_OCSP_TEST_MODE" ] = "true"
244- environ [ "SF_TEST_OCSP_URL" ] = "http://httpbin.org/delay/10"
245- environ [ "SF_TEST_CA_OCSP_RESPONDER_CONNECTION_TIMEOUT" ] = "5"
238+ monkeypatch . setenv ( "SF_OCSP_TEST_MODE" , "true" )
239+ monkeypatch . setenv ( "SF_TEST_OCSP_URL" , "http://httpbin.org/delay/10" )
240+ monkeypatch . setenv ( "SF_TEST_CA_OCSP_RESPONDER_CONNECTION_TIMEOUT" , "5" )
246241
247242 OCSPCache .del_cache_file ()
248243
@@ -254,21 +249,16 @@ async def test_ocsp_fail_close_w_single_endpoint(session_manager):
254249 "snowflake.okta.com" , connection , session_manager = session_manager
255250 )
256251
257- try :
258- assert (
259- ex .value .errno == ER_OCSP_RESPONSE_FETCH_FAILURE
260- ), "Connection should have failed"
261- finally :
262- del environ ["SF_OCSP_TEST_MODE" ]
263- del environ ["SF_TEST_OCSP_URL" ]
264- del environ ["SF_TEST_CA_OCSP_RESPONDER_CONNECTION_TIMEOUT" ]
252+ assert (
253+ ex .value .errno == ER_OCSP_RESPONSE_FETCH_FAILURE
254+ ), "Connection should have failed"
265255
266256
267- async def test_ocsp_bad_validity (session_manager ):
257+ async def test_ocsp_bad_validity (session_manager , monkeypatch ):
268258 SnowflakeOCSP .clear_cache ()
269259
270- environ [ "SF_OCSP_TEST_MODE" ] = "true"
271- environ [ "SF_TEST_OCSP_FORCE_BAD_RESPONSE_VALIDITY" ] = "true"
260+ monkeypatch . setenv ( "SF_OCSP_TEST_MODE" , "true" )
261+ monkeypatch . setenv ( "SF_TEST_OCSP_FORCE_BAD_RESPONSE_VALIDITY" , "true" )
272262
273263 try :
274264 OCSPCache .del_cache_file ()
@@ -282,12 +272,10 @@ async def test_ocsp_bad_validity(session_manager):
282272 assert await ocsp .validate (
283273 "snowflake.okta.com" , connection , session_manager = session_manager
284274 ), "Connection should have passed with fail open"
285- del environ ["SF_OCSP_TEST_MODE" ]
286- del environ ["SF_TEST_OCSP_FORCE_BAD_RESPONSE_VALIDITY" ]
287275
288276
289- async def test_ocsp_single_endpoint (session_manager ):
290- environ [ "SF_OCSP_ACTIVATE_NEW_ENDPOINT" ] = "True"
277+ async def test_ocsp_single_endpoint (session_manager , monkeypatch ):
278+ monkeypatch . setenv ( "SF_OCSP_ACTIVATE_NEW_ENDPOINT" , "True" )
291279 SnowflakeOCSP .clear_cache ()
292280 ocsp = SFOCSP ()
293281 ocsp .OCSP_CACHE_SERVER .NEW_DEFAULT_CACHE_SERVER_BASE_URL = "https://snowflake.preprod3.us-west-2-dev.external-zone.snowflakecomputing.com:8085/ocsp/"
@@ -296,8 +284,6 @@ async def test_ocsp_single_endpoint(session_manager):
296284 "snowflake.okta.com" , connection , session_manager = session_manager
297285 ), "Failed to validate: {}" .format ("snowflake.okta.com" )
298286
299- del environ ["SF_OCSP_ACTIVATE_NEW_ENDPOINT" ]
300-
301287
302288async def test_ocsp_by_post_method (session_manager ):
303289 """OCSP tests."""
@@ -327,7 +313,7 @@ async def test_ocsp_with_file_cache(tmpdir, session_manager):
327313
328314
329315async def test_ocsp_with_bogus_cache_files (
330- tmpdir , random_ocsp_response_validation_cache , session_manager
316+ tmpdir , random_ocsp_response_validation_cache , session_manager , monkeypatch
331317):
332318 with mock .patch (
333319 "snowflake.connector.ocsp_snowflake.OCSP_RESPONSE_VALIDATION_CACHE" ,
@@ -337,7 +323,7 @@ async def test_ocsp_with_bogus_cache_files(
337323
338324 """Attempts to use bogus OCSP response data."""
339325 cache_file_name , target_hosts = await _store_cache_in_file (
340- tmpdir , session_manager
326+ tmpdir , session_manager , monkeypatch = monkeypatch
341327 )
342328
343329 ocsp = SFOCSP ()
@@ -369,7 +355,7 @@ async def test_ocsp_with_bogus_cache_files(
369355
370356
371357async def test_ocsp_with_outdated_cache (
372- tmpdir , random_ocsp_response_validation_cache , session_manager
358+ tmpdir , random_ocsp_response_validation_cache , session_manager , monkeypatch
373359):
374360 with mock .patch (
375361 "snowflake.connector.ocsp_snowflake.OCSP_RESPONSE_VALIDATION_CACHE" ,
@@ -379,7 +365,7 @@ async def test_ocsp_with_outdated_cache(
379365
380366 """Attempts to use outdated OCSP response cache file."""
381367 cache_file_name , target_hosts = await _store_cache_in_file (
382- tmpdir , session_manager
368+ tmpdir , session_manager , monkeypatch = monkeypatch
383369 )
384370
385371 ocsp = SFOCSP ()
@@ -410,10 +396,10 @@ async def test_ocsp_with_outdated_cache(
410396 ), "must be empty. outdated cache should not be loaded"
411397
412398
413- async def _store_cache_in_file (tmpdir , session_manager , target_hosts = None ):
399+ async def _store_cache_in_file (tmpdir , session_manager , monkeypatch , target_hosts = None ):
414400 if target_hosts is None :
415401 target_hosts = TARGET_HOSTS
416- os . environ [ "SF_OCSP_RESPONSE_CACHE_DIR" ] = str (tmpdir )
402+ monkeypatch . setenv ( "SF_OCSP_RESPONSE_CACHE_DIR" , str (tmpdir ) )
417403 OCSPCache .reset_cache_dir ()
418404 filename = path .join (str (tmpdir ), "ocsp_response_cache.json" )
419405
0 commit comments