|
3 | 3 | import json
|
4 | 4 | import logging
|
5 | 5 | import pathlib
|
| 6 | +import pytest_subtests |
6 | 7 | import subprocess
|
7 | 8 | import tempfile
|
8 | 9 | import textwrap
|
9 |
| -from typing import TYPE_CHECKING |
| 10 | +from typing import NamedTuple, TYPE_CHECKING |
10 | 11 |
|
11 | 12 | import allure
|
12 | 13 | import pytest
|
|
21 | 22 | class TestRStudioImage:
|
22 | 23 | """Tests for RStudio Workbench images in this repository."""
|
23 | 24 |
|
24 |
| - APP_ROOT_HOME = "/opt/app-root/src/" |
| 25 | + APP_ROOT_HOME = "/opt/app-root/src" |
25 | 26 |
|
26 | 27 | @allure.issue("RHOAIENG-17256")
|
27 | 28 | def test_rmd_to_pdf_rendering(self, image: str) -> None:
|
@@ -99,6 +100,43 @@ def test_rmd_to_pdf_rendering(self, image: str) -> None:
|
99 | 100 | finally:
|
100 | 101 | docker_utils.NotebookContainer(container).stop(timeout=0)
|
101 | 102 |
|
| 103 | + @allure.issue("RHOAIENG-16604") |
| 104 | + def test_http_proxy_env_propagates(self, image: str, subtests: pytest_subtests.plugin.SubTests) -> None: |
| 105 | + """ |
| 106 | + This checks that the lowercased proxy configuration is propagated into the RStudio |
| 107 | + environment so that the appropriate values are then accepted and followed. |
| 108 | + """ |
| 109 | + skip_if_not_rstudio_image(image) |
| 110 | + |
| 111 | + class TestCase(NamedTuple): |
| 112 | + name: str |
| 113 | + name_lc: str |
| 114 | + value: str |
| 115 | + |
| 116 | + test_cases: list[TestCase] = [ |
| 117 | + TestCase("HTTP_PROXY", "http_proxy", "http://localhost:8080"), |
| 118 | + TestCase("HTTPS_PROXY", "https_proxy", "https://localhost:8443"), |
| 119 | + TestCase("NO_PROXY", "no_proxy", "google.com"), |
| 120 | + ] |
| 121 | + |
| 122 | + container = WorkbenchContainer(image=image, user=1000, group_add=[0]) |
| 123 | + for tc in test_cases: |
| 124 | + container.with_env(tc.name, tc.value) |
| 125 | + |
| 126 | + try: |
| 127 | + # We need to wait for the IDE to be completely loaded so that the envs are processed properly. |
| 128 | + container.start(wait_for_readiness=True) |
| 129 | + |
| 130 | + # Once the RStudio IDE is fully up and running, the processed envs should includ also lowercased proxy configs. |
| 131 | + for tc in test_cases: |
| 132 | + with subtests.test(tc.name): |
| 133 | + output = check_output( |
| 134 | + container, |
| 135 | + f"/usr/bin/R --quiet --no-echo -e 'Sys.getenv(\"{tc.name_lc}\")'") |
| 136 | + assert '"' + tc.value + '"' in output |
| 137 | + finally: |
| 138 | + docker_utils.NotebookContainer(container).stop(timeout=0) |
| 139 | + |
102 | 140 |
|
103 | 141 | def check_call(container: WorkbenchContainer, cmd: str) -> int:
|
104 | 142 | """Like subprocess.check_output, but in a container."""
|
|
0 commit comments