@Test public void should_return_expected_response_when_endpoint_disabled_chunked_request_size_validation() throws Exception { NettyHttpClientRequestBuilder request = request() .withMethod(HttpMethod.POST) .withUri(BasicEndpointWithRequestSizeValidationDisabled.MATCHING_PATH) .withPaylod(generatePayloadOfSizeInBytes(GLOBAL_MAX_REQUEST_SIZE + 100)) .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(BasicEndpointWithRequestSizeValidationDisabled.RESPONSE_PAYLOAD); }
@Test public void should_return_expected_response_when_chunked_request_not_exceeding_endpoint_overridden_request_size() throws Exception { NettyHttpClientRequestBuilder request = request() .withMethod(HttpMethod.POST) .withUri(BasicEndpointWithRequestSizeValidationOverride.MATCHING_PATH) .withPaylod(generatePayloadOfSizeInBytes(BasicEndpointWithRequestSizeValidationOverride.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(BasicEndpointWithRequestSizeValidationOverride.RESPONSE_PAYLOAD); }
@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); }
.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");
@DataProvider(value = { "STANDARD_ENDPOINT", "PROXY_ENDPOINT" }) @Test public void endpoints_should_handle_decode_exception_for_invalid_http_request( EndpointTypeScenario scenario ) throws Exception { // given int payloadSize = CUSTOM_REQUEST_DECODER_CONFIG.maxInitialLineLength() + 1; String payload = generatePayload(payloadSize); //leave off content-length and transfer-encoding headers to trigger DecoderFailedResult NettyHttpClientRequestBuilder request = request() .withMethod(HttpMethod.POST) .withUri(scenario.matchingPathBase) .withPaylod(payload); // 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); }
/** * This test verifies the corner case where the downstream system short circuits and returns a response before * it receives the full request (i.e. the request chunks are still streaming when the response is returned). * This should cause request chunks to fail to stream with an error, but the downstream response should still * be returned to the original caller successfully. */ @Test public void proxy_endpoints_should_successfully_return_short_circuited_downstream_response() throws Exception { // Do this test a bunch of times to try and catch all the race condition possibilities. for (int i = 0; i < 20; i++) { // given int payloadSize = 1024 * 1000; String payload = generatePayload(payloadSize); NettyHttpClientRequestBuilder request = request() .withMethod(HttpMethod.POST) .withUri(RouterEndpointForwardingToShortCircuitError.MATCHING_PATH) .withPaylod(payload) .withHeader(HttpHeaders.Names.CONTENT_LENGTH, payloadSize); // when NettyHttpClientResponse serverResponse = request.execute(proxyServerConfig.endpointsPort(), 3000); // then verifyErrorReceived(serverResponse.payload, serverResponse.statusCode, FAIL_FAST_API_ERROR); } }
@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); }
@Test public void should_return_bad_request_when_chunked_request_exceeds_global_configured_max_request_size() throws Exception { NettyHttpClientRequestBuilder request = request() .withMethod(HttpMethod.POST) .withUri(BasicEndpoint.MATCHING_PATH) .withPaylod(generatePayloadOfSizeInBytes(GLOBAL_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); }