|
18 | 18 |
|
19 | 19 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
20 | 20 | import static org.junit.jupiter.api.Assertions.assertThrows; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
21 | 22 | import static org.mockito.ArgumentMatchers.any; |
22 | 23 | import static org.mockito.Mockito.doThrow; |
23 | 24 | import static org.mockito.Mockito.mock; |
| 25 | +import static org.mockito.Mockito.verifyNoInteractions; |
24 | 26 |
|
25 | 27 | import java.sql.SQLException; |
26 | 28 | import java.util.ArrayList; |
27 | 29 | import java.util.Collection; |
| 30 | +import java.util.Collections; |
28 | 31 | import java.util.Optional; |
29 | 32 | import org.apache.arrow.flight.CallOption; |
30 | 33 | import org.apache.arrow.flight.CallStatus; |
31 | 34 | import org.apache.arrow.flight.CloseSessionRequest; |
| 35 | +import org.apache.arrow.flight.FlightDescriptor; |
| 36 | +import org.apache.arrow.flight.FlightEndpoint; |
| 37 | +import org.apache.arrow.flight.FlightInfo; |
32 | 38 | import org.apache.arrow.flight.FlightStatusCode; |
| 39 | +import org.apache.arrow.flight.Location; |
| 40 | +import org.apache.arrow.flight.Ticket; |
33 | 41 | import org.apache.arrow.flight.sql.FlightSqlClient; |
| 42 | +import org.apache.arrow.memory.BufferAllocator; |
| 43 | +import org.apache.arrow.memory.RootAllocator; |
| 44 | +import org.apache.arrow.vector.types.pojo.Schema; |
| 45 | +import org.junit.jupiter.api.Test; |
34 | 46 | import org.junit.jupiter.params.ParameterizedTest; |
35 | 47 | import org.junit.jupiter.params.provider.MethodSource; |
36 | 48 |
|
37 | 49 | public class ArrowFlightSqlClientHandlerTest { |
38 | 50 |
|
| 51 | + @Test |
| 52 | + public void testGetStreamsRejectsUnencryptedEndpointOnEncryptedConnection() throws Exception { |
| 53 | + try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE)) { |
| 54 | + final FlightSqlClient sqlClient = mock(FlightSqlClient.class); |
| 55 | + final ArrowFlightSqlClientHandler.Builder builder = |
| 56 | + new ArrowFlightSqlClientHandler.Builder() |
| 57 | + .withHost("localhost") |
| 58 | + .withPort(443) |
| 59 | + .withEncryption(true) |
| 60 | + .withUsername("user") |
| 61 | + .withPassword("password") |
| 62 | + .withBufferAllocator(allocator); |
| 63 | + |
| 64 | + final ArrowFlightSqlClientHandler handler = |
| 65 | + new ArrowFlightSqlClientHandler( |
| 66 | + "cacheKey", sqlClient, builder, new ArrayList<>(), Optional.empty(), null); |
| 67 | + |
| 68 | + // A server-supplied location that asks the driver to drop back to plaintext. |
| 69 | + final FlightInfo flightInfo = |
| 70 | + new FlightInfo( |
| 71 | + new Schema(Collections.emptyList()), |
| 72 | + FlightDescriptor.command(new byte[0]), |
| 73 | + Collections.singletonList( |
| 74 | + new FlightEndpoint( |
| 75 | + new Ticket(new byte[0]), |
| 76 | + Location.forGrpcInsecure("other.example.com", 443))), |
| 77 | + -1, |
| 78 | + -1); |
| 79 | + |
| 80 | + final SQLException ex = |
| 81 | + assertThrows(SQLException.class, () -> handler.getStreams(flightInfo)); |
| 82 | + assertTrue(ex.getMessage().contains("without encryption"), ex.getMessage()); |
| 83 | + // The credentials must not have been sent anywhere. |
| 84 | + verifyNoInteractions(sqlClient); |
| 85 | + } |
| 86 | + } |
| 87 | + |
39 | 88 | @ParameterizedTest |
40 | 89 | @MethodSource |
41 | 90 | public void testCloseHandlesFlightRuntimeException( |
|
0 commit comments