summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-03-10 23:19:01 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-03-11 13:50:29 +0100
commitdc41fb29beab432e573f994ee559c0f9b2b4b394 (patch)
tree097f3e4626dd5c094dac345ee1f8e820c075f163
parent20570f275c8a996939c264bf032615554e784fc5 (diff)
downloadsonarqube-dc41fb29beab432e573f994ee559c0f9b2b4b394.tar.gz
sonarqube-dc41fb29beab432e573f994ee559c0f9b2b4b394.zip
SONAR-7429 Should be possible to specify "https.proxyHost" and "https.proxyPort" in "conf/sonar.properties"
-rw-r--r--sonar-application/src/main/assembly/conf/sonar.properties6
-rw-r--r--sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java16
-rw-r--r--sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java10
3 files changed, 23 insertions, 9 deletions
diff --git a/sonar-application/src/main/assembly/conf/sonar.properties b/sonar-application/src/main/assembly/conf/sonar.properties
index f8804f4560d..905c626599a 100644
--- a/sonar-application/src/main/assembly/conf/sonar.properties
+++ b/sonar-application/src/main/assembly/conf/sonar.properties
@@ -248,6 +248,10 @@
#http.proxyHost=
#http.proxyPort=
+# HTTPS proxy (default none)
+#https.proxyHost=
+#https.proxyPort=
+
# NT domain name if NTLM proxy is used
#http.auth.ntlm.domain=
@@ -255,7 +259,7 @@
#socksProxyHost=
#socksProxyPort=
-# proxy authentication. The 2 following properties are used for HTTP and SOCKS proxies.
+# Proxy authentication (used for HTTP, HTTPS and SOCKS proxies)
#http.proxyUser=
#http.proxyPassword=
diff --git a/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java b/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java
index 69c2f14aa4a..9d7b87e1bd6 100644
--- a/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java
+++ b/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java
@@ -75,7 +75,7 @@ public class DefaultHttpDownloader extends HttpDownloader {
public DefaultHttpDownloader(Server server, Settings settings, @Nullable Integer connectTimeout, @Nullable Integer readTimeout) {
this.readTimeout = readTimeout;
this.connectTimeout = connectTimeout;
- downloader = new BaseHttpDownloader(new ProxySystem(), settings, server.getVersion());
+ downloader = new BaseHttpDownloader(new SystemFacade(), settings, server.getVersion());
}
public DefaultHttpDownloader(Settings settings) {
@@ -89,7 +89,7 @@ public class DefaultHttpDownloader extends HttpDownloader {
public DefaultHttpDownloader(Settings settings, @Nullable Integer connectTimeout, @Nullable Integer readTimeout) {
this.readTimeout = readTimeout;
this.connectTimeout = connectTimeout;
- downloader = new BaseHttpDownloader(new ProxySystem(), settings, null);
+ downloader = new BaseHttpDownloader(new SystemFacade(), settings, null);
}
@Override
@@ -157,7 +157,12 @@ public class DefaultHttpDownloader extends HttpDownloader {
throw new SonarException(String.format("Fail to download: %s (%s)", uri, getProxySynthesis(uri)), e);
}
- static class ProxySystem {
+ /**
+ * Facade to allow unit tests to verify calls to {@link System}.
+ * This class could be replaced by {@link org.sonar.api.utils.System2},
+ * but it sounds overkill to define {@link #setDefaultAuthenticator(Authenticator)}.
+ */
+ static class SystemFacade {
public void setProperty(String key, String value) {
System.setProperty(key, value);
}
@@ -175,16 +180,17 @@ public class DefaultHttpDownloader extends HttpDownloader {
private static final List<String> PROXY_SETTINGS = ImmutableList.of(
"http.proxyHost", "http.proxyPort", "http.nonProxyHosts",
+ "https.proxyHost", "https.proxyPort",
"http.auth.ntlm.domain", "socksProxyHost", "socksProxyPort");
private String userAgent;
- BaseHttpDownloader(ProxySystem system, Settings settings, @Nullable String userAgent) {
+ BaseHttpDownloader(SystemFacade system, Settings settings, @Nullable String userAgent) {
initProxy(system, settings);
initUserAgent(userAgent);
}
- private void initProxy(ProxySystem system, Settings settings) {
+ private void initProxy(SystemFacade system, Settings settings) {
// propagate system properties
for (String key : PROXY_SETTINGS) {
if (settings.hasKey(key)) {
diff --git a/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java b/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java
index d25429bbc78..906c96a2013 100644
--- a/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java
@@ -255,22 +255,26 @@ public class DefaultHttpDownloaderTest {
}
@Test
- public void configure_http_proxy() {
- DefaultHttpDownloader.ProxySystem system = mock(DefaultHttpDownloader.ProxySystem.class);
+ public void configure_http_and_https_proxies() {
+ DefaultHttpDownloader.SystemFacade system = mock(DefaultHttpDownloader.SystemFacade.class);
Settings settings = new Settings();
settings.setProperty("http.proxyHost", "1.2.3.4");
settings.setProperty("http.proxyPort", "80");
+ settings.setProperty("https.proxyHost", "5.6.7.8");
+ settings.setProperty("https.proxyPort", "443");
new DefaultHttpDownloader.BaseHttpDownloader(system, settings, null);
verify(system).setProperty("http.proxyHost", "1.2.3.4");
verify(system).setProperty("http.proxyPort", "80");
+ verify(system).setProperty("https.proxyHost", "5.6.7.8");
+ verify(system).setProperty("https.proxyPort", "443");
verify(system, never()).setDefaultAuthenticator(any(Authenticator.class));
}
@Test
public void configure_http_proxy_credentials() {
- DefaultHttpDownloader.ProxySystem system = mock(DefaultHttpDownloader.ProxySystem.class);
+ DefaultHttpDownloader.SystemFacade system = mock(DefaultHttpDownloader.SystemFacade.class);
Settings settings = new Settings();
settings.setProperty("https.proxyHost", "1.2.3.4");
settings.setProperty("http.proxyUser", "the_login");