Skip to content
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 @@ -822,7 +822,13 @@ public Builder verifyServer(boolean verifyServer) {
return this;
}

/** Create the client from this builder. */
/**
* Create the client from this builder.
*
* @throws IllegalArgumentException if the location uses a TCP-based scheme ({@code grpc},
* {@code grpc+tcp}, {@code grpc+tls}) and the location contains no port, or a port outside
* the range [1, 65535].
*/
public FlightClient build() {
final NettyChannelBuilder channelBuilder = builder.build();
return new FlightClient(builder.allocator(), channelBuilder.build(), builder.middleware());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ public NettyClientBuilder verifyServer(boolean verifyServer) {
return this;
}

/** Create the client from this builder. */
/**
* Create the client from this builder.
*
* @throws IllegalArgumentException if the URI uses a TCP-based scheme ({@code grpc}, {@code
* grpc+tcp}, {@code grpc+tls}) and the URI contains no port, or a port outside the range [1,
* 65535].
*/
public NettyChannelBuilder build() {
final NettyChannelBuilder builder;

Expand All @@ -140,9 +146,13 @@ public NettyChannelBuilder build() {
case LocationSchemes.GRPC_TLS:
{
final int port = location.getUri().getPort();
if (port < 0 || port > 65535) {
if (port == -1) {
throw new IllegalArgumentException(
"No port specified in location URI: " + location.getUri());
}
if (port < 1 || port > 65535) {
Comment thread
jbonofre marked this conversation as resolved.
throw new IllegalArgumentException(
"Invalid port " + port + ": must be between 0 and 65535.");
"Invalid port " + port + ": must be between 1 and 65535.");
Comment thread
jbonofre marked this conversation as resolved.
}
builder = NettyChannelBuilder.forAddress(location.getUri().getHost(), port);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public void testGetNonAuthenticatedEncryptedClientNoAuth() throws Exception {
try (ArrowFlightSqlClientHandler client =
new ArrowFlightSqlClientHandler.Builder()
.withHost(FLIGHT_SERVER_TEST_EXTENSION.getHost())
.withPort(FLIGHT_SERVER_TEST_EXTENSION.getPort())
.withTlsRootCertificates(tlsRootCertsPath)
.withClientCertificate(clientMTlsCertPath)
.withClientKey(clientMTlsKeyPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/** Tests for {@link Connection}. */
public class ConnectionTest {
Expand Down Expand Up @@ -204,21 +206,20 @@ public void testGetBasicClientAuthenticatedShouldOpenConnection() throws Excepti
}

/**
* Checks if the exception IllegalArgumentException is thrown when trying to establish an
* unencrypted connection providing with an invalid port.
*
* @throws SQLException on error.
* Checks if a SQLException is thrown when trying to establish an unencrypted connection with an
* invalid port.
*/
@Test
public void testUnencryptedConnectionProvidingInvalidPort() throws Exception {
@ParameterizedTest
@ValueSource(ints = {0, -1, 65536, 65537})
public void testUnencryptedConnectionProvidingInvalidPort(int invalidPort) {
final Properties properties = new Properties();

properties.put(ArrowFlightConnectionProperty.HOST.camelName(), "localhost");
properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest);
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest);
properties.put(ArrowFlightConnectionProperty.USE_ENCRYPTION.camelName(), false);
final String invalidUrl =
"jdbc:arrow-flight-sql://" + FLIGHT_SERVER_TEST_EXTENSION.getHost() + ":" + 65537;
"jdbc:arrow-flight-sql://" + FLIGHT_SERVER_TEST_EXTENSION.getHost() + ":" + invalidPort;

assertThrows(
SQLException.class,
Expand All @@ -240,6 +241,7 @@ public void testGetBasicClientNoAuthShouldOpenConnection() throws Exception {
try (ArrowFlightSqlClientHandler client =
new ArrowFlightSqlClientHandler.Builder()
.withHost(FLIGHT_SERVER_TEST_EXTENSION.getHost())
.withPort(FLIGHT_SERVER_TEST_EXTENSION.getPort())
.withBufferAllocator(allocator)
.withEncryption(false)
.build()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public void testGetNonAuthenticatedEncryptedClientNoAuth() throws Exception {
try (ArrowFlightSqlClientHandler client =
new ArrowFlightSqlClientHandler.Builder()
.withHost(FLIGHT_SERVER_TEST_EXTENSION.getHost())
.withPort(FLIGHT_SERVER_TEST_EXTENSION.getPort())
.withTlsRootCertificates(tlsRootCertsPath)
.withBufferAllocator(allocator)
.withEncryption(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public void testGetNonAuthenticatedEncryptedClientNoAuth() throws Exception {
try (ArrowFlightSqlClientHandler client =
new ArrowFlightSqlClientHandler.Builder()
.withHost(FLIGHT_SERVER_TEST_EXTENSION.getHost())
.withPort(FLIGHT_SERVER_TEST_EXTENSION.getPort())
.withSystemTrustStore(false)
.withTrustStorePath(trustStorePath)
.withTrustStorePassword(trustStorePass)
Expand Down
Loading