use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class DistributingExecutorTest method shouldThrowServerExceptionIfServerServiceContextIsDeniedAuthorization.
@Test
public void shouldThrowServerExceptionIfServerServiceContextIsDeniedAuthorization() {
// Given:
final KsqlSecurityContext userSecurityContext = new KsqlSecurityContext(Optional.empty(), SandboxedServiceContext.create(TestServiceContext.create()));
final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new ListProperties(Optional.empty()));
final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
doNothing().when(authorizationValidator).checkAuthorization(eq(userSecurityContext), any(), any());
doThrow(KsqlTopicAuthorizationException.class).when(authorizationValidator).checkAuthorization(ArgumentMatchers.argThat(securityContext -> securityContext.getServiceContext() == serviceContext), any(), any());
// When:
final Exception e = assertThrows(KsqlServerException.class, () -> distributor.execute(configured, executionContext, userSecurityContext));
// Then:
assertThat(e.getCause(), (is(instanceOf(KsqlTopicAuthorizationException.class))));
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class DistributingExecutorTest method shouldThrowExceptionWhenInsertIntoUnknownStream.
@Test
public void shouldThrowExceptionWhenInsertIntoUnknownStream() {
// Given
final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new InsertInto(SourceName.of("s1"), mock(Query.class)));
final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
doReturn(null).when(metaStore).getSource(SourceName.of("s1"));
// When:
final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, mock(KsqlSecurityContext.class)));
// Then:
assertThat(e.getMessage(), containsString("Cannot insert into an unknown stream/table: `s1`"));
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class DistributingExecutorTest method shouldThrowExceptionWhenInsertIntoSourceWithHeaders.
@Test
public void shouldThrowExceptionWhenInsertIntoSourceWithHeaders() {
// Given
final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new InsertInto(SourceName.of("s1"), mock(Query.class)));
final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
final DataSource dataSource = mock(DataSource.class);
final LogicalSchema schema = mock(LogicalSchema.class);
doReturn(dataSource).when(metaStore).getSource(SourceName.of("s1"));
doReturn(schema).when(dataSource).getSchema();
doReturn(ImmutableList.of(ColumnName.of("a"))).when(schema).headers();
when(dataSource.getKafkaTopicName()).thenReturn("topic");
// When:
final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, mock(KsqlSecurityContext.class)));
// Then:
assertThat(e.getMessage(), is("Cannot insert into s1 because it has header columns"));
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class DistributingExecutorTest method shouldThrowExceptionIfUserServiceContextIsDeniedAuthorization.
@Test
public void shouldThrowExceptionIfUserServiceContextIsDeniedAuthorization() {
// Given:
final KsqlSecurityContext userSecurityContext = new KsqlSecurityContext(Optional.empty(), mock(ServiceContext.class));
final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new ListProperties(Optional.empty()));
final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
doThrow(KsqlTopicAuthorizationException.class).when(authorizationValidator).checkAuthorization(eq(userSecurityContext), any(), eq(configured.getStatement()));
// When:
assertThrows(KsqlTopicAuthorizationException.class, () -> distributor.execute(configured, executionContext, userSecurityContext));
}
use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.
the class DistributingExecutorTest method shouldNotEnqueueRedundantIfNotExists.
@Test
public void shouldNotEnqueueRedundantIfNotExists() {
// Given:
final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new CreateStream(SourceName.of("TEST"), TableElements.of(), false, true, CreateSourceProperties.from(ImmutableMap.of(CommonCreateConfigs.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral("topic"), CommonCreateConfigs.VALUE_FORMAT_PROPERTY, new StringLiteral("json"))), false));
final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
final DataSource dataSource = mock(DataSource.class);
doReturn(dataSource).when(metaStore).getSource(SourceName.of("TEST"));
// When:
final StatementExecutorResponse response = distributor.execute(configured, executionContext, securityContext);
// Then:
assertThat("Should be present", response.getEntity().isPresent());
assertThat(((WarningEntity) response.getEntity().get()).getMessage(), containsString(""));
}
Aggregations