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) {
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
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);
}
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)) {
}
@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");