Skip to content

Commit 772e8af

Browse files
committed
[RHOAIENG-17251]: Add a test for the proxy env propagation in RStudio
Includes a simple test to check that the variables are propagated properly so that the proxy configuration can work in RStudio IDE as expected. * https://issues.redhat.com/browse/RHOAIENG-17251
1 parent 7e41238 commit 772e8af

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/containers/workbenches/rstudio/rstudio_test.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import json
44
import logging
55
import pathlib
6+
import pytest_subtests
67
import subprocess
78
import tempfile
89
import textwrap
9-
from typing import TYPE_CHECKING
10+
from typing import NamedTuple, TYPE_CHECKING
1011

1112
import allure
1213
import pytest
@@ -99,6 +100,43 @@ def test_rmd_to_pdf_rendering(self, image: str) -> None:
99100
finally:
100101
docker_utils.NotebookContainer(container).stop(timeout=0)
101102

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+
102140

103141
def check_call(container: WorkbenchContainer, cmd: str) -> int:
104142
"""Like subprocess.check_output, but in a container."""

0 commit comments

Comments
 (0)