|
15 | 15 | import base64 |
16 | 16 | import hashlib |
17 | 17 | import json |
| 18 | +import os |
18 | 19 | from unittest import mock |
19 | 20 | import urllib.parse |
20 | 21 |
|
@@ -93,6 +94,34 @@ def test_get_agent_identity_certificate_path_value_error( |
93 | 94 | assert result == "cert_path" |
94 | 95 | mock_get_cert.assert_called_once_with("/path/to/config.json", False) |
95 | 96 |
|
| 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 | + |
96 | 125 | @mock.patch("google.auth._agent_identity_utils.os.stat") |
97 | 126 | def test_is_certificate_file_ready_permission_error(self, mock_stat): |
98 | 127 | mock_stat.side_effect = PermissionError("Permission denied") |
|
0 commit comments