use of com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder in project riposte by Nike-Inc.
the class VerifyRequestSizeValidationComponentTest method should_return_bad_request_when_chunked_request_exceeds_endpoint_overridden_configured_max_request_size.
@Test
public void should_return_bad_request_when_chunked_request_exceeds_endpoint_overridden_configured_max_request_size() throws Exception {
NettyHttpClientRequestBuilder request = request().withMethod(HttpMethod.POST).withUri(BasicEndpointWithRequestSizeValidationOverride.MATCHING_PATH).withPaylod(generatePayloadOfSizeInBytes(BasicEndpointWithRequestSizeValidationOverride.MAX_REQUEST_SIZE + 1)).withHeader(HttpHeaders.Names.TRANSFER_ENCODING, CHUNKED);
// when
NettyHttpClientResponse serverResponse = request.execute(serverConfig.endpointsPort(), incompleteCallTimeoutMillis);
// then
assertThat(serverResponse.statusCode).isEqualTo(HttpResponseStatus.BAD_REQUEST.code());
assertBadRequestErrorMessageAndMetadata(serverResponse.payload);
}
use of com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder in project riposte by Nike-Inc.
the class VerifyRequestSizeValidationComponentTest method should_return_expected_response_when_chunked_request_not_exceeding_global_request_size.
@Test
public void should_return_expected_response_when_chunked_request_not_exceeding_global_request_size() throws Exception {
NettyHttpClientRequestBuilder request = request().withMethod(HttpMethod.POST).withUri(BasicEndpoint.MATCHING_PATH).withPaylod(generatePayloadOfSizeInBytes(GLOBAL_MAX_REQUEST_SIZE)).withHeader(HttpHeaders.Names.TRANSFER_ENCODING, CHUNKED);
// when
NettyHttpClientResponse serverResponse = request.execute(serverConfig.endpointsPort(), incompleteCallTimeoutMillis);
// then
assertThat(serverResponse.statusCode).isEqualTo(HttpResponseStatus.OK.code());
assertThat(serverResponse.payload).isEqualTo(BasicEndpoint.RESPONSE_PAYLOAD);
}
use of com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder in project riposte by Nike-Inc.
the class VerifyProxyEndpointsDoNotAlterRequestOrResponseByDefaultComponentTest method proxy_endpoints_should_honor_transfer_encoding_and_not_alter_request_or_response.
@DataProvider(value = { "CHUNKED_REQUEST_CHUNKED_RESPONSE", "CHUNKED_REQUEST_NORMAL_RESPONSE", "NORMAL_REQUEST_CHUNKED_RESPONSE", "NORMAL_REQUEST_NORMAL_RESPONSE" })
@Test
public void proxy_endpoints_should_honor_transfer_encoding_and_not_alter_request_or_response(CallScenario scenario) throws Exception {
// given
int payloadSize = 10000;
String origRequestPayload = generatePayload(payloadSize);
NettyHttpClientRequestBuilder request = request().withMethod(HttpMethod.POST).withUri(RouterEndpoint.MATCHING_PATH).withPaylod(origRequestPayload).withHeader(SOME_EXPECTED_REQUEST_HEADER.getKey(), SOME_EXPECTED_REQUEST_HEADER.getValue()).withHeader(HttpHeaders.Names.HOST, "localhost");
if (scenario.isChunkedRequest) {
request = request.withHeader(TRANSFER_ENCODING, CHUNKED);
} else {
request = request.withHeader(CONTENT_LENGTH, origRequestPayload.length());
}
if (scenario.isChunkedResponse) {
request.withHeader(DownstreamEndpoint.RESPONSE_SHOULD_BE_CHUNKED_REQUEST_HEADER_KEY, "true");
}
// when
NettyHttpClientResponse serverResponse = request.execute(proxyServerConfig.endpointsPort(), incompleteCallTimeoutMillis);
// then
// Sanity check the response from the caller's perspective.
assertThat(serverResponse.statusCode).isEqualTo(HttpResponseStatus.OK.code());
assertThat(serverResponse.payload).isEqualTo(DownstreamEndpoint.RESPONSE_PAYLOAD);
// Verify all the requests through the proxy to the downstream.
verifyRawRequestStuff(scenario, origRequestPayload);
// Verify all the responses from the downstream through the proxy.
verifyRawResponseStuff(scenario, DownstreamEndpoint.RESPONSE_PAYLOAD);
}
use of com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder in project riposte by Nike-Inc.
the class VerifyDecoderFailedResultIsHandledTest method endpoints_should_throw_decode_exception_for_initial_line_length_that_is_too_long.
@DataProvider(value = { "STANDARD_ENDPOINT", "PROXY_ENDPOINT" })
@Test
public void endpoints_should_throw_decode_exception_for_initial_line_length_that_is_too_long(EndpointTypeScenario scenario) throws Exception {
// given
String tooLongUri = generateUriForInitialLineLength(HttpMethod.GET, scenario.matchingPathBase, CUSTOM_REQUEST_DECODER_CONFIG.maxInitialLineLength() + 1);
NettyHttpClientRequestBuilder request = request().withMethod(HttpMethod.GET).withUri(tooLongUri);
// when
NettyHttpClientResponse serverResponse = request.execute(scenario.serverPort, incompleteCallTimeoutMillis);
// then
assertTooLongFrameErrorResponse(serverResponse, EXPECTED_TOO_LONG_FRAME_LINE_API_ERROR);
// The EXPECTED_TOO_LONG_FRAME_LINE_API_ERROR check above should have verified 400 status code, but do a
// sanity check here just for test readability.
assertThat(serverResponse.statusCode).isEqualTo(400);
}
use of com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder in project riposte by Nike-Inc.
the class VerifyDecoderFailedResultIsHandledTest method endpoints_should_throw_decode_exception_for_single_header_that_is_too_long.
@DataProvider(value = { "STANDARD_ENDPOINT", "PROXY_ENDPOINT" })
@Test
public void endpoints_should_throw_decode_exception_for_single_header_that_is_too_long(EndpointTypeScenario scenario) throws Exception {
// given
Pair<String, Object> tooLongHeader = generateHeaderForHeaderLineLength(CUSTOM_REQUEST_DECODER_CONFIG.maxHeaderSize() + 1);
NettyHttpClientRequestBuilder request = request().withMethod(HttpMethod.GET).withUri(scenario.matchingPathBase).withHeaders(tooLongHeader);
// when
NettyHttpClientResponse serverResponse = request.execute(scenario.serverPort, incompleteCallTimeoutMillis);
// then
assertTooLongFrameErrorResponse(serverResponse, EXPECTED_TOO_LONG_FRAME_HEADER_API_ERROR);
// The EXPECTED_TOO_LONG_FRAME_HEADER_API_ERROR check above should have verified 431 status code, but do a
// sanity check here just for test readability.
assertThat(serverResponse.statusCode).isEqualTo(431);
}
Aggregations