Skip to content

Commit 961e9d2

Browse files
committed
test: add unit test
1 parent 10763ad commit 961e9d2

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

packages/google-auth/tests/test_agent_identity_utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import base64
1616
import hashlib
1717
import json
18+
import os
1819
from unittest import mock
1920
import urllib.parse
2021

@@ -93,6 +94,34 @@ def test_get_agent_identity_certificate_path_value_error(
9394
assert result == "cert_path"
9495
mock_get_cert.assert_called_once_with("/path/to/config.json", False)
9596

97+
@mock.patch(
98+
"google.auth._agent_identity_utils._get_cert_path_with_optional_polling"
99+
)
100+
def test_get_agent_identity_certificate_path_prefix_false_positive(
101+
self, mock_get_cert, monkeypatch, tmpdir
102+
):
103+
base_dir = str(tmpdir)
104+
well_known_dir = os.path.join(base_dir, "workload-spiffe-credentials")
105+
well_known_path = os.path.join(well_known_dir, "certificates.pem")
106+
107+
monkeypatch.setattr(
108+
"google.auth._agent_identity_utils._WELL_KNOWN_CERT_PATH",
109+
well_known_path,
110+
)
111+
112+
fake_dir = os.path.join(base_dir, "workload-spiffe-credentials-fake")
113+
fake_config_path = os.path.join(fake_dir, "config.json")
114+
115+
monkeypatch.setenv(
116+
environment_vars.GOOGLE_API_CERTIFICATE_CONFIG, fake_config_path
117+
)
118+
mock_get_cert.return_value = "cert_path"
119+
120+
result = _agent_identity_utils.get_agent_identity_certificate_path()
121+
122+
assert result == "cert_path"
123+
mock_get_cert.assert_called_once_with(fake_config_path, False)
124+
96125
@mock.patch("google.auth._agent_identity_utils.os.stat")
97126
def test_is_certificate_file_ready_permission_error(self, mock_stat):
98127
mock_stat.side_effect = PermissionError("Permission denied")

0 commit comments

Comments
 (0)