Skip to content

Commit bb69aa9

Browse files
committed
test(auth): add test coverage for mTLS auto-enablement with invalid JSON structure
1 parent 9497cb4 commit bb69aa9

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

packages/google-auth/tests/transport/test__mtls_helper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,22 @@ def test_config_file_not_found(self, mock_exists, mock_file):
858858
mock_file.side_effect = FileNotFoundError
859859
assert _mtls_helper.check_use_client_cert() is False
860860

861+
@mock.patch("builtins.open", autospec=True)
862+
@mock.patch.dict(
863+
os.environ,
864+
{
865+
"GOOGLE_API_USE_CLIENT_CERTIFICATE": "",
866+
"CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE": "",
867+
"GOOGLE_API_CERTIFICATE_CONFIG": "/path/to/config",
868+
"CLOUDSDK_CONTEXT_AWARE_CERTIFICATE_CONFIG_FILE_PATH": "",
869+
},
870+
)
871+
@mock.patch("os.path.exists", autospec=True)
872+
def test_config_file_invalid_json_type(self, mock_exists, mock_file):
873+
mock_exists.return_value = True
874+
mock_file.side_effect = mock.mock_open(read_data="[]")
875+
assert _mtls_helper.check_use_client_cert() is False
876+
861877
@mock.patch("builtins.open", autospec=True)
862878
@mock.patch.dict(os.environ, {}, clear=True)
863879
@mock.patch("os.path.exists", autospec=True)

0 commit comments

Comments
 (0)