Skip to content

Commit

Permalink
Support pipe and new line in the 'No proxy host'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan770 committed Sep 19, 2024
1 parent 4e451f6 commit c49255f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/io/jenkins/plugins/jfrog/CliEnvConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.jenkins.plugins.jfrog.configuration.JenkinsProxyConfiguration;
import org.apache.commons.lang3.StringUtils;


/**
* Configures JFrog CLI environment variables for the job.
*
Expand Down Expand Up @@ -66,7 +67,7 @@ private static void setupProxy(EnvVars env) {
env.put(HTTP_PROXY_ENV, proxyUrl);
env.put(HTTPS_PROXY_ENV, proxyUrl);
if (StringUtils.isNotBlank(proxyConfiguration.noProxy)) {
env.put(NO_PROXY, proxyConfiguration.noProxy);
env.put(NO_PROXY, noProxyExtractor(proxyConfiguration.noProxy));
}
}

Expand All @@ -79,4 +80,13 @@ private static void excludeProxyEnvFromPublishing(EnvVars env) {
String jfrogCliEnvExclude = env.getOrDefault(JFROG_CLI_ENV_EXCLUDE, JFROG_CLI_DEFAULT_EXCLUSIONS);
env.put(JFROG_CLI_ENV_EXCLUDE, String.join(";", jfrogCliEnvExclude, HTTP_PROXY_ENV, HTTPS_PROXY_ENV));
}

static String noProxyExtractor(String noProxyList) {
// Trim leading and trailing spaces
String noProxyListTrim = noProxyList.trim();
// Replace '|' with spaces and normalize whitespace
String noProxyListRemoveSpaceAndPipe = noProxyListTrim.replace("|", " ").replaceAll("\\s+", ";");
// Replace multiple spaces with a single semicolon
return noProxyListRemoveSpaceAndPipe.replaceAll(";+", ";").replaceAll(";$", "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.jenkins.plugins.jfrog;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;

import static io.jenkins.plugins.jfrog.CliEnvConfigurator.noProxyExtractor;
import static org.junit.Assert.assertEquals;

/**
* @author nathana
**/
@RunWith(Parameterized.class)
public class CliEnvConfiguratorNoProxyTest {
private final String noProxyList;
private final String expectedResult;

public CliEnvConfiguratorNoProxyTest(String noProxyList, String expectedResult) {
this.noProxyList = noProxyList;
this.expectedResult = expectedResult;
}

@Parameterized.Parameters
public static Collection<Object[]> dataProvider() {
return Arrays.asList(
// Positive tests
new Object[]{"artifactory.jfrog.io", "artifactory.jfrog.io"},
new Object[]{"artifactory.jfrog.io \n artifactory1.jfrog.io ", "artifactory.jfrog.io;artifactory1.jfrog.io"},
new Object[]{" artifactory.jfrog.io \n \r artifactory1.jfrog.io;artifactory2.jfrog.io \n artifactory3.jfrog.io | artifactory4.jfrog.io \n artifactory5.jfrog.io ", "artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io;artifactory4.jfrog.io;artifactory5.jfrog.io"},
new Object[]{"\r\n", ""},
new Object[]{";;;", ""},
new Object[]{"artifactory.jfrog.io;", "artifactory.jfrog.io"},
new Object[]{"artifactory.jfrog.io;artifactory1.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io"},
new Object[]{"artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io"},
new Object[]{"artifactory.jfrog.io \nartifactory1.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io"},
new Object[]{"artifactory.jfrog.io \nartifactory1.jfrog.io\nartifactory2.jfrog.io \n artifactory3.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io"}
);
}

@Test
public void testValidateCliVersion() {
assertEquals(expectedResult, noProxyExtractor(noProxyList));
}
}

0 comments on commit c49255f

Please sign in to comment.