Skip to content

Commit e5ab675

Browse files
smtakedaankit-bhatnagar167
authored andcommitted
SNOW-63266: Added unit test for OCSP retry URL
1 parent e784694 commit e5ab675

File tree

2 files changed

+102
-10
lines changed

2 files changed

+102
-10
lines changed

ocsp_snowflake.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,28 @@ def _reset_ocsp_dynamic_cache_server_url():
178178
# only if custom OCSP cache server is used.
179179
parsed_url = urlsplit(
180180
OCSPCache.CACHE_SERVER_URL)
181-
if parsed_url.port:
182-
OCSPCache.RETRY_URL_PATTERN = \
183-
u"{0}://{1}:{2}/retry/".format(
184-
parsed_url.scheme, parsed_url.hostname,
185-
parsed_url.port) + u"{0}/{1}"
181+
if not OCSPCache.ACTIVATE_SSD:
182+
if parsed_url.port:
183+
OCSPCache.RETRY_URL_PATTERN = \
184+
u"{0}://{1}:{2}/retry/".format(
185+
parsed_url.scheme, parsed_url.hostname,
186+
parsed_url.port) + u"{0}/{1}"
187+
else:
188+
OCSPCache.RETRY_URL_PATTERN = \
189+
u"{0}://{1}/retry/".format(
190+
parsed_url.scheme, parsed_url.hostname) + u"{0}/{1}"
186191
else:
187-
OCSPCache.RETRY_URL_PATTERN = \
188-
u"{0}://{1}/retry/".format(
189-
parsed_url.scheme, parsed_url.hostname) + u"{0}/{1}"
190-
elif \
191-
OCSPCache.ACTIVATE_SSD:
192+
if parsed_url.port:
193+
OCSPCache.RETRY_URL_PATTERN = \
194+
u"{0}://{1}:{2}/retry".format(
195+
parsed_url.scheme, parsed_url.hostname,
196+
parsed_url.port)
197+
else:
198+
OCSPCache.RETRY_URL_PATTERN = \
199+
u"{0}://{1}/retry".format(
200+
parsed_url.scheme, parsed_url.hostname)
201+
202+
elif OCSPCache.ACTIVATE_SSD:
192203
OCSPCache.RETRY_URL_PATTERN = OCSPCache.DEFAULT_RETRY_URL
193204

194205
logger.debug(

test/test_unit_ocsp.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# encoding=utf-8
2+
# !/usr/bin/env python
3+
#
4+
# Copyright (c) 2012-2019 Snowflake Computing Inc. All right reserved.
5+
#
6+
7+
from snowflake.connector.ocsp_snowflake import OCSPCache
8+
9+
10+
def test_building_retry_url():
11+
# privatelink retry url
12+
OCSPCache.ACTIVATE_SSD = False
13+
OCSPCache.RETRY_URL_PATTERN = None
14+
OCSPCache.CACHE_SERVER_URL = \
15+
'http://ocsp.us-east-1.snowflakecomputing.com/ocsp_response_cache.json'
16+
OCSPCache._reset_ocsp_dynamic_cache_server_url()
17+
assert OCSPCache.RETRY_URL_PATTERN == \
18+
'http://ocsp.us-east-1.snowflakecomputing.com/retry/{0}/{1}'
19+
20+
# privatelink retry url with port
21+
OCSPCache.ACTIVATE_SSD = False
22+
OCSPCache.RETRY_URL_PATTERN = None
23+
OCSPCache.CACHE_SERVER_URL = \
24+
'http://ocsp.us-east-1.snowflakecomputing.com:80/ocsp_response_cache' \
25+
'.json'
26+
OCSPCache._reset_ocsp_dynamic_cache_server_url()
27+
assert OCSPCache.RETRY_URL_PATTERN == \
28+
'http://ocsp.us-east-1.snowflakecomputing.com:80/retry/{0}/{1}'
29+
30+
# non-privatelink retry url
31+
OCSPCache.ACTIVATE_SSD = False
32+
OCSPCache.RETRY_URL_PATTERN = None
33+
OCSPCache.CACHE_SERVER_URL = \
34+
'http://ocsp.snowflakecomputing.com/ocsp_response_cache.json'
35+
OCSPCache._reset_ocsp_dynamic_cache_server_url()
36+
assert OCSPCache.RETRY_URL_PATTERN is None
37+
38+
# non-privatelink retry url with port
39+
OCSPCache.ACTIVATE_SSD = False
40+
OCSPCache.RETRY_URL_PATTERN = None
41+
OCSPCache.CACHE_SERVER_URL = \
42+
'http://ocsp.snowflakecomputing.com:80/ocsp_response_cache.json'
43+
OCSPCache._reset_ocsp_dynamic_cache_server_url()
44+
assert OCSPCache.RETRY_URL_PATTERN is None
45+
46+
# ssd enabled for privatelink retry url
47+
OCSPCache.ACTIVATE_SSD = True
48+
OCSPCache.RETRY_URL_PATTERN = None
49+
OCSPCache.CACHE_SERVER_URL = \
50+
'http://ocsp.us-east-1.snowflakecomputing.com/ocsp_response_cache.json'
51+
OCSPCache._reset_ocsp_dynamic_cache_server_url()
52+
assert OCSPCache.RETRY_URL_PATTERN == \
53+
'http://ocsp.us-east-1.snowflakecomputing.com/retry'
54+
55+
# ssd enabled for privatelink retry url with port
56+
OCSPCache.ACTIVATE_SSD = True
57+
OCSPCache.RETRY_URL_PATTERN = None
58+
OCSPCache.CACHE_SERVER_URL = \
59+
'http://ocsp.us-east-1.snowflakecomputing.com:80/ocsp_response_cache' \
60+
'.json'
61+
OCSPCache._reset_ocsp_dynamic_cache_server_url()
62+
assert OCSPCache.RETRY_URL_PATTERN == \
63+
'http://ocsp.us-east-1.snowflakecomputing.com:80/retry'
64+
65+
# ssd enabled for non-privatelink
66+
OCSPCache.ACTIVATE_SSD = True
67+
OCSPCache.RETRY_URL_PATTERN = None
68+
OCSPCache.CACHE_SERVER_URL = \
69+
'http://ocsp.snowflakecomputing.com/ocsp_response_cache.json'
70+
OCSPCache._reset_ocsp_dynamic_cache_server_url()
71+
assert OCSPCache.RETRY_URL_PATTERN == \
72+
'http://ocsp.snowflakecomputing.com/retry'
73+
74+
# ssd enabled for non-privatelink with port
75+
OCSPCache.ACTIVATE_SSD = True
76+
OCSPCache.RETRY_URL_PATTERN = None
77+
OCSPCache.CACHE_SERVER_URL = \
78+
'http://ocsp.snowflakecomputing.com:80/ocsp_response_cache.json'
79+
OCSPCache._reset_ocsp_dynamic_cache_server_url()
80+
assert OCSPCache.RETRY_URL_PATTERN == \
81+
'http://ocsp.snowflakecomputing.com/retry'

0 commit comments

Comments
 (0)