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;
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)) {
}
}
+ 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);
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;
verify(system, never()).setDefaultAuthenticator(any(Authenticator.class));
}
+ @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);
}));
}
+ @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 {