Skip to content

Commit

Permalink
Throw IAE in case neither address nor host is specified for the proxy (
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg authored Apr 8, 2021
1 parent 15c394d commit ff6d886
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit ff6d886

Please sign in to comment.