Skip to content

Commit 763b50e

Browse files
committed
chore: updated goldens
1 parent 29cb163 commit 763b50e

File tree

22 files changed

+1558
-110
lines changed

22 files changed

+1558
-110
lines changed

tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _use_client_cert_effective():
155155
# check if google-auth version supports should_use_client_cert for automatic mTLS enablement
156156
if hasattr(mtls, "should_use_client_cert"):
157157
return mtls.should_use_client_cert()
158-
else:
158+
else: # pragma: NO COVER
159159
# if unsupported, fallback to reading from env var
160160
use_client_cert_str = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower()
161161
if use_client_cert_str not in ("true", "false"):

tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,91 @@ def test__read_environment_variables():
165165
with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}):
166166
assert AssetServiceClient._read_environment_variables() == (False, "auto", "foo.com")
167167

168+
169+
def test_use_client_cert_effective():
170+
# Test case 1: Test when `should_use_client_cert` returns True.
171+
# We mock the `should_use_client_cert` function to simulate a scenario where
172+
# the google-auth library supports automatic mTLS and determines that a
173+
# client certificate should be used.
174+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
175+
with mock.patch("google.auth.transport.mtls.should_use_client_cert", return_value=True):
176+
assert AssetServiceClient._use_client_cert_effective() is True
177+
178+
# Test case 2: Test when `should_use_client_cert` returns False.
179+
# We mock the `should_use_client_cert` function to simulate a scenario where
180+
# the google-auth library supports automatic mTLS and determines that a
181+
# client certificate should NOT be used.
182+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
183+
with mock.patch("google.auth.transport.mtls.should_use_client_cert", return_value=False):
184+
assert AssetServiceClient._use_client_cert_effective() is False
185+
186+
# Test case 3: Test when `should_use_client_cert` is unavailable and the
187+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "true".
188+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
189+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
190+
assert AssetServiceClient._use_client_cert_effective() is True
191+
192+
# Test case 4: Test when `should_use_client_cert` is unavailable and the
193+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "false".
194+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
195+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}):
196+
assert AssetServiceClient._use_client_cert_effective() is False
197+
198+
# Test case 5: Test when `should_use_client_cert` is unavailable and the
199+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "True".
200+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
201+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "True"}):
202+
assert AssetServiceClient._use_client_cert_effective() is True
203+
204+
# Test case 6: Test when `should_use_client_cert` is unavailable and the
205+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "False".
206+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
207+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "False"}):
208+
assert AssetServiceClient._use_client_cert_effective() is False
209+
210+
# Test case 7: Test when `should_use_client_cert` is unavailable and the
211+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "TRUE".
212+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
213+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "TRUE"}):
214+
assert AssetServiceClient._use_client_cert_effective() is True
215+
216+
# Test case 8: Test when `should_use_client_cert` is unavailable and the
217+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "FALSE".
218+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
219+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "FALSE"}):
220+
assert AssetServiceClient._use_client_cert_effective() is False
221+
222+
# Test case 9: Test when `should_use_client_cert` is unavailable and the
223+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not set.
224+
# In this case, the method should return False, which is the default value.
225+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
226+
with mock.patch.dict(os.environ, clear=True):
227+
assert AssetServiceClient._use_client_cert_effective() is False
228+
229+
# Test case 10: Test when `should_use_client_cert` is unavailable and the
230+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
231+
# The method should raise a ValueError as the environment variable must be either
232+
# "true" or "false".
233+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
234+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}):
235+
with pytest.raises(ValueError):
236+
AssetServiceClient._use_client_cert_effective()
237+
238+
# Test case 11: Test when `should_use_client_cert` is available and the
239+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
240+
# The method should return False as the environment variable is set to an invalid value.
241+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
242+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}):
243+
assert AssetServiceClient._use_client_cert_effective() is False
244+
245+
# Test case 12: Test when `should_use_client_cert` is available and the
246+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is unset. Also,
247+
# the GOOGLE_API_CONFIG environment variable is unset.
248+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
249+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": ""}):
250+
with mock.patch.dict(os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": ""}):
251+
assert AssetServiceClient._use_client_cert_effective() is False
252+
168253
def test__get_client_cert_source():
169254
mock_provided_cert_source = mock.Mock()
170255
mock_default_cert_source = mock.Mock()

tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _use_client_cert_effective():
158158
# check if google-auth version supports should_use_client_cert for automatic mTLS enablement
159159
if hasattr(mtls, "should_use_client_cert"):
160160
return mtls.should_use_client_cert()
161-
else:
161+
else: # pragma: NO COVER
162162
# if unsupported, fallback to reading from env var
163163
use_client_cert_str = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower()
164164
if use_client_cert_str not in ("true", "false"):

tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,91 @@ def test__read_environment_variables():
155155
with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}):
156156
assert IAMCredentialsClient._read_environment_variables() == (False, "auto", "foo.com")
157157

158+
159+
def test_use_client_cert_effective():
160+
# Test case 1: Test when `should_use_client_cert` returns True.
161+
# We mock the `should_use_client_cert` function to simulate a scenario where
162+
# the google-auth library supports automatic mTLS and determines that a
163+
# client certificate should be used.
164+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
165+
with mock.patch("google.auth.transport.mtls.should_use_client_cert", return_value=True):
166+
assert IAMCredentialsClient._use_client_cert_effective() is True
167+
168+
# Test case 2: Test when `should_use_client_cert` returns False.
169+
# We mock the `should_use_client_cert` function to simulate a scenario where
170+
# the google-auth library supports automatic mTLS and determines that a
171+
# client certificate should NOT be used.
172+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
173+
with mock.patch("google.auth.transport.mtls.should_use_client_cert", return_value=False):
174+
assert IAMCredentialsClient._use_client_cert_effective() is False
175+
176+
# Test case 3: Test when `should_use_client_cert` is unavailable and the
177+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "true".
178+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
179+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
180+
assert IAMCredentialsClient._use_client_cert_effective() is True
181+
182+
# Test case 4: Test when `should_use_client_cert` is unavailable and the
183+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "false".
184+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
185+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}):
186+
assert IAMCredentialsClient._use_client_cert_effective() is False
187+
188+
# Test case 5: Test when `should_use_client_cert` is unavailable and the
189+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "True".
190+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
191+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "True"}):
192+
assert IAMCredentialsClient._use_client_cert_effective() is True
193+
194+
# Test case 6: Test when `should_use_client_cert` is unavailable and the
195+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "False".
196+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
197+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "False"}):
198+
assert IAMCredentialsClient._use_client_cert_effective() is False
199+
200+
# Test case 7: Test when `should_use_client_cert` is unavailable and the
201+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "TRUE".
202+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
203+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "TRUE"}):
204+
assert IAMCredentialsClient._use_client_cert_effective() is True
205+
206+
# Test case 8: Test when `should_use_client_cert` is unavailable and the
207+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "FALSE".
208+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
209+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "FALSE"}):
210+
assert IAMCredentialsClient._use_client_cert_effective() is False
211+
212+
# Test case 9: Test when `should_use_client_cert` is unavailable and the
213+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not set.
214+
# In this case, the method should return False, which is the default value.
215+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
216+
with mock.patch.dict(os.environ, clear=True):
217+
assert IAMCredentialsClient._use_client_cert_effective() is False
218+
219+
# Test case 10: Test when `should_use_client_cert` is unavailable and the
220+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
221+
# The method should raise a ValueError as the environment variable must be either
222+
# "true" or "false".
223+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
224+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}):
225+
with pytest.raises(ValueError):
226+
IAMCredentialsClient._use_client_cert_effective()
227+
228+
# Test case 11: Test when `should_use_client_cert` is available and the
229+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
230+
# The method should return False as the environment variable is set to an invalid value.
231+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
232+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}):
233+
assert IAMCredentialsClient._use_client_cert_effective() is False
234+
235+
# Test case 12: Test when `should_use_client_cert` is available and the
236+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is unset. Also,
237+
# the GOOGLE_API_CONFIG environment variable is unset.
238+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
239+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": ""}):
240+
with mock.patch.dict(os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": ""}):
241+
assert IAMCredentialsClient._use_client_cert_effective() is False
242+
158243
def test__get_client_cert_source():
159244
mock_provided_cert_source = mock.Mock()
160245
mock_default_cert_source = mock.Mock()

tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def _use_client_cert_effective():
167167
# check if google-auth version supports should_use_client_cert for automatic mTLS enablement
168168
if hasattr(mtls, "should_use_client_cert"):
169169
return mtls.should_use_client_cert()
170-
else:
170+
else: # pragma: NO COVER
171171
# if unsupported, fallback to reading from env var
172172
use_client_cert_str = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower()
173173
if use_client_cert_str not in ("true", "false"):

tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,91 @@ def test__read_environment_variables():
175175
with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}):
176176
assert EventarcClient._read_environment_variables() == (False, "auto", "foo.com")
177177

178+
179+
def test_use_client_cert_effective():
180+
# Test case 1: Test when `should_use_client_cert` returns True.
181+
# We mock the `should_use_client_cert` function to simulate a scenario where
182+
# the google-auth library supports automatic mTLS and determines that a
183+
# client certificate should be used.
184+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
185+
with mock.patch("google.auth.transport.mtls.should_use_client_cert", return_value=True):
186+
assert EventarcClient._use_client_cert_effective() is True
187+
188+
# Test case 2: Test when `should_use_client_cert` returns False.
189+
# We mock the `should_use_client_cert` function to simulate a scenario where
190+
# the google-auth library supports automatic mTLS and determines that a
191+
# client certificate should NOT be used.
192+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
193+
with mock.patch("google.auth.transport.mtls.should_use_client_cert", return_value=False):
194+
assert EventarcClient._use_client_cert_effective() is False
195+
196+
# Test case 3: Test when `should_use_client_cert` is unavailable and the
197+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "true".
198+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
199+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
200+
assert EventarcClient._use_client_cert_effective() is True
201+
202+
# Test case 4: Test when `should_use_client_cert` is unavailable and the
203+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "false".
204+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
205+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}):
206+
assert EventarcClient._use_client_cert_effective() is False
207+
208+
# Test case 5: Test when `should_use_client_cert` is unavailable and the
209+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "True".
210+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
211+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "True"}):
212+
assert EventarcClient._use_client_cert_effective() is True
213+
214+
# Test case 6: Test when `should_use_client_cert` is unavailable and the
215+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "False".
216+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
217+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "False"}):
218+
assert EventarcClient._use_client_cert_effective() is False
219+
220+
# Test case 7: Test when `should_use_client_cert` is unavailable and the
221+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "TRUE".
222+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
223+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "TRUE"}):
224+
assert EventarcClient._use_client_cert_effective() is True
225+
226+
# Test case 8: Test when `should_use_client_cert` is unavailable and the
227+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "FALSE".
228+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
229+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "FALSE"}):
230+
assert EventarcClient._use_client_cert_effective() is False
231+
232+
# Test case 9: Test when `should_use_client_cert` is unavailable and the
233+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not set.
234+
# In this case, the method should return False, which is the default value.
235+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
236+
with mock.patch.dict(os.environ, clear=True):
237+
assert EventarcClient._use_client_cert_effective() is False
238+
239+
# Test case 10: Test when `should_use_client_cert` is unavailable and the
240+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
241+
# The method should raise a ValueError as the environment variable must be either
242+
# "true" or "false".
243+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
244+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}):
245+
with pytest.raises(ValueError):
246+
EventarcClient._use_client_cert_effective()
247+
248+
# Test case 11: Test when `should_use_client_cert` is available and the
249+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
250+
# The method should return False as the environment variable is set to an invalid value.
251+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
252+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}):
253+
assert EventarcClient._use_client_cert_effective() is False
254+
255+
# Test case 12: Test when `should_use_client_cert` is available and the
256+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is unset. Also,
257+
# the GOOGLE_API_CONFIG environment variable is unset.
258+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
259+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": ""}):
260+
with mock.patch.dict(os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": ""}):
261+
assert EventarcClient._use_client_cert_effective() is False
262+
178263
def test__get_client_cert_source():
179264
mock_provided_cert_source = mock.Mock()
180265
mock_default_cert_source = mock.Mock()

tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _use_client_cert_effective():
151151
# check if google-auth version supports should_use_client_cert for automatic mTLS enablement
152152
if hasattr(mtls, "should_use_client_cert"):
153153
return mtls.should_use_client_cert()
154-
else:
154+
else: # pragma: NO COVER
155155
# if unsupported, fallback to reading from env var
156156
use_client_cert_str = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower()
157157
if use_client_cert_str not in ("true", "false"):

tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def _use_client_cert_effective():
148148
# check if google-auth version supports should_use_client_cert for automatic mTLS enablement
149149
if hasattr(mtls, "should_use_client_cert"):
150150
return mtls.should_use_client_cert()
151-
else:
151+
else: # pragma: NO COVER
152152
# if unsupported, fallback to reading from env var
153153
use_client_cert_str = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower()
154154
if use_client_cert_str not in ("true", "false"):

0 commit comments

Comments
 (0)