Skip to content

Commit 91d31b8

Browse files
authored
SNOW-872568: Fix retry oscp URL for private link (#1733)
1 parent f50427b commit 91d31b8

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1010

1111
- v3.2.1(TBD)
1212

13+
- Fixed a bug where url port and path were ignore in private link oscp retry.
1314
- Added thread safety in telemetry when instantiating multiple connections concurrently.
1415

1516
- v3.2.0(September 06,2023)

src/snowflake/connector/ocsp_snowflake.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,15 @@ def generate_get_url(self, ocsp_url, b64data):
439439
if self.OCSP_RETRY_URL is None:
440440
target_url = f"{ocsp_url}/{b64data}"
441441
else:
442-
target_url = self.OCSP_RETRY_URL.format(parsed_url.hostname, b64data)
442+
# values of parsed_url.netloc and parsed_url.path based on oscp_url are as follows:
443+
# URL NETLOC PATH
444+
# "http://oneocsp.microsoft.com" "oneocsp.microsoft.com" ""
445+
# "http://oneocsp.microsoft.com:8080" "oneocsp.microsoft.com:8080" ""
446+
# "http://oneocsp.microsoft.com/" "oneocsp.microsoft.com" "/"
447+
# "http://oneocsp.microsoft.com/ocsp" "oneocsp.microsoft.com" "/ocsp"
448+
# The check below is to treat first two urls same
449+
path = parsed_url.path if parsed_url.path != "/" else ""
450+
target_url = self.OCSP_RETRY_URL.format(parsed_url.netloc + path, b64data)
443451

444452
logger.debug("OCSP Retry URL is - %s", target_url)
445453
return target_url

test/unit/test_ocsp.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,33 @@ def test_building_retry_url():
395395
== "http://ocsp.us-east-1.snowflakecomputing.com/retry/{0}/{1}"
396396
)
397397

398+
assert (
399+
OCSP_SERVER.generate_get_url("http://oneocsp.microsoft.com", "1234")
400+
== "http://ocsp.us-east-1.snowflakecomputing.com/retry/oneocsp.microsoft.com/1234"
401+
)
402+
assert (
403+
OCSP_SERVER.generate_get_url("http://oneocsp.microsoft.com/", "1234")
404+
== "http://ocsp.us-east-1.snowflakecomputing.com/retry/oneocsp.microsoft.com/1234"
405+
)
406+
assert (
407+
OCSP_SERVER.generate_get_url("http://oneocsp.microsoft.com/ocsp", "1234")
408+
== "http://ocsp.us-east-1.snowflakecomputing.com/retry/oneocsp.microsoft.com/ocsp/1234"
409+
)
410+
411+
# ensure we also handle port
412+
assert (
413+
OCSP_SERVER.generate_get_url("http://oneocsp.microsoft.com:8080", "1234")
414+
== "http://ocsp.us-east-1.snowflakecomputing.com/retry/oneocsp.microsoft.com:8080/1234"
415+
)
416+
assert (
417+
OCSP_SERVER.generate_get_url("http://oneocsp.microsoft.com:8080/", "1234")
418+
== "http://ocsp.us-east-1.snowflakecomputing.com/retry/oneocsp.microsoft.com:8080/1234"
419+
)
420+
assert (
421+
OCSP_SERVER.generate_get_url("http://oneocsp.microsoft.com:8080/ocsp", "1234")
422+
== "http://ocsp.us-east-1.snowflakecomputing.com/retry/oneocsp.microsoft.com:8080/ocsp/1234"
423+
)
424+
398425
# privatelink retry url with port
399426
OCSP_SERVER.OCSP_RETRY_URL = None
400427
OCSP_SERVER.CACHE_SERVER_URL = (

0 commit comments

Comments
 (0)