Skip to content

Commit afbc10c

Browse files
committed
Address code review comments, added more tests
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
1 parent e450fc0 commit afbc10c

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/test/java/org/opensearch/security/ssl/OpenSearchSecuritySSLPluginTest.java

+68
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.opensearch.common.settings.ClusterSettings;
2727
import org.opensearch.common.settings.Settings;
2828
import org.opensearch.http.HttpServerTransport;
29+
import org.opensearch.http.netty4.ssl.SecureNetty4HttpServerTransport;
2930
import org.opensearch.plugins.SecureHttpTransportSettingsProvider;
3031
import org.opensearch.plugins.SecureTransportSettingsProvider;
3132
import org.opensearch.plugins.TransportExceptionHandler;
@@ -35,8 +36,12 @@
3536
import org.opensearch.security.test.helper.file.FileHelper;
3637
import org.opensearch.telemetry.tracing.noop.NoopTracer;
3738
import org.opensearch.transport.Transport;
39+
import org.opensearch.transport.TransportAdapterProvider;
40+
41+
import io.netty.channel.ChannelInboundHandlerAdapter;
3842

3943
import static org.hamcrest.CoreMatchers.containsString;
44+
import static org.hamcrest.CoreMatchers.instanceOf;
4045
import static org.hamcrest.CoreMatchers.not;
4146
import static org.hamcrest.CoreMatchers.nullValue;
4247
import static org.hamcrest.MatcherAssert.assertThat;
@@ -125,6 +130,10 @@ public void testRegisterSecureHttpTransport() throws IOException {
125130
NoopTracer.INSTANCE
126131
);
127132
assertThat(transports, hasKey("org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport"));
133+
assertThat(
134+
transports.get("org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport").get(),
135+
not(nullValue())
136+
);
128137
}
129138
}
130139

@@ -142,6 +151,7 @@ public void testRegisterSecureTransport() throws IOException {
142151
NoopTracer.INSTANCE
143152
);
144153
assertThat(transports, hasKey("org.opensearch.security.ssl.http.netty.SecuritySSLNettyTransport"));
154+
assertThat(transports.get("org.opensearch.security.ssl.http.netty.SecuritySSLNettyTransport").get(), not(nullValue()));
145155
}
146156
}
147157

@@ -247,4 +257,62 @@ public void testRegisterSecureTransportWithDuplicateSettings() throws IOExceptio
247257
}
248258
}
249259
}
260+
261+
@Test
262+
public void testRegisterSecureHttpTransportWithRequestHeaderVerifier() throws IOException {
263+
class LocalHeaderVerifier extends ChannelInboundHandlerAdapter {}
264+
265+
final SecureHttpTransportSettingsProvider provider = new SecureHttpTransportSettingsProvider() {
266+
@Override
267+
public Collection<TransportAdapterProvider<HttpServerTransport>> getHttpTransportAdapterProviders(Settings settings) {
268+
return List.of(new TransportAdapterProvider<HttpServerTransport>() {
269+
270+
@Override
271+
public String name() {
272+
// TODO Auto-generated method stub
273+
return SecureNetty4HttpServerTransport.REQUEST_HEADER_VERIFIER;
274+
}
275+
276+
@SuppressWarnings("unchecked")
277+
@Override
278+
public <C> Optional<C> create(Settings settings, HttpServerTransport transport, Class<C> adapterClass) {
279+
return Optional.of((C) new LocalHeaderVerifier());
280+
}
281+
282+
});
283+
}
284+
285+
@Override
286+
public Optional<TransportExceptionHandler> buildHttpServerExceptionHandler(Settings settings, HttpServerTransport transport) {
287+
return Optional.empty();
288+
}
289+
290+
@Override
291+
public Optional<SSLEngine> buildSecureHttpServerEngine(Settings settings, HttpServerTransport transport) throws SSLException {
292+
return Optional.empty();
293+
}
294+
};
295+
296+
try (OpenSearchSecuritySSLPlugin plugin = new OpenSearchSecuritySSLPlugin(settings, null, false)) {
297+
final Map<String, Supplier<HttpServerTransport>> transports = plugin.getSecureHttpTransports(
298+
settings,
299+
MOCK_POOL,
300+
null,
301+
null,
302+
null,
303+
null,
304+
null,
305+
null,
306+
clusterSettings,
307+
secureHttpTransportSettingsProvider,
308+
NoopTracer.INSTANCE
309+
);
310+
assertThat(transports, hasKey("org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport"));
311+
312+
final HttpServerTransport transport = transports.get(
313+
"org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport"
314+
).get();
315+
assertThat(transport, instanceOf(SecureNetty4HttpServerTransport.class));
316+
}
317+
}
250318
}

0 commit comments

Comments
 (0)