Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX JENKINS-29266] Add HTTP_PROXY and HTTPS_PROXY variables to the p…
…rocess environment that execute the npm install of global packages. The proxy URL is the same used to download the nodejs installer and could be setup in Jenkins configuration.
- Loading branch information
Showing
4 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/java/jenkins/plugins/nodejs/tools/NodeJSInstallerProxyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package jenkins.plugins.nodejs.tools; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameters; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.powermock.reflect.Whitebox; | ||
|
||
import hudson.EnvVars; | ||
import hudson.ProxyConfiguration; | ||
|
||
@Issue("JENKINS-29266") | ||
@RunWith(Parameterized.class) | ||
public class NodeJSInstallerProxyTest { | ||
|
||
@Parameters(name = "proxy url = {0}") | ||
public static String[] data() throws MalformedURLException { | ||
return new String[] { "http://proxy.example.org:8080", "http://user:password@proxy.example.org:8080" }; | ||
} | ||
|
||
@Rule | ||
public JenkinsRule r = new JenkinsRule(); | ||
private String host; | ||
private int port; | ||
private String username; | ||
private String password; | ||
private String expectedURL; | ||
|
||
public NodeJSInstallerProxyTest(String url) throws Exception { | ||
URL proxyURL = new URL(url); | ||
|
||
this.expectedURL = url; | ||
this.host = proxyURL.getHost(); | ||
this.port = proxyURL.getPort(); | ||
if (proxyURL.getUserInfo() != null) { | ||
String[] userInfo = proxyURL.getUserInfo().split(":"); | ||
this.username = userInfo[0]; | ||
this.password = userInfo[1]; | ||
} | ||
} | ||
|
||
@Test | ||
public void test_proxy_settings() throws Exception { | ||
ProxyConfiguration proxycfg = new ProxyConfiguration(host, port, username, password); | ||
proxycfg.save(); | ||
|
||
NodeJSInstaller installer = new NodeJSInstaller("test-id", "grunt", NodeJSInstaller.DEFAULT_NPM_PACKAGES_REFRESH_HOURS); | ||
EnvVars env = new EnvVars(); | ||
Whitebox.invokeMethod(installer, "buildProxyEnvVars", env); | ||
|
||
assertThat(env.keySet(), CoreMatchers.hasItems("HTTP_PROXY", "HTTPS_PROXY")); | ||
assertThat(env.get("HTTP_PROXY"), CoreMatchers.is(expectedURL)); | ||
assertThat(env.get("HTTPS_PROXY"), CoreMatchers.is(expectedURL)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters