public static String generatePayload(int payloadSize) { return generatePayload(payloadSize, payloadDictionary); }
private static String generatePayloadOfSizeInBytes(String prefix, int length) { return prefix + generatePayload(length - prefix.length()); }
public static ByteBuf createByteBufPayload(int payloadSize) { return Unpooled.wrappedBuffer(generatePayload(payloadSize).getBytes(UTF_8)); }
private String generateUriForInitialLineLength(HttpMethod method, String baseUri, int desiredInitialLineLength) { String baseInitialLine = method.name() + " " + baseUri + "/ HTTP/1.1"; int neededWildcardLength = desiredInitialLineLength - baseInitialLine.length(); return baseUri + "/" + generatePayload(neededWildcardLength, "a"); }
private Pair<String, Object> generateHeaderForHeaderLineLength(String headerKey, int desiredHeaderLineLength) { String baseHeaderLine = headerKey + ": "; int neededHeaderValueLength = desiredHeaderLineLength - baseHeaderLine.length(); return Pair.of(headerKey, generatePayload(neededHeaderValueLength, "h")); }
@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); }
String origRequestPayload = generatePayload(payloadSize);
/** * 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); } }