diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-04-14 18:01:27 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-04-14 18:30:02 +0200 |
commit | ec0c9c265fed27964480ce51edc8a191b5234be7 (patch) | |
tree | 8e6cf6822f764f97779776bf0f8133df3191ecc8 /sonar-core | |
parent | c32b3042bfdc8991ee42d7ae3855226018561ae8 (diff) | |
download | sonarqube-ec0c9c265fed27964480ce51edc8a191b5234be7.tar.gz sonarqube-ec0c9c265fed27964480ce51edc8a191b5234be7.zip |
SONAR-7429 defaults of HTTPS proxy are values of HTTP proxy
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java | 18 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java | 30 |
2 files changed, 46 insertions, 2 deletions
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 9d7b87e1bd6..d7b343787ad 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 @@ -177,10 +177,14 @@ public class DefaultHttpDownloader extends HttpDownloader { private static final String GET = "GET"; private static final String HTTP_PROXY_USER = "http.proxyUser"; private static final String HTTP_PROXY_PASSWORD = "http.proxyPassword"; + private static final String HTTP_PROXY_HOST = "http.proxyHost"; + private static final String HTTPS_PROXY_HOST = "https.proxyHost"; + private static final String HTTP_PROXY_PORT = "http.proxyPort"; + private static final String HTTPS_PROXY_PORT = "https.proxyPort"; private static final List<String> PROXY_SETTINGS = ImmutableList.of( - "http.proxyHost", "http.proxyPort", "http.nonProxyHosts", - "https.proxyHost", "https.proxyPort", + HTTP_PROXY_HOST, HTTP_PROXY_PORT, "http.nonProxyHosts", + HTTPS_PROXY_HOST, HTTPS_PROXY_PORT, "http.auth.ntlm.domain", "socksProxyHost", "socksProxyPort"); private String userAgent; @@ -197,6 +201,10 @@ public class DefaultHttpDownloader extends HttpDownloader { system.setProperty(key, settings.getString(key)); } } + // defaults of HTTPS properties are the values of HTTP properties + setSystemPropertyToDefaultIfNotSet(system, settings, HTTPS_PROXY_HOST, HTTP_PROXY_HOST); + setSystemPropertyToDefaultIfNotSet(system, settings, HTTPS_PROXY_PORT, HTTP_PROXY_PORT); + // register credentials String login = settings.getString(HTTP_PROXY_USER); if (isNotEmpty(login)) { @@ -204,6 +212,12 @@ public class DefaultHttpDownloader extends HttpDownloader { } } + private static void setSystemPropertyToDefaultIfNotSet(SystemFacade system, Settings settings, String httpsProperty, String httpProperty) { + if (!settings.hasKey(httpsProperty) && settings.hasKey(httpProperty)) { + system.setProperty(httpsProperty, settings.getString(httpProperty)); + } + } + private void initUserAgent(@Nullable String sonarVersion) { userAgent = sonarVersion == null ? "SonarQube" : String.format("SonarQube %s", sonarVersion); System.setProperty("http.agent", userAgent); 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 906c96a2013..f9296bcd139 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 @@ -57,7 +57,9 @@ import org.sonar.api.utils.SonarException; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -273,6 +275,21 @@ public class DefaultHttpDownloaderTest { } @Test + public void https_defaults_are_http_properties() { + DefaultHttpDownloader.SystemFacade system = mock(DefaultHttpDownloader.SystemFacade.class); + Settings settings = new Settings(); + settings.setProperty("http.proxyHost", "1.2.3.4"); + settings.setProperty("http.proxyPort", "80"); + + 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", "1.2.3.4"); + verify(system).setProperty("https.proxyPort", "80"); + } + + @Test public void configure_http_proxy_credentials() { DefaultHttpDownloader.SystemFacade system = mock(DefaultHttpDownloader.SystemFacade.class); Settings settings = new Settings(); @@ -297,6 +314,19 @@ public class DefaultHttpDownloaderTest { })); } + @Test + public void no_http_proxy_settings_by_default() { + DefaultHttpDownloader.SystemFacade system = mock(DefaultHttpDownloader.SystemFacade.class); + Settings settings = new Settings(); + new DefaultHttpDownloader.BaseHttpDownloader(system, settings, null); + + verify(system, never()).setProperty(eq("http.proxyHost"), anyString()); + verify(system, never()).setProperty(eq("https.proxyHost"), anyString()); + verify(system, never()).setProperty(eq("http.proxyPort"), anyString()); + verify(system, never()).setProperty(eq("https.proxyPort"), anyString()); + verify(system, never()).setDefaultAuthenticator(any(Authenticator.class)); + } + } class FakeProxy extends Proxy { |