Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BrowserWebDriverContainer to honor existing no_proxy setting #929

Merged
merged 8 commits into from
Mar 19, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class BrowserWebDriverContainer<SELF extends BrowserWebDriverContainer<SE
private static final int SELENIUM_PORT = 4444;
private static final int VNC_PORT = 5900;

private static final String NO_PROXY_KEY = "no_proxy";

@Nullable
private Capabilities capabilities;
private boolean customImageNameIsSet = false;
Expand Down Expand Up @@ -156,7 +158,11 @@ protected void configure() {

addExposedPorts(SELENIUM_PORT, VNC_PORT);
addEnv("TZ", timeZone);
addEnv("no_proxy", "localhost");

if (!getEnvMap().containsKey(NO_PROXY_KEY)) {
addEnv(NO_PROXY_KEY, "localhost");
}

setCommand("/opt/bin/entry_point.sh");

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.testcontainers.junit;

import org.junit.Test;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testcontainers.containers.BrowserWebDriverContainer;

import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;

public class BrowserWebDriverContainerTest {

private static final String NO_PROXY_KEY = "no_proxy";

private static final String NO_PROXY_VALUE = "localhost,.noproxy-domain.com";

@Test
public void honorPresetNoProxyEnvironment() {
try (
BrowserWebDriverContainer chromeWithNoProxySet = (BrowserWebDriverContainer) new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions())
.withEnv(NO_PROXY_KEY, NO_PROXY_VALUE)
) {
chromeWithNoProxySet.start();

Object noProxy = chromeWithNoProxySet.getEnvMap().get(NO_PROXY_KEY);
assertEquals("no_proxy should be preserved by the container rule", NO_PROXY_VALUE, noProxy);
}
}

@Test
public void provideDefaultNoProxyEnvironmentIfNotSet() {
try (
BrowserWebDriverContainer chromeWithoutNoProxySet = new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions())

) {
chromeWithoutNoProxySet.start();

Object noProxy = chromeWithoutNoProxySet.getEnvMap().get(NO_PROXY_KEY);
assertEquals("no_proxy should be set to default if not already present", "localhost", noProxy);
}
}
}