Skip to content

Commit cf6df54

Browse files
chore: Add unit test for specific case and improve docstring
Signed-off-by: Radhika Agrawal <agrawalradhika@google.com>
1 parent 8fa9fb6 commit cf6df54

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

google/auth/transport/_mtls_helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ def check_use_client_cert():
411411
"""Returns boolean for whether the client certificate should be used for mTLS.
412412
413413
If GOOGLE_API_USE_CLIENT_CERTIFICATE is set to true or false, a corresponding
414-
bool value will be returned.
414+
bool value will be returned. If the value is set to an unexpected string, it
415+
will default to False.
415416
If GOOGLE_API_USE_CLIENT_CERTIFICATE is unset, the value will be inferred
416417
by reading a file pointed at by GOOGLE_API_CERTIFICATE_CONFIG, and verifying
417418
it contains a "workload" section. If so, the function will return True,

tests/transport/test__mtls_helper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,11 @@ def test_check_use_client_cert_false(self, monkeypatch):
670670
use_client_cert = _mtls_helper.check_use_client_cert()
671671
assert use_client_cert is False
672672

673+
def test_check_use_client_cert_unsupported_value(self, monkeypatch):
674+
monkeypatch.setenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "dummy")
675+
use_client_cert = _mtls_helper.check_use_client_cert()
676+
assert use_client_cert is False
677+
673678
def test_check_use_client_cert_for_workload_with_config_file_not_found(
674679
self, monkeypatch
675680
):

0 commit comments

Comments
 (0)