use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.
the class ServerInfoResourceTest method shouldReturnServerInfo.
@Test
public void shouldReturnServerInfo() {
// When:
final EndpointResponse response = serverInfoResource.get();
// Then:
assertThat(response.getStatus(), equalTo(200));
assertThat(response.getEntity(), instanceOf(ServerInfo.class));
final ServerInfo serverInfo = (ServerInfo) response.getEntity();
assertThat(serverInfo, equalTo(new ServerInfo(AppInfo.getVersion(), KAFKA_CLUSTER_ID, KSQL_SERVICE_ID, "RUNNING")));
}
use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.
the class StreamedQueryResourceTest method shouldReturnForbiddenKafkaAccessForPullQueryAuthorizationDenied.
@Test
public void shouldReturnForbiddenKafkaAccessForPullQueryAuthorizationDenied() {
// Given:
when(mockStatementParser.<Query>parseSingleStatement(PULL_QUERY_STRING)).thenReturn(query);
doThrow(new KsqlTopicAuthorizationException(AclOperation.READ, Collections.singleton(TOPIC_NAME))).when(authorizationValidator).checkAuthorization(any(), any(), any());
// When:
final EndpointResponse response = testResource.streamQuery(securityContext, new KsqlRequest(PULL_QUERY_STRING, Collections.emptyMap(), Collections.emptyMap(), null), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context);
final KsqlErrorMessage responseEntity = (KsqlErrorMessage) response.getEntity();
final KsqlErrorMessage expectedEntity = (KsqlErrorMessage) AUTHORIZATION_ERROR_RESPONSE.getEntity();
assertEquals(response.getStatus(), AUTHORIZATION_ERROR_RESPONSE.getStatus());
assertEquals(responseEntity.getMessage(), expectedEntity.getMessage());
}
use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.
the class StreamedQueryResourceTest method shouldThrowOnDenyListedStreamProperty.
@Test
public void shouldThrowOnDenyListedStreamProperty() {
// Given:
when(mockStatementParser.<Query>parseSingleStatement(PULL_QUERY_STRING)).thenReturn(query);
testResource = new StreamedQueryResource(mockKsqlEngine, ksqlRestConfig, mockStatementParser, commandQueue, DISCONNECT_CHECK_INTERVAL, COMMAND_QUEUE_CATCHUP_TIMOEUT, activenessRegistrar, Optional.of(authorizationValidator), errorsHandler, denyListPropertyValidator, queryExecutor);
final Map<String, Object> props = new HashMap<>(ImmutableMap.of(StreamsConfig.APPLICATION_SERVER_CONFIG, "something:1"));
props.put(KsqlConfig.KSQL_PROPERTIES_OVERRIDES_DENYLIST, StreamsConfig.NUM_STREAM_THREADS_CONFIG);
testResource.configure(new KsqlConfig(props));
final Map<String, Object> overrides = ImmutableMap.of(StreamsConfig.NUM_STREAM_THREADS_CONFIG, 1);
doThrow(new KsqlException("deny override")).when(denyListPropertyValidator).validateAll(overrides);
when(errorsHandler.generateResponse(any(), any())).thenReturn(badRequest("A property override was set locally for a property that the " + "server prohibits overrides for: 'num.stream.threads'"));
// When:
final EndpointResponse response = testResource.streamQuery(securityContext, new KsqlRequest(PULL_QUERY_STRING, // stream properties
overrides, Collections.emptyMap(), null), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context);
// Then:
verify(denyListPropertyValidator).validateAll(overrides);
assertThat(response.getStatus(), CoreMatchers.is(BAD_REQUEST.code()));
assertThat(((KsqlErrorMessage) response.getEntity()).getMessage(), is("A property override was set locally for a property that the server prohibits " + "overrides for: '" + StreamsConfig.NUM_STREAM_THREADS_CONFIG + "'"));
}
use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.
the class StreamedQueryResourceTest method shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException.
@Test
public void shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException() {
// Given:
when(mockStatementParser.<Query>parseSingleStatement(PUSH_QUERY_STRING)).thenReturn(query);
doThrow(new KsqlTopicAuthorizationException(AclOperation.READ, Collections.singleton(TOPIC_NAME))).when(authorizationValidator).checkAuthorization(any(), any(), any());
// When:
final EndpointResponse response = testResource.streamQuery(securityContext, new KsqlRequest(PUSH_QUERY_STRING, Collections.emptyMap(), Collections.emptyMap(), null), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context);
final KsqlErrorMessage responseEntity = (KsqlErrorMessage) response.getEntity();
final KsqlErrorMessage expectedEntity = (KsqlErrorMessage) AUTHORIZATION_ERROR_RESPONSE.getEntity();
assertEquals(response.getStatus(), AUTHORIZATION_ERROR_RESPONSE.getStatus());
assertEquals(responseEntity.getMessage(), expectedEntity.getMessage());
}
use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.
the class ServerInternalKsqlClient method makeKsqlRequest.
@Override
public RestResponse<KsqlEntityList> makeKsqlRequest(final URI serverEndpoint, final String sql, final Map<String, ?> requestProperties) {
final KsqlRequest request = new KsqlRequest(sql, Collections.emptyMap(), requestProperties, null);
final EndpointResponse response = ksqlResource.handleKsqlStatements(securityContext, request);
final int status = response.getStatus();
if (status == OK.code()) {
return RestResponse.successful(status, (KsqlEntityList) response.getEntity());
} else {
return RestResponse.erroneous(status, (KsqlErrorMessage) response.getEntity());
}
}
Aggregations