Skip to content

Commit

Permalink
Address code review comments, added more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta committed Mar 28, 2024
1 parent e450fc0 commit afbc10c
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.http.HttpServerTransport;
import org.opensearch.http.netty4.ssl.SecureNetty4HttpServerTransport;
import org.opensearch.plugins.SecureHttpTransportSettingsProvider;
import org.opensearch.plugins.SecureTransportSettingsProvider;
import org.opensearch.plugins.TransportExceptionHandler;
Expand All @@ -35,8 +36,12 @@
import org.opensearch.security.test.helper.file.FileHelper;
import org.opensearch.telemetry.tracing.noop.NoopTracer;
import org.opensearch.transport.Transport;
import org.opensearch.transport.TransportAdapterProvider;

import io.netty.channel.ChannelInboundHandlerAdapter;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -125,6 +130,10 @@ public void testRegisterSecureHttpTransport() throws IOException {
NoopTracer.INSTANCE
);
assertThat(transports, hasKey("org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport"));
assertThat(
transports.get("org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport").get(),
not(nullValue())
);
}
}

Expand All @@ -142,6 +151,7 @@ public void testRegisterSecureTransport() throws IOException {
NoopTracer.INSTANCE
);
assertThat(transports, hasKey("org.opensearch.security.ssl.http.netty.SecuritySSLNettyTransport"));
assertThat(transports.get("org.opensearch.security.ssl.http.netty.SecuritySSLNettyTransport").get(), not(nullValue()));
}
}

Expand Down Expand Up @@ -247,4 +257,62 @@ public void testRegisterSecureTransportWithDuplicateSettings() throws IOExceptio
}
}
}

@Test
public void testRegisterSecureHttpTransportWithRequestHeaderVerifier() throws IOException {
class LocalHeaderVerifier extends ChannelInboundHandlerAdapter {}

final SecureHttpTransportSettingsProvider provider = new SecureHttpTransportSettingsProvider() {
@Override
public Collection<TransportAdapterProvider<HttpServerTransport>> getHttpTransportAdapterProviders(Settings settings) {
return List.of(new TransportAdapterProvider<HttpServerTransport>() {

@Override
public String name() {
// TODO Auto-generated method stub
return SecureNetty4HttpServerTransport.REQUEST_HEADER_VERIFIER;
}

@SuppressWarnings("unchecked")
@Override
public <C> Optional<C> create(Settings settings, HttpServerTransport transport, Class<C> adapterClass) {
return Optional.of((C) new LocalHeaderVerifier());
}

});
}

@Override
public Optional<TransportExceptionHandler> buildHttpServerExceptionHandler(Settings settings, HttpServerTransport transport) {
return Optional.empty();
}

@Override
public Optional<SSLEngine> buildSecureHttpServerEngine(Settings settings, HttpServerTransport transport) throws SSLException {
return Optional.empty();
}
};

try (OpenSearchSecuritySSLPlugin plugin = new OpenSearchSecuritySSLPlugin(settings, null, false)) {
final Map<String, Supplier<HttpServerTransport>> transports = plugin.getSecureHttpTransports(
settings,
MOCK_POOL,
null,
null,
null,
null,
null,
null,
clusterSettings,
secureHttpTransportSettingsProvider,
NoopTracer.INSTANCE
);
assertThat(transports, hasKey("org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport"));

final HttpServerTransport transport = transports.get(
"org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport"
).get();
assertThat(transport, instanceOf(SecureNetty4HttpServerTransport.class));
}
}
}

0 comments on commit afbc10c

Please sign in to comment.