Skip to content

Commit 4cb55e0

Browse files
chore: Update comments on test and update google.auth check to be done by version number
Signed-off-by: Radhika Agrawal <agrawalradhika@google.com>
1 parent 8bfc4ba commit 4cb55e0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tests/unit/operations_v1/test_operations_rest_client.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
from google.api_core import client_options
3636
from google.api_core import exceptions as core_exceptions
3737
from google.api_core import gapic_v1
38+
from google.api_core import parse_version_to_tuple
3839
from google.api_core.operations_v1 import AbstractOperationsClient
3940

4041
import google.auth
4142
from google.api_core.operations_v1 import pagers
4243
from google.api_core.operations_v1 import pagers_async
4344
from google.api_core.operations_v1 import transports
4445
from google.auth import credentials as ga_credentials
46+
from google.auth import __version__ as auth_version
4547
from google.auth.exceptions import MutualTLSChannelError
4648
from google.longrunning import operations_pb2
4749
from google.oauth2 import service_account
@@ -346,14 +348,23 @@ def test_operations_client_client_options(
346348
with pytest.raises(MutualTLSChannelError):
347349
client = client_class()
348350

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
351352
with mock.patch.dict(
352353
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
353354
):
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):
355360
with pytest.raises(ValueError):
356361
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.
357368
else:
358369
with mock.patch.object(transport_class, "__init__") as patched:
359370
patched.return_value = None

0 commit comments

Comments
 (0)