Fix disabled local proxy configuration being used over global config (#1780)

The original proxy configuration implementation only used the global configuration if the local proxy configuration was not provided (i.e. null). This PR adds the corner case where a local configuration is provided, but disabled. In this case, the global proxy configuration will be used as a fallback as well.
This commit is contained in:
Konstantin Schaper
2021-08-25 08:19:52 +02:00
committed by GitHub
parent 7e94f434dd
commit 44f25d6b15
5 changed files with 41 additions and 3 deletions

View File

@@ -147,7 +147,7 @@ public class SvnMirrorCommand extends AbstractSvnCommand implements MirrorComman
}
};
checkAndApplyProxyConfiguration(
authManager, mirrorCommandRequest.getProxyConfiguration().orElse(globalProxyConfiguration), url
authManager, mirrorCommandRequest.getProxyConfiguration().filter(ProxyConfiguration::isEnabled).orElse(globalProxyConfiguration), url
);
return authManager;
}

View File

@@ -53,6 +53,7 @@ import java.util.function.Consumer;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static sonia.scm.repository.api.MirrorCommandResult.ResultType.OK;
@@ -197,6 +198,18 @@ public class SvnMirrorCommandTest extends AbstractSvnCommandTestBase {
assertThat(authenticationManager.getProxyPasswordValue()).isNull();
}
@Test
public void shouldNotApplyDisabledLocalProxySettings() throws SVNException {
MirrorCommandRequest request = new MirrorCommandRequest();
request.setProxyConfiguration(createDisabledProxyConfiguration());
BasicAuthenticationManager authenticationManager = createAuthenticationManager(request);
assertThat(authenticationManager.getProxyHost()).isNull();
assertThat(authenticationManager.getProxyPort()).isZero();
assertThat(authenticationManager.getProxyUserName()).isNull();
assertThat(authenticationManager.getProxyPasswordValue()).isNull();
}
private ProxyConfiguration createProxyConfiguration() {
ProxyConfiguration configuration = mock(ProxyConfiguration.class);
when(configuration.isEnabled()).thenReturn(true);
@@ -205,6 +218,14 @@ public class SvnMirrorCommandTest extends AbstractSvnCommandTestBase {
return configuration;
}
private ProxyConfiguration createDisabledProxyConfiguration() {
ProxyConfiguration configuration = mock(ProxyConfiguration.class);
when(configuration.isEnabled()).thenReturn(false);
lenient().when(configuration.getHost()).thenReturn("proxy.hitchhiker.com");
lenient().when(configuration.getPort()).thenReturn(3128);
return configuration;
}
private BasicAuthenticationManager createAuthenticationManager() throws SVNException {
return createAuthenticationManager(new MirrorCommandRequest());
}