use of com.nike.riposte.server.config.ServerConfig.HttpRequestDecoderConfig in project riposte by Nike-Inc.
the class HttpChannelInitializerTest method initChannel_adds_HttpRequestDecoder_with_config_values_coming_from_httpRequestDecoderConfig.
@Test
public void initChannel_adds_HttpRequestDecoder_with_config_values_coming_from_httpRequestDecoderConfig() {
// given
HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();
HttpRequestDecoderConfig configWithCustomValues = new HttpRequestDecoderConfig() {
@Override
public int maxInitialLineLength() {
return 123;
}
@Override
public int maxHeaderSize() {
return 456;
}
@Override
public int maxChunkSize() {
return 789;
}
};
Whitebox.setInternalState(hci, "httpRequestDecoderConfig", configWithCustomValues);
// when
hci.initChannel(socketChannelMock);
// then
ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
Pair<Integer, HttpRequestDecoder> requestDecoderHandlerPair = findChannelHandler(handlers, HttpRequestDecoder.class);
Assertions.assertThat(requestDecoderHandlerPair).isNotNull();
HttpRequestDecoder decoderHandler = requestDecoderHandlerPair.getValue();
int actualMaxInitialLineLength = extractField(extractField(decoderHandler, "lineParser"), "maxLength");
int actualMaxHeaderSize = extractField(extractField(decoderHandler, "headerParser"), "maxLength");
int actualMaxChunkSize = extractField(decoderHandler, "maxChunkSize");
Assertions.assertThat(actualMaxInitialLineLength).isEqualTo(configWithCustomValues.maxInitialLineLength());
Assertions.assertThat(actualMaxHeaderSize).isEqualTo(configWithCustomValues.maxHeaderSize());
Assertions.assertThat(actualMaxChunkSize).isEqualTo(configWithCustomValues.maxChunkSize());
}
use of com.nike.riposte.server.config.ServerConfig.HttpRequestDecoderConfig in project riposte by Nike-Inc.
the class HttpChannelInitializerTest method constructor_works_with_valid_args.
@Test
public void constructor_works_with_valid_args() {
// given
SslContext sslCtx = mock(SslContext.class);
int maxRequestSizeInBytes = 42;
Collection<Endpoint<?>> endpoints = Arrays.asList(getMockEndpoint("/some/path", HttpMethod.GET));
RequestAndResponseFilter beforeSecurityRequestFilter = mock(RequestAndResponseFilter.class);
doReturn(true).when(beforeSecurityRequestFilter).shouldExecuteBeforeSecurityValidation();
RequestAndResponseFilter afterSecurityRequestFilter = mock(RequestAndResponseFilter.class);
doReturn(false).when(afterSecurityRequestFilter).shouldExecuteBeforeSecurityValidation();
List<RequestAndResponseFilter> reqResFilters = Arrays.asList(beforeSecurityRequestFilter, afterSecurityRequestFilter);
Executor longRunningTaskExecutor = mock(Executor.class);
RiposteErrorHandler riposteErrorHandler = mock(RiposteErrorHandler.class);
RiposteUnhandledErrorHandler riposteUnhandledErrorHandler = mock(RiposteUnhandledErrorHandler.class);
RequestValidator validationService = mock(RequestValidator.class);
ObjectMapper requestContentDeserializer = mock(ObjectMapper.class);
ResponseSender responseSender = mock(ResponseSender.class);
@SuppressWarnings("unchecked") MetricsListener metricsListener = mock(MetricsListener.class);
long defaultCompletableFutureTimeoutMillis = 4242L;
AccessLogger accessLogger = mock(AccessLogger.class);
List<PipelineCreateHook> pipelineCreateHooks = mock(List.class);
RequestSecurityValidator requestSecurityValidator = mock(RequestSecurityValidator.class);
long workerChannelIdleTimeoutMillis = 121000;
long proxyRouterConnectTimeoutMillis = 4200;
long incompleteHttpCallTimeoutMillis = 1234;
int maxOpenChannelsThreshold = 1000;
boolean debugChannelLifecycleLoggingEnabled = true;
List<String> userIdHeaderKeys = mock(List.class);
int responseCompressionThresholdBytes = 5678;
HttpRequestDecoderConfig httpRequestDecoderConfig = new HttpRequestDecoderConfig() {
};
DistributedTracingConfig<Span> distributedTracingConfig = mock(DistributedTracingConfig.class);
ProxyRouterSpanNamingAndTaggingStrategy<Span> proxySpanTaggingStrategyMock = mock(ProxyRouterSpanNamingAndTaggingStrategy.class);
doReturn(proxySpanTaggingStrategyMock).when(distributedTracingConfig).getProxyRouterSpanNamingAndTaggingStrategy();
// when
HttpChannelInitializer hci = new HttpChannelInitializer(sslCtx, maxRequestSizeInBytes, endpoints, reqResFilters, longRunningTaskExecutor, riposteErrorHandler, riposteUnhandledErrorHandler, validationService, requestContentDeserializer, responseSender, metricsListener, defaultCompletableFutureTimeoutMillis, accessLogger, pipelineCreateHooks, requestSecurityValidator, workerChannelIdleTimeoutMillis, proxyRouterConnectTimeoutMillis, incompleteHttpCallTimeoutMillis, maxOpenChannelsThreshold, debugChannelLifecycleLoggingEnabled, userIdHeaderKeys, responseCompressionThresholdBytes, httpRequestDecoderConfig, distributedTracingConfig);
// then
assertThat(extractField(hci, "sslCtx"), is(sslCtx));
assertThat(extractField(hci, "maxRequestSizeInBytes"), is(maxRequestSizeInBytes));
assertThat(extractField(hci, "endpoints"), is(endpoints));
assertThat(extractField(hci, "longRunningTaskExecutor"), is(longRunningTaskExecutor));
assertThat(extractField(hci, "riposteErrorHandler"), is(riposteErrorHandler));
assertThat(extractField(hci, "riposteUnhandledErrorHandler"), is(riposteUnhandledErrorHandler));
assertThat(extractField(hci, "validationService"), is(validationService));
assertThat(extractField(hci, "requestContentDeserializer"), is(requestContentDeserializer));
assertThat(extractField(hci, "responseSender"), is(responseSender));
assertThat(extractField(hci, "metricsListener"), is(metricsListener));
assertThat(extractField(hci, "defaultCompletableFutureTimeoutMillis"), is(defaultCompletableFutureTimeoutMillis));
assertThat(extractField(hci, "accessLogger"), is(accessLogger));
assertThat(extractField(hci, "pipelineCreateHooks"), is(pipelineCreateHooks));
assertThat(extractField(hci, "requestSecurityValidator"), is(requestSecurityValidator));
assertThat(extractField(hci, "workerChannelIdleTimeoutMillis"), is(workerChannelIdleTimeoutMillis));
assertThat(extractField(hci, "incompleteHttpCallTimeoutMillis"), is(incompleteHttpCallTimeoutMillis));
assertThat(extractField(hci, "maxOpenChannelsThreshold"), is(maxOpenChannelsThreshold));
assertThat(extractField(hci, "debugChannelLifecycleLoggingEnabled"), is(debugChannelLifecycleLoggingEnabled));
assertThat(extractField(hci, "userIdHeaderKeys"), is(userIdHeaderKeys));
assertThat(extractField(hci, "responseCompressionThresholdBytes"), is(responseCompressionThresholdBytes));
assertThat(extractField(hci, "httpRequestDecoderConfig"), is(httpRequestDecoderConfig));
assertThat(extractField(hci, "distributedTracingConfig"), is(distributedTracingConfig));
StreamingAsyncHttpClient sahc = extractField(hci, "streamingAsyncHttpClientForProxyRouterEndpoints");
assertThat(extractField(sahc, "idleChannelTimeoutMillis"), is(workerChannelIdleTimeoutMillis));
assertThat(extractField(sahc, "downstreamConnectionTimeoutMillis"), is((int) proxyRouterConnectTimeoutMillis));
assertThat(extractField(sahc, "debugChannelLifecycleLoggingEnabled"), is(debugChannelLifecycleLoggingEnabled));
assertThat(extractField(sahc, "proxySpanTaggingStrategy"), is(proxySpanTaggingStrategyMock));
RequestFilterHandler beforeSecReqFH = extractField(hci, "beforeSecurityRequestFilterHandler");
assertThat(extractField(beforeSecReqFH, "filters"), is(Collections.singletonList(beforeSecurityRequestFilter)));
RequestFilterHandler afterSecReqFH = extractField(hci, "afterSecurityRequestFilterHandler");
assertThat(extractField(afterSecReqFH, "filters"), is(Collections.singletonList(afterSecurityRequestFilter)));
ResponseFilterHandler resFH = extractField(hci, "cachedResponseFilterHandler");
List<RequestAndResponseFilter> reversedFilters = new ArrayList<>(reqResFilters);
Collections.reverse(reversedFilters);
assertThat(extractField(resFH, "filtersInResponseProcessingOrder"), is(reversedFilters));
}
use of com.nike.riposte.server.config.ServerConfig.HttpRequestDecoderConfig in project riposte by Nike-Inc.
the class HttpChannelInitializerTest method initChannel_adds_HttpServerCodec_with_config_values_coming_from_httpRequestDecoderConfig.
@Test
public void initChannel_adds_HttpServerCodec_with_config_values_coming_from_httpRequestDecoderConfig() {
// given
HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();
HttpRequestDecoderConfig configWithCustomValues = new HttpRequestDecoderConfig() {
@Override
public int maxInitialLineLength() {
return 123;
}
@Override
public int maxHeaderSize() {
return 456;
}
@Override
public int maxChunkSize() {
return 789;
}
};
Whitebox.setInternalState(hci, "httpRequestDecoderConfig", configWithCustomValues);
// when
hci.initChannel(socketChannelMock);
// then
ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
Pair<Integer, HttpServerCodec> httpServerCodecHandlerPair = findChannelHandler(handlers, HttpServerCodec.class);
Assertions.assertThat(httpServerCodecHandlerPair).isNotNull();
HttpServerCodec httpServerCodecHandler = httpServerCodecHandlerPair.getValue();
HttpRequestDecoder decoderHandler = (HttpRequestDecoder) Whitebox.getInternalState(httpServerCodecHandler, "inboundHandler");
int actualMaxInitialLineLength = extractField(extractField(decoderHandler, "lineParser"), "maxLength");
int actualMaxHeaderSize = extractField(extractField(decoderHandler, "headerParser"), "maxLength");
int actualMaxChunkSize = extractField(decoderHandler, "maxChunkSize");
Assertions.assertThat(actualMaxInitialLineLength).isEqualTo(configWithCustomValues.maxInitialLineLength());
Assertions.assertThat(actualMaxHeaderSize).isEqualTo(configWithCustomValues.maxHeaderSize());
Assertions.assertThat(actualMaxChunkSize).isEqualTo(configWithCustomValues.maxChunkSize());
}
Aggregations