Skip to content

Commit

Permalink
fix: Makes SslClientAuthFunctionalTest work with both java 8 and 11 (#…
Browse files Browse the repository at this point in the history
…10156) (#10159)

Co-authored-by: Alan Sheinberg <57688982+AlanConfluent@users.noreply.github.com>
  • Loading branch information
mjsax and AlanConfluent authored Dec 12, 2023
1 parent c399781 commit 49ca862
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static io.confluent.ksql.serde.FormatFactory.KAFKA;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static java.util.Collections.emptyMap;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand All @@ -44,6 +45,8 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLHandshakeException;

import io.netty.handler.codec.http.websocketx.WebSocketHandshakeException;
import kafka.zookeeper.ZooKeeperClientException;
import org.apache.kafka.common.config.SslConfigs;
import org.junit.Before;
Expand Down Expand Up @@ -112,7 +115,10 @@ public void shouldNotBeAbleToUseCliIfClientDoesNotProvideCertificate() {

// Then:
assertThat(e.getCause(), (is(instanceOf(ExecutionException.class))));
assertThat(e.getCause(), (hasCause(is(instanceOf(SSLHandshakeException.class)))));
// Make this compatible with both java 8 and 11.
assertThat(e.getCause(), anyOf(
hasCause(hasCause(is(instanceOf(SSLHandshakeException.class)))),
hasCause(is(instanceOf(SSLHandshakeException.class)))));
}

@Test
Expand All @@ -133,10 +139,16 @@ public void shouldNotBeAbleToUseWssIfClientDoesNotTrustServerCert() {
givenClientConfiguredWithoutCertificate();

// When:
assertThrows(
SSLHandshakeException.class,
() -> WebsocketUtils.makeWsRequest(JSON_KSQL_REQUEST, clientProps, REST_APP)
final Exception e = assertThrows(
Exception.class,
() -> WebsocketUtils.makeWsRequest(JSON_KSQL_REQUEST, clientProps, REST_APP)
);
assertThat(e, anyOf(is(instanceOf(RuntimeException.class)),
is(instanceOf(SSLHandshakeException.class))));
if (e instanceof RuntimeException) {
assertThat(e.getCause(), is(instanceOf(ExecutionException.class)));
assertThat(e.getCause(), hasCause(instanceOf(WebSocketHandshakeException.class)));
}
}

@Test
Expand Down

0 comments on commit 49ca862

Please sign in to comment.