Skip to content

Commit

Permalink
feat: allow unsecured tcp server
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitgravitee committed Oct 17, 2024
1 parent 3b37b30 commit 09bbb47
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 09bbb47

Please sign in to comment.