Skip to content

Commit 093ac26

Browse files
committed
fix(api-core): make mTLS endpoint conversion case-insensitive
1 parent 6596ac5 commit 093ac26

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

packages/google-api-core/google/api_core/gapic_v1/client_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ def get_default_mtls_endpoint(api_endpoint: Optional[str]) -> Optional[str]:
3333
Returns:
3434
Optional[str]: converted mTLS api endpoint.
3535
"""
36-
if not api_endpoint or ".mtls." in api_endpoint:
36+
if not api_endpoint or ".mtls." in api_endpoint.lower():
3737
return api_endpoint
3838

39-
if api_endpoint.endswith(".sandbox.googleapis.com"):
39+
lowered_endpoint = api_endpoint.lower()
40+
if lowered_endpoint.endswith(".sandbox.googleapis.com"):
4041
# len(".sandbox.googleapis.com") == 23
4142
return api_endpoint[:-23] + ".mtls.sandbox.googleapis.com"
4243

43-
if api_endpoint.endswith(".googleapis.com"):
44+
if lowered_endpoint.endswith(".googleapis.com"):
4445
# len(".googleapis.com") == 15
4546
return api_endpoint[:-15] + ".mtls.googleapis.com"
4647

packages/google-api-core/tests/unit/gapic/test_client_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def test_get_default_mtls_endpoint():
3939
get_default_mtls_endpoint("foo.sandbox.googleapis.com")
4040
== "foo.mtls.sandbox.googleapis.com"
4141
)
42+
# Test case-insensitivity
43+
assert (
44+
get_default_mtls_endpoint("foo.GoogleAPIs.com")
45+
== "foo.mtls.googleapis.com"
46+
)
47+
assert (
48+
get_default_mtls_endpoint("foo.Sandbox.GoogleAPIs.com")
49+
== "foo.mtls.sandbox.googleapis.com"
50+
)
4251

4352
# Test endpoints that shouldn't be converted
4453
assert (

0 commit comments

Comments
 (0)