Skip to content

Commit 01a6b6a

Browse files
chore: add test coverage for unchanged lines
Signed-off-by: Radhika Agrawal <agrawalradhika@google.com>
1 parent 720a0c9 commit 01a6b6a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/transport/test_mtls.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,55 @@
2121
from google.auth.transport import mtls
2222

2323

24+
@mock.patch("google.auth.transport._mtls_helper._check_config_path")
25+
def test_has_default_client_cert_source_with_context_aware_metadata(mock_check):
26+
"""
27+
Directly tests the logic: if CONTEXT_AWARE_METADATA_PATH is found, return True.
28+
"""
29+
30+
# Setup: Return a path only for the Context Aware Metadata Path
31+
def side_effect(path):
32+
if path == _mtls_helper.CONTEXT_AWARE_METADATA_PATH:
33+
return "/path/to/context_aware_metadata.json"
34+
return None
35+
36+
mock_check.side_effect = side_effect
37+
38+
# Execute
39+
result = mtls.has_default_client_cert_source()
40+
41+
# Assert
42+
assert result is True
43+
mock_check.assert_any_call(_mtls_helper.CONTEXT_AWARE_METADATA_PATH)
44+
45+
46+
@mock.patch("google.auth.transport._mtls_helper._check_config_path")
47+
def test_has_default_client_cert_source_falls_back(mock_check):
48+
"""
49+
Tests that it skips CONTEXT_AWARE_METADATA_PATH if None, and checks the next path.
50+
"""
51+
52+
# Setup: First path is None, second path is valid
53+
def side_effect(path):
54+
if path == _mtls_helper.CERTIFICATE_CONFIGURATION_DEFAULT_PATH:
55+
return "/path/to/default_cert.json"
56+
return None
57+
58+
mock_check.side_effect = side_effect
59+
60+
# Execute
61+
result = mtls.has_default_client_cert_source()
62+
63+
# Assert
64+
assert result is True
65+
# Verify the sequence of calls
66+
expected_calls = [
67+
mock.call(_mtls_helper.CONTEXT_AWARE_METADATA_PATH),
68+
mock.call(_mtls_helper.CERTIFICATE_CONFIGURATION_DEFAULT_PATH),
69+
]
70+
mock_check.assert_has_calls(expected_calls)
71+
72+
2473
@mock.patch("google.auth.transport.mtls.getenv", autospec=True)
2574
@mock.patch("google.auth.transport._mtls_helper._check_config_path", autospec=True)
2675
def test_has_default_client_cert_source_env_var_success(check_config_path, mock_getenv):

0 commit comments

Comments
 (0)