Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed how wrapped KsqlTopicAuthorizationException error messages are displayed #3258

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 @@ -72,10 +72,10 @@ public static Response accessDenied(final String msg) {
.build();
}

public static Response accessDeniedFromKafka(final Exception error) {
public static Response accessDeniedFromKafka(final Throwable t) {
return Response
.status(FORBIDDEN)
.entity(new KsqlErrorMessage(ERROR_CODE_FORBIDDEN_KAFKA_ACCESS, error.getMessage()))
.entity(new KsqlErrorMessage(ERROR_CODE_FORBIDDEN_KAFKA_ACCESS, t))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,10 @@ public void shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException()
@Test
public void shouldReturnForbiddenKafkaAccessIfRootCauseKsqlTopicAuthorizationException() {
// Given:
doThrow(new KsqlException("", new KsqlTopicAuthorizationException(
AclOperation.DELETE,
Collections.singleton("topic")))).when(topicAccessValidator).validate(any(), any(), any());
doThrow(new KsqlException("Could not delete the corresponding kafka topic: topic",
new KsqlTopicAuthorizationException(
AclOperation.DELETE,
Collections.singleton("topic")))).when(topicAccessValidator).validate(any(), any(), any());


// When:
Expand All @@ -676,6 +677,9 @@ public void shouldReturnForbiddenKafkaAccessIfRootCauseKsqlTopicAuthorizationExc
// Then:
assertThat(result, is(instanceOf(KsqlErrorMessage.class)));
assertThat(result.getErrorCode(), is(Errors.ERROR_CODE_FORBIDDEN_KAFKA_ACCESS));
assertThat(result.getMessage(), is(
"Could not delete the corresponding kafka topic: topic\n" +
"Caused by: Authorization denied to Delete on topic(s): [topic]"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import io.confluent.ksql.parser.tree.Statement;
import io.confluent.ksql.planner.PlanSourceExtractorVisitor;
import io.confluent.ksql.planner.plan.OutputNode;
import io.confluent.ksql.rest.entity.KsqlErrorMessage;
import io.confluent.ksql.rest.entity.KsqlRequest;
import io.confluent.ksql.rest.entity.StreamedRow;
import io.confluent.ksql.rest.server.StatementParser;
Expand Down Expand Up @@ -468,8 +469,10 @@ public void shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException()
final Response expected = Errors.accessDeniedFromKafka(
new KsqlTopicAuthorizationException(AclOperation.READ, Collections.singleton(topicName)));

final KsqlErrorMessage responseEntity = (KsqlErrorMessage) response.getEntity();
final KsqlErrorMessage expectedEntity = (KsqlErrorMessage) expected.getEntity();
assertEquals(response.getStatus(), expected.getStatus());
assertEquals(response.getEntity(), expected.getEntity());
assertEquals(responseEntity.getMessage(), expectedEntity.getMessage());
}

@Test
Expand Down Expand Up @@ -500,8 +503,10 @@ public void shouldReturnForbiddenKafkaAccessIfRootCauseKsqlTopicAuthorizationExc
"",
new KsqlTopicAuthorizationException(AclOperation.READ, Collections.singleton(topicName))));

final KsqlErrorMessage responseEntity = (KsqlErrorMessage) response.getEntity();
final KsqlErrorMessage expectedEntity = (KsqlErrorMessage) expected.getEntity();
assertEquals(response.getStatus(), expected.getStatus());
assertEquals(response.getEntity(), expected.getEntity());
assertEquals(responseEntity.getMessage(), expectedEntity.getMessage());
}

@Test
Expand Down