Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw IAE in case neither address nor host is specified for the proxy #1592

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ public static ProxyProvider.TypeSpec builder() {
this.password = builder.password;
this.nonProxyHostPredicate = builder.nonProxyHostPredicate;
if (Objects.isNull(builder.address)) {
this.address = () -> AddressUtils.createResolved(builder.host, builder.port);
if (builder.host != null) {
this.address = () -> AddressUtils.createResolved(builder.host, builder.port);
}
else {
throw new IllegalArgumentException("Neither address nor host is specified");
}
}
else {
this.address = builder.address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

class ProxyProviderTest {

Expand Down Expand Up @@ -195,6 +196,14 @@ void nonProxyHosts_builderDefault_empty() {
assertThat(pred.test(someAddress("localhost"))).as("Default should proxy").isFalse();
}

@Test
void shouldNotCreateProxyProviderWithMissingRemoteHostInfo() {
ProxyProvider.Build builder = (ProxyProvider.Build) ProxyProvider.builder().type(ProxyProvider.Proxy.HTTP);
assertThatIllegalArgumentException()
.isThrownBy(builder::build)
.withMessage("Neither address nor host is specified");
}

private ProxyProvider createProxy(InetSocketAddress address, Function<String, String> passwordFunc) {
return ProxyProvider.builder()
.type(ProxyProvider.Proxy.SOCKS5)
Expand Down