Skip to content

Commit 541dbf4

Browse files
roamingthingskiview
authored andcommitted
Update BrowserWebDriverContainer to honor existing no_proxy setting (#929)
Fixes #928
1 parent 99e2c1c commit 541dbf4

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

modules/selenium/src/main/java/org/testcontainers/containers/BrowserWebDriverContainer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class BrowserWebDriverContainer<SELF extends BrowserWebDriverContainer<SE
4848
private static final int SELENIUM_PORT = 4444;
4949
private static final int VNC_PORT = 5900;
5050

51+
private static final String NO_PROXY_KEY = "no_proxy";
52+
5153
@Nullable
5254
private Capabilities capabilities;
5355
private boolean customImageNameIsSet = false;
@@ -156,7 +158,11 @@ protected void configure() {
156158

157159
addExposedPorts(SELENIUM_PORT, VNC_PORT);
158160
addEnv("TZ", timeZone);
159-
addEnv("no_proxy", "localhost");
161+
162+
if (!getEnvMap().containsKey(NO_PROXY_KEY)) {
163+
addEnv(NO_PROXY_KEY, "localhost");
164+
}
165+
160166
setCommand("/opt/bin/entry_point.sh");
161167

162168
/*
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.testcontainers.junit;
2+
3+
import org.junit.Test;
4+
import org.openqa.selenium.chrome.ChromeOptions;
5+
import org.testcontainers.containers.BrowserWebDriverContainer;
6+
7+
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;
8+
9+
public class BrowserWebDriverContainerTest {
10+
11+
private static final String NO_PROXY_KEY = "no_proxy";
12+
13+
private static final String NO_PROXY_VALUE = "localhost,.noproxy-domain.com";
14+
15+
@Test
16+
public void honorPresetNoProxyEnvironment() {
17+
try (
18+
BrowserWebDriverContainer chromeWithNoProxySet = (BrowserWebDriverContainer) new BrowserWebDriverContainer()
19+
.withCapabilities(new ChromeOptions())
20+
.withEnv(NO_PROXY_KEY, NO_PROXY_VALUE)
21+
) {
22+
chromeWithNoProxySet.start();
23+
24+
Object noProxy = chromeWithNoProxySet.getEnvMap().get(NO_PROXY_KEY);
25+
assertEquals("no_proxy should be preserved by the container rule", NO_PROXY_VALUE, noProxy);
26+
}
27+
}
28+
29+
@Test
30+
public void provideDefaultNoProxyEnvironmentIfNotSet() {
31+
try (
32+
BrowserWebDriverContainer chromeWithoutNoProxySet = new BrowserWebDriverContainer()
33+
.withCapabilities(new ChromeOptions())
34+
35+
) {
36+
chromeWithoutNoProxySet.start();
37+
38+
Object noProxy = chromeWithoutNoProxySet.getEnvMap().get(NO_PROXY_KEY);
39+
assertEquals("no_proxy should be set to default if not already present", "localhost", noProxy);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)