Skip to content

Commit d7d1af5

Browse files
smtakedaankit-bhatnagar167
authored andcommitted
SNOW-74042: Fixed custom OCSP Cache server URL for privatelink
1 parent 5b017bb commit d7d1af5

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

connection.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,24 @@ def __open_connection(self):
584584
self.host,
585585
self.port)
586586

587+
if 'SF_OCSP_RESPONSE_CACHE_SERVER_URL' in os.environ:
588+
logger.debug(u"Custom OCSP Cache Server URL found in environment - %s", os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'])
589+
587590
if self.host.endswith(u".privatelink.snowflakecomputing.com"):
588591
ocsp_cache_server = \
589592
u'http://ocsp{}/ocsp_response_cache.json'.format(
590593
self.host[self.host.index('.'):])
591594
if 'SF_OCSP_RESPONSE_CACHE_SERVER_URL' not in os.environ:
595+
os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server
596+
else:
597+
if not os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'].\
598+
startswith("http://"):
599+
ocsp_cache_server = "http://{0}/{1}".format(os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'],
600+
"ocsp_response_cache.json")
601+
else:
602+
ocsp_cache_server = "{0}/{1}".format(os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'],
603+
"ocsp_response_cache.json")
604+
592605
os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server
593606
logger.debug(u"OCSP Cache Server is updated: %s", ocsp_cache_server)
594607
else:

test/test_ocsp_ssd.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def _teardown_ssd_test_setup():
9898
if 'SF_OCSP_ACTIVATE_SSD' in os.environ:
9999
del os.environ['SF_OCSP_ACTIVATE_SSD']
100100

101+
101102
def _create_host_spec_ocsp_bypass_ssd(ocsp, priv_key, hostname):
102103

103104
"""
@@ -149,13 +150,13 @@ def test_host_spec_ocsp_bypass_ssd():
149150

150151
acc_name = ocsp.get_account_from_hostname(hostname[0])
151152
cache_status, cur_host_spec_token = ocsp.SSD.find_in_ssd_cache(acc_name)
152-
assert((cur_host_spec_token is not None), "Failed to read host specific directive")
153+
assert cur_host_spec_token is not None, "Failed to read host specific directive"
153154

154155
try:
155-
assert(ocsp.process_ocsp_bypass_directive(cur_host_spec_token, '*', hostname),
156-
"Failed to process host specific bypass ssd")
156+
assert ocsp.process_ocsp_bypass_directive(cur_host_spec_token, '*', hostname[0]), \
157+
"Failed to process host specific bypass ssd"
157158
except Exception as ex:
158-
print("Exception while processing SSD :"+ex)
159+
print("Exception while processing SSD :"+str(ex))
159160

160161

161162
def test_host_spec_ocsp_bypass_updated_ssd():
@@ -188,7 +189,7 @@ def test_host_spec_ocsp_bypass_updated_ssd():
188189

189190
acc_name = ocsp.get_account_from_hostname(hostname[0])
190191
cache_status, cur_host_spec_token = ocsp.SSD.find_in_ssd_cache(acc_name)
191-
assert((cur_host_spec_token is not None), "Failed to read host specific directive")
192+
assert cur_host_spec_token is not None, "Failed to read host specific directive"
192193

193194
try:
194195
assert ocsp.process_ocsp_bypass_directive(cur_host_spec_token, '*', hostname[1]),\
@@ -227,7 +228,7 @@ def test_invalid_host_spec_ocsp_bypass_updated_ssd():
227228

228229
acc_name = ocsp.get_account_from_hostname(hostname[0])
229230
cache_status, cur_host_spec_token = ocsp.SSD.find_in_ssd_cache(acc_name)
230-
assert((cur_host_spec_token is not None), "Failed to read host specific directive")
231+
assert cur_host_spec_token is not None, "Failed to read host specific directive"
231232

232233
try:
233234
assert ocsp.process_ocsp_bypass_directive(cur_host_spec_token, '*', "sonytv.snowflakecomputing.com") is False,\
@@ -284,8 +285,8 @@ def test_certid_spec_bypass_ssd():
284285
hostname = 'sfcsupport.us-east-1.snowflakecomputing.com'
285286

286287
connection = _openssl_connect(hostname)
287-
assert (ocsp.validate(hostname, connection),
288-
"Failed to validate {} using Cert specific OCSP Bypass SSD".format(hostname))
288+
assert ocsp.validate(hostname, connection), \
289+
"Failed to validate {} using Cert specific OCSP Bypass SSD".format(hostname)
289290

290291

291292
def test_invalid_certid_spec_bypass_ssd():
@@ -330,8 +331,8 @@ def test_invalid_certid_spec_bypass_ssd():
330331
except Exception:
331332
exception_occured = True
332333

333-
assert(exception_occured,
334-
"No exception raised for bad Server Side Directive")
334+
assert exception_occured,\
335+
"No exception raised for bad Server Side Directive"
335336

336337

337338
def test_wildcard_ocsp_bypass_ssd():
@@ -364,8 +365,8 @@ def test_wildcard_ocsp_bypass_ssd():
364365

365366
ocsp = _setup_ssd_test(temp_ocsp_file_path)
366367
connection = _openssl_connect(hostname)
367-
assert (ocsp.validate(hostname, connection),
368-
"Failed to validate {0} using Wildcard OCSP Bypass SSD".format(hostname))
368+
assert ocsp.validate(hostname, connection), \
369+
"Failed to validate {0} using Wildcard OCSP Bypass SSD".format(hostname)
369370

370371

371372
def test_key_upd_ssd():
@@ -415,8 +416,8 @@ def test_key_upd_ssd():
415416
print("Exception occurred : "+str(ex))
416417

417418
ocsp_cur_pub_key = ocsp.SSD.ssd_pub_key_dep1.get_key()
418-
assert(pub_key_new == ocsp_cur_pub_key,
419-
"Failed to read Key Update Directive")
419+
assert pub_key_new == ocsp_cur_pub_key,\
420+
"Failed to read Key Update Directive"
420421

421422
_create_host_spec_ocsp_bypass_ssd(ocsp, priv_key, hostname)
422423

0 commit comments

Comments
 (0)