use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class AllowAllTheThingsCORSFilterTest method filterRequestFirstChunkWithOptionalShortCircuitResponse_short_circuits_on_CORS_preflight_OPTIONS_request.
@DataProvider(value = { "OPTIONS | true", "GET | false", "POST | false", "PUT | false" }, splitBy = "\\|")
@Test
public void filterRequestFirstChunkWithOptionalShortCircuitResponse_short_circuits_on_CORS_preflight_OPTIONS_request(String httpMethodString, boolean expectShortCircuit) {
// given
HttpMethod method = HttpMethod.valueOf(httpMethodString);
doReturn(method).when(requestMock).getMethod();
// when
Pair<RequestInfo<?>, Optional<ResponseInfo<?>>> result = filter.filterRequestFirstChunkWithOptionalShortCircuitResponse(requestMock, ctxMock);
// then
if (expectShortCircuit) {
assertThat(result).isNotNull();
assertThat(result.getLeft()).isSameAs(requestMock);
assertThat(result.getRight()).isPresent();
assertThat(result.getRight().get().getHttpStatusCode()).isEqualTo(200);
} else
assertThat(result).isNull();
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class RequestAndResponseFilterTest method default_method_implementations_behave_as_expected.
@Test
public void default_method_implementations_behave_as_expected() throws CertificateException, SSLException {
// given
RequestAndResponseFilter defaultImpl = new RequestAndResponseFilter() {
@Override
public <T> RequestInfo<T> filterRequestFirstChunkNoPayload(RequestInfo<T> currentRequestInfo, ChannelHandlerContext ctx) {
return null;
}
@Override
public <T> RequestInfo<T> filterRequestLastChunkWithFullPayload(RequestInfo<T> currentRequestInfo, ChannelHandlerContext ctx) {
return null;
}
@Override
public <T> ResponseInfo<T> filterResponse(ResponseInfo<T> currentResponseInfo, RequestInfo<?> requestInfo, ChannelHandlerContext ctx) {
return null;
}
};
// expect
assertThat(defaultImpl.isShortCircuitRequestFilter()).isFalse();
Throwable firstChunkShortCircuitEx = catchThrowable(() -> defaultImpl.filterRequestFirstChunkWithOptionalShortCircuitResponse(mock(RequestInfo.class), mock(ChannelHandlerContext.class)));
assertThat(firstChunkShortCircuitEx).isNotNull().isInstanceOf(UnsupportedOperationException.class);
Throwable lastChunkShortCircuitEx = catchThrowable(() -> defaultImpl.filterRequestLastChunkWithOptionalShortCircuitResponse(mock(RequestInfo.class), mock(ChannelHandlerContext.class)));
assertThat(lastChunkShortCircuitEx).isNotNull().isInstanceOf(UnsupportedOperationException.class);
assertThat(defaultImpl.shouldExecuteBeforeSecurityValidation()).isTrue();
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class ShortCircuitingRequestAndResponseFilterTest method default_method_implementations_behave_as_expected.
@Test
public void default_method_implementations_behave_as_expected() throws CertificateException, SSLException {
// given
ShortCircuitingRequestAndResponseFilter defaultImpl = new ShortCircuitingRequestAndResponseFilter() {
@Override
public <T> ResponseInfo<T> filterResponse(ResponseInfo<T> currentResponseInfo, RequestInfo<?> requestInfo, ChannelHandlerContext ctx) {
return null;
}
@Override
public <T> Pair<RequestInfo<T>, Optional<ResponseInfo<?>>> filterRequestFirstChunkWithOptionalShortCircuitResponse(RequestInfo<T> currentRequestInfo, ChannelHandlerContext ctx) {
return null;
}
@Override
public <T> Pair<RequestInfo<T>, Optional<ResponseInfo<?>>> filterRequestLastChunkWithOptionalShortCircuitResponse(RequestInfo<T> currentRequestInfo, ChannelHandlerContext ctx) {
return null;
}
};
// expect
assertThat(defaultImpl.isShortCircuitRequestFilter()).isTrue();
Throwable firstChunkEx = catchThrowable(() -> defaultImpl.filterRequestFirstChunkNoPayload(mock(RequestInfo.class), mock(ChannelHandlerContext.class)));
assertThat(firstChunkEx).isNotNull().isInstanceOf(UnsupportedOperationException.class);
Throwable lastChunkEx = catchThrowable(() -> defaultImpl.filterRequestLastChunkWithFullPayload(mock(RequestInfo.class), mock(ChannelHandlerContext.class)));
assertThat(lastChunkEx).isNotNull().isInstanceOf(UnsupportedOperationException.class);
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class RequestInfoImplTest method setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_is_null.
@Test
public void setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_is_null() throws IOException {
// given
RequestInfo<TestContentObject> requestInfo = (RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();
assertThat(requestInfo.getRawContent(), nullValue());
// when
requestInfo.setupContentDeserializer(new ObjectMapper(), new TypeReference<TestContentObject>() {
});
// then
assertThat(requestInfo.getContent(), nullValue());
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class RiposteUnhandledExceptionHandlerTest method handleErrorFromNettyInterfaceWrapsRequestInfoWithAdapterBeforeContinuing.
@Test
public void handleErrorFromNettyInterfaceWrapsRequestInfoWithAdapterBeforeContinuing() {
com.nike.backstopper.handler.ErrorResponseInfo<ErrorResponseBody> backstopperResponse = new ErrorResponseInfo<>(42, mock(ErrorResponseBody.class), Collections.emptyMap());
doReturn(backstopperResponse).when(adapterSpy).handleException(any(Throwable.class), any(RequestInfoForLogging.class));
RequestInfo requestInfoMock = mock(RequestInfo.class);
adapterSpy.handleError(new Exception(), requestInfoMock);
ArgumentCaptor<RequestInfoForLogging> requestInfoForLoggingArgumentCaptor = ArgumentCaptor.forClass(RequestInfoForLogging.class);
verify(adapterSpy).handleException(any(Throwable.class), requestInfoForLoggingArgumentCaptor.capture());
RequestInfoForLogging passedArg = requestInfoForLoggingArgumentCaptor.getValue();
assertThat(passedArg, instanceOf(RequestInfoForLoggingRiposteAdapter.class));
RequestInfo embeddedRequestInfoInWrapper = (RequestInfo) Whitebox.getInternalState(passedArg, "request");
assertThat(embeddedRequestInfoInWrapper, sameInstance(requestInfoMock));
}
Aggregations