diff --git a/gravitee-node-vertx/src/main/java/io/gravitee/node/vertx/server/VertxServerOptions.java b/gravitee-node-vertx/src/main/java/io/gravitee/node/vertx/server/VertxServerOptions.java index 2da393376..9f3d71461 100644 --- a/gravitee-node-vertx/src/main/java/io/gravitee/node/vertx/server/VertxServerOptions.java +++ b/gravitee-node-vertx/src/main/java/io/gravitee/node/vertx/server/VertxServerOptions.java @@ -20,8 +20,6 @@ import io.gravitee.node.api.certificate.KeyStoreLoaderOptions; import io.gravitee.node.api.certificate.TrustStoreLoaderOptions; import io.gravitee.node.api.server.ServerOptions; -import io.gravitee.node.vertx.cert.VertxKeyCertOptions; -import io.gravitee.node.vertx.cert.VertxTrustOptions; import io.gravitee.node.vertx.server.http.VertxHttpServerOptions; import io.gravitee.node.vertx.server.tcp.VertxTcpServerOptions; import io.vertx.core.http.ClientAuth; diff --git a/gravitee-node-vertx/src/main/java/io/gravitee/node/vertx/server/tcp/VertxTcpServerOptions.java b/gravitee-node-vertx/src/main/java/io/gravitee/node/vertx/server/tcp/VertxTcpServerOptions.java index cc87ab626..df039e8dd 100644 --- a/gravitee-node-vertx/src/main/java/io/gravitee/node/vertx/server/tcp/VertxTcpServerOptions.java +++ b/gravitee-node-vertx/src/main/java/io/gravitee/node/vertx/server/tcp/VertxTcpServerOptions.java @@ -27,11 +27,9 @@ public NetServerOptions createNetServerOptions(KeyCertOptions vertxKeyCertOption options.setPort(this.port); options.setHost(this.host); - if (this.secured && this.sni) { - options.setSni(true); + if (this.secured) { + options.setSni(this.sni); options.setClientAuth(ClientAuth.valueOf(clientAuth)); - } else { - throw new IllegalArgumentException("Cannot start unsecured TCP server or without SNI enabled"); } setupTcp(options, vertxKeyCertOptions, vertxTrustOptions); diff --git a/gravitee-node-vertx/src/test/java/io/gravitee/node/vertx/server/tcp/VertxTcpServerOptionsTest.java b/gravitee-node-vertx/src/test/java/io/gravitee/node/vertx/server/tcp/VertxTcpServerOptionsTest.java index 4e0a8b6a9..9e70ccb2f 100644 --- a/gravitee-node-vertx/src/test/java/io/gravitee/node/vertx/server/tcp/VertxTcpServerOptionsTest.java +++ b/gravitee-node-vertx/src/test/java/io/gravitee/node/vertx/server/tcp/VertxTcpServerOptionsTest.java @@ -336,26 +336,32 @@ void should_create_vertx_options() { } @Test - void should_throw_illegal_argument_exception_when_create_vertx_options_with_unsecured_options() { + void should_be_able_to_create_options_without_SNI() { environment.setProperty("servers[0].secured", "false"); + environment.setProperty("servers[0].ssl.sni", "false"); final VertxTcpServerOptions options = VertxTcpServerOptions.builder().prefix("servers[0]").environment(environment).build(); - final IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> options.createNetServerOptions(mock(KeyCertOptions.class), mock(TrustOptions.class)) - ); - assertThat(exception.getMessage()).isEqualTo("Cannot start unsecured TCP server or without SNI enabled"); + NetServerOptions netServerOptions = options.createNetServerOptions(mock(KeyCertOptions.class), mock(TrustOptions.class)); + assertThat(netServerOptions.getKeyCertOptions()).isNull(); + assertThat(netServerOptions.getTrustOptions()).isNull(); + assertThat(netServerOptions.getClientAuth()).isEqualTo(ClientAuth.NONE); + assertThat(netServerOptions.getEnabledCipherSuites()).isEmpty(); + assertThat(netServerOptions.getOpenSslEngineOptions()).isNull(); + assertThat(netServerOptions.isSsl()).isFalse(); + assertThat(netServerOptions.isSni()).isFalse(); } @Test - void should_throw_illegal_argument_exception_when_create_vertx_options_without_SNI() { + void should_be_able_to_create_secured_options_without_SNI() { environment.setProperty("servers[0].ssl.sni", "false"); final VertxTcpServerOptions options = VertxTcpServerOptions.builder().prefix("servers[0]").environment(environment).build(); - final IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> options.createNetServerOptions(mock(KeyCertOptions.class), mock(TrustOptions.class)) - ); - assertThat(exception.getMessage()).isEqualTo("Cannot start unsecured TCP server or without SNI enabled"); + NetServerOptions netServerOptions = options.createNetServerOptions(mock(KeyCertOptions.class), mock(TrustOptions.class)); + assertThat(netServerOptions.getKeyCertOptions()).isNotNull(); + assertThat(netServerOptions.getTrustOptions()).isNotNull(); + assertThat(netServerOptions.getClientAuth()).isEqualTo(ClientAuth.valueOf(CLIENT_AUTH.toUpperCase())); + assertThat(netServerOptions.getEnabledCipherSuites()).isNotEmpty(); + assertThat(netServerOptions.isSsl()).isTrue(); + assertThat(netServerOptions.isSni()).isFalse(); } }