13
13
import java .util .List ;
14
14
import java .util .Map ;
15
15
import java .util .Optional ;
16
+ import java .util .concurrent .atomic .AtomicBoolean ;
16
17
import java .util .function .Supplier ;
17
18
import javax .net .ssl .SSLEngine ;
18
19
import javax .net .ssl .SSLException ;
26
27
import org .opensearch .common .settings .ClusterSettings ;
27
28
import org .opensearch .common .settings .Settings ;
28
29
import org .opensearch .http .HttpServerTransport ;
30
+ import org .opensearch .http .netty4 .ssl .SecureNetty4HttpServerTransport ;
29
31
import org .opensearch .plugins .SecureHttpTransportSettingsProvider ;
30
32
import org .opensearch .plugins .SecureTransportSettingsProvider ;
31
33
import org .opensearch .plugins .TransportExceptionHandler ;
35
37
import org .opensearch .security .test .helper .file .FileHelper ;
36
38
import org .opensearch .telemetry .tracing .noop .NoopTracer ;
37
39
import org .opensearch .transport .Transport ;
40
+ import org .opensearch .transport .TransportAdapterProvider ;
41
+
42
+ import io .netty .channel .ChannelInboundHandlerAdapter ;
38
43
39
44
import static org .hamcrest .CoreMatchers .containsString ;
45
+ import static org .hamcrest .CoreMatchers .is ;
40
46
import static org .hamcrest .CoreMatchers .not ;
41
47
import static org .hamcrest .CoreMatchers .nullValue ;
42
48
import static org .hamcrest .MatcherAssert .assertThat ;
@@ -125,6 +131,10 @@ public void testRegisterSecureHttpTransport() throws IOException {
125
131
NoopTracer .INSTANCE
126
132
);
127
133
assertThat (transports , hasKey ("org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport" ));
134
+ assertThat (
135
+ transports .get ("org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport" ).get (),
136
+ not (nullValue ())
137
+ );
128
138
}
129
139
}
130
140
@@ -142,6 +152,7 @@ public void testRegisterSecureTransport() throws IOException {
142
152
NoopTracer .INSTANCE
143
153
);
144
154
assertThat (transports , hasKey ("org.opensearch.security.ssl.http.netty.SecuritySSLNettyTransport" ));
155
+ assertThat (transports .get ("org.opensearch.security.ssl.http.netty.SecuritySSLNettyTransport" ).get (), not (nullValue ()));
145
156
}
146
157
}
147
158
@@ -247,4 +258,69 @@ public void testRegisterSecureTransportWithDuplicateSettings() throws IOExceptio
247
258
}
248
259
}
249
260
}
261
+
262
+ @ Test
263
+ public void testRegisterSecureHttpTransportWithRequestHeaderVerifier () throws IOException {
264
+ final AtomicBoolean created = new AtomicBoolean (false );
265
+
266
+ class LocalHeaderVerifier extends ChannelInboundHandlerAdapter {
267
+ public LocalHeaderVerifier () {
268
+ created .set (true );
269
+ }
270
+ }
271
+
272
+ final SecureHttpTransportSettingsProvider provider = new SecureHttpTransportSettingsProvider () {
273
+ @ Override
274
+ public Collection <TransportAdapterProvider <HttpServerTransport >> getHttpTransportAdapterProviders (Settings settings ) {
275
+ return List .of (new TransportAdapterProvider <HttpServerTransport >() {
276
+
277
+ @ Override
278
+ public String name () {
279
+ return SecureNetty4HttpServerTransport .REQUEST_HEADER_VERIFIER ;
280
+ }
281
+
282
+ @ SuppressWarnings ("unchecked" )
283
+ @ Override
284
+ public <C > Optional <C > create (Settings settings , HttpServerTransport transport , Class <C > adapterClass ) {
285
+ return Optional .of ((C ) new LocalHeaderVerifier ());
286
+ }
287
+
288
+ });
289
+ }
290
+
291
+ @ Override
292
+ public Optional <TransportExceptionHandler > buildHttpServerExceptionHandler (Settings settings , HttpServerTransport transport ) {
293
+ return Optional .empty ();
294
+ }
295
+
296
+ @ Override
297
+ public Optional <SSLEngine > buildSecureHttpServerEngine (Settings settings , HttpServerTransport transport ) throws SSLException {
298
+ return Optional .empty ();
299
+ }
300
+ };
301
+
302
+ try (OpenSearchSecuritySSLPlugin plugin = new OpenSearchSecuritySSLPlugin (settings , null , false )) {
303
+ final Map <String , Supplier <HttpServerTransport >> transports = plugin .getSecureHttpTransports (
304
+ settings ,
305
+ MOCK_POOL ,
306
+ null ,
307
+ null ,
308
+ null ,
309
+ null ,
310
+ null ,
311
+ null ,
312
+ clusterSettings ,
313
+ provider ,
314
+ NoopTracer .INSTANCE
315
+ );
316
+ assertThat (transports , hasKey ("org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport" ));
317
+
318
+ assertThat (
319
+ transports .get ("org.opensearch.security.ssl.http.netty.SecuritySSLNettyHttpServerTransport" ).get (),
320
+ not (nullValue ())
321
+ );
322
+
323
+ assertThat (created .get (), is (true ));
324
+ }
325
+ }
250
326
}
0 commit comments