Skip to content

Commit 8990f86

Browse files
committed
fix(auth): Add additional test coverage and comments
1 parent 06d9045 commit 8990f86

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

google/auth/transport/_mtls_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def _get_workload_cert_and_key_paths(config_path):
198198
key_path = workload["key_path"]
199199

200200
# == BEGIN Temporary Cloud Run PATCH ==
201+
# See https://github.com/googleapis/google-auth-library-python/issues/1881
201202
if (cert_path == _INCORRECT_CLOUD_RUN_CERT_PATH) and (
202203
key_path == _INCORRECT_CLOUD_RUN_KEY_PATH
203204
):

tests/transport/test__mtls_helper.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,51 @@ def test_success_with_certificate_config_cloud_run_patch(
376376
_mtls_helper._WELL_KNOWN_CLOUD_RUN_KEY_PATH,
377377
)
378378

379+
@mock.patch("os.path.exists", autospec=True)
380+
@mock.patch(
381+
"google.auth.transport._mtls_helper._read_cert_and_key_files", autospec=True
382+
)
383+
@mock.patch(
384+
"google.auth.transport._mtls_helper._get_cert_config_path", autospec=True
385+
)
386+
@mock.patch("google.auth.transport._mtls_helper._load_json_file", autospec=True)
387+
@mock.patch("google.auth.transport._mtls_helper._check_config_path", autospec=True)
388+
def test_success_with_certificate_config_cloud_run_patch_skipped_if_cert_exists(
389+
self,
390+
mock_check_config_path,
391+
mock_load_json_file,
392+
mock_get_cert_config_path,
393+
mock_read_cert_and_key_files,
394+
mock_os_path_exists,
395+
):
396+
cert_config_path = "/path/to/config"
397+
mock_check_config_path.return_value = cert_config_path
398+
mock_os_path_exists.return_value = True
399+
mock_load_json_file.return_value = {
400+
"cert_configs": {
401+
"workload": {
402+
"cert_path": _mtls_helper._INCORRECT_CLOUD_RUN_CERT_PATH,
403+
"key_path": _mtls_helper._INCORRECT_CLOUD_RUN_KEY_PATH,
404+
}
405+
}
406+
}
407+
mock_get_cert_config_path.return_value = cert_config_path
408+
mock_read_cert_and_key_files.return_value = (
409+
pytest.public_cert_bytes,
410+
pytest.private_key_bytes,
411+
)
412+
413+
has_cert, cert, key, passphrase = _mtls_helper.get_client_ssl_credentials()
414+
assert has_cert
415+
assert cert == pytest.public_cert_bytes
416+
assert key == pytest.private_key_bytes
417+
assert passphrase is None
418+
419+
mock_read_cert_and_key_files.assert_called_once_with(
420+
_mtls_helper._INCORRECT_CLOUD_RUN_CERT_PATH,
421+
_mtls_helper._INCORRECT_CLOUD_RUN_KEY_PATH,
422+
)
423+
379424
@mock.patch(
380425
"google.auth.transport._mtls_helper._get_workload_cert_and_key", autospec=True
381426
)

0 commit comments

Comments
 (0)