|
8 | 8 | from django_dynamic_fixture import get
|
9 | 9 | from docker.errors import APIError as DockerAPIError
|
10 | 10 |
|
| 11 | +from readthedocs.projects.models import APIProject |
11 | 12 | from readthedocs.builds.models import Version
|
12 | 13 | from readthedocs.doc_builder.environments import (
|
13 | 14 | BuildCommand,
|
@@ -41,7 +42,7 @@ def test_record_command_as_success(self):
|
41 | 42 | api_client.command().patch.return_value = {
|
42 | 43 | "id": 1,
|
43 | 44 | }
|
44 |
| - project = get(Project) |
| 45 | + project = APIProject(**get(Project).__dict__) |
45 | 46 | build_env = LocalBuildEnvironment(
|
46 | 47 | project=project,
|
47 | 48 | build={
|
@@ -258,7 +259,7 @@ def test_missing_command(self):
|
258 | 259 |
|
259 | 260 | def test_output(self):
|
260 | 261 | """Test output command."""
|
261 |
| - project = get(Project) |
| 262 | + project = APIProject(**get(Project).__dict__) |
262 | 263 | api_client = mock.MagicMock()
|
263 | 264 | build_env = LocalBuildEnvironment(
|
264 | 265 | project=project,
|
@@ -310,6 +311,34 @@ def test_sanitize_output(self):
|
310 | 311 | for output, sanitized in checks:
|
311 | 312 | self.assertEqual(cmd.sanitize_output(output), sanitized)
|
312 | 313 |
|
| 314 | + def test_obfuscate_output_private_variables(self): |
| 315 | + build_env = mock.MagicMock() |
| 316 | + build_env.project = mock.MagicMock() |
| 317 | + build_env.project._environment_variables = mock.MagicMock() |
| 318 | + build_env.project._environment_variables.items.return_value = [ |
| 319 | + ( |
| 320 | + "PUBLIC", |
| 321 | + { |
| 322 | + "public": True, |
| 323 | + "value": "public-value", |
| 324 | + }, |
| 325 | + ), |
| 326 | + ( |
| 327 | + "PRIVATE", |
| 328 | + { |
| 329 | + "public": False, |
| 330 | + "value": "private-value", |
| 331 | + }, |
| 332 | + ), |
| 333 | + ] |
| 334 | + cmd = BuildCommand(["/bin/bash", "-c", "echo"], build_env=build_env) |
| 335 | + checks = ( |
| 336 | + ("public-value", "public-value"), |
| 337 | + ("private-value", "priv****"), |
| 338 | + ) |
| 339 | + for output, sanitized in checks: |
| 340 | + self.assertEqual(cmd.sanitize_output(output), sanitized) |
| 341 | + |
313 | 342 | @patch("subprocess.Popen")
|
314 | 343 | def test_unicode_output(self, mock_subprocess):
|
315 | 344 | """Unicode output from command."""
|
|
0 commit comments