fix: gracefully fallback if workload fields are missing from cert con… · googleapis/google-cloud-python@3ed2d68 · GitHub
Skip to content

Commit 3ed2d68

Browse files
fix: gracefully fallback if workload fields are missing from cert config (#16022)
Prevents exceptions during gECC flows or when falling back to SecureConnect by returning None instead of raising ClientCertError when X.509 workload fields are absent. --------- Co-authored-by: Daniel Sanche <d.sanche14@gmail.com>
1 parent 99fa08e commit 3ed2d68

3 files changed

Lines changed: 36 additions & 21 deletions

File tree

packages/google-auth/google/auth/transport/_mtls_helper.py

Lines changed: 8 additions & 15 deletions

packages/google-auth/tests/transport/aio/test_sessions_mtls.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@ async def test_configure_mtls_channel_invalid_format(self):
9898
with pytest.raises(exceptions.MutualTLSChannelError):
9999
await session.configure_mtls_channel()
100100

101+
@pytest.mark.asyncio
102+
async def test_configure_mtls_channel_invalud_fields(self):
103+
"""
104+
If cert is missing expected keys, it should fail gracefully
105+
"""
106+
with mock.patch.dict(
107+
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}
108+
), mock.patch("os.path.exists") as mock_exists, mock.patch(
109+
"builtins.open", mock.mock_open(read_data='{"cert_configs": {}}')
110+
):
111+
mock_exists.return_value = True
112+
mock_creds = mock.AsyncMock(spec=credentials.Credentials)
113+
session = sessions.AsyncAuthorizedSession(mock_creds)
114+
115+
await session.configure_mtls_channel()
116+
117+
# If the file couldn't be parsed, it shouldn't error; it just won't use mTLS
118+
assert session._is_mtls is False
119+
101120
@pytest.mark.asyncio
102121
async def test_configure_mtls_channel_mock_callback(self):
103122
"""

packages/google-auth/tests/transport/test__mtls_helper.py

Lines changed: 9 additions & 6 deletions

0 commit comments

Comments
 (0)