|
35 | 35 | from google.api_core import client_options |
36 | 36 | from google.api_core import exceptions as core_exceptions |
37 | 37 | from google.api_core import gapic_v1 |
| 38 | +from google.api_core import parse_version_to_tuple |
38 | 39 | from google.api_core.operations_v1 import AbstractOperationsClient |
39 | 40 |
|
40 | 41 | import google.auth |
41 | 42 | from google.api_core.operations_v1 import pagers |
42 | 43 | from google.api_core.operations_v1 import pagers_async |
43 | 44 | from google.api_core.operations_v1 import transports |
44 | 45 | from google.auth import credentials as ga_credentials |
| 46 | +from google.auth import __version__ as auth_version |
45 | 47 | from google.auth.exceptions import MutualTLSChannelError |
46 | 48 | from google.longrunning import operations_pb2 |
47 | 49 | from google.oauth2 import service_account |
@@ -346,14 +348,23 @@ def test_operations_client_client_options( |
346 | 348 | with pytest.raises(MutualTLSChannelError): |
347 | 349 | client = client_class() |
348 | 350 |
|
349 | | - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value and |
350 | | - # should_use_client_cert is unavailable. |
| 351 | + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value |
351 | 352 | with mock.patch.dict( |
352 | 353 | os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} |
353 | 354 | ): |
354 | | - if not hasattr(google.auth.transport.mtls, "should_use_client_cert"): |
| 355 | + # Test behavior for google.auth versions < 2.43.0. |
| 356 | + # These versions do not have the updated mtls.should_use_client_cert logic. |
| 357 | + # Verify that a ValueError is raised when GOOGLE_API_USE_CLIENT_CERTIFICATE |
| 358 | + # is set to an unsupported value, as expected in these older versions. |
| 359 | + if parse_version_to_tuple(auth_version) < (2, 43, 0): |
355 | 360 | with pytest.raises(ValueError): |
356 | 361 | client = client_class() |
| 362 | + # Test behavior for google.auth versions >= 2.43.0. |
| 363 | + # In these versions, if GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an |
| 364 | + # unsupported value (e.g., not 'true' or 'false'), the expected behavior |
| 365 | + # of the internal google.auth.mtls.should_use_client_cert() function |
| 366 | + # is to return False. Expect should_use_client_cert to return False, so |
| 367 | + # client creation should proceed without requiring a client certificate. |
357 | 368 | else: |
358 | 369 | with mock.patch.object(transport_class, "__init__") as patched: |
359 | 370 | patched.return_value = None |
|
0 commit comments