Search in sources :

Example 16 with NettyHttpClientRequestBuilder

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);
}
Also used : NettyHttpClientResponse(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientResponse) NettyHttpClientRequestBuilder(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder) Test(org.junit.Test)

Example 17 with NettyHttpClientRequestBuilder

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);
}
Also used : NettyHttpClientResponse(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientResponse) NettyHttpClientRequestBuilder(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder) Test(org.junit.Test)

Example 18 with NettyHttpClientRequestBuilder

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);
}
Also used : NettyHttpClientResponse(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientResponse) ProxyRouterEndpoint(com.nike.riposte.server.http.ProxyRouterEndpoint) Endpoint(com.nike.riposte.server.http.Endpoint) StandardEndpoint(com.nike.riposte.server.http.StandardEndpoint) NettyHttpClientRequestBuilder(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 19 with NettyHttpClientRequestBuilder

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);
}
Also used : NettyHttpClientResponse(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientResponse) NettyHttpClientRequestBuilder(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 20 with NettyHttpClientRequestBuilder

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);
}
Also used : NettyHttpClientResponse(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientResponse) NettyHttpClientRequestBuilder(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

NettyHttpClientRequestBuilder (com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder)22 NettyHttpClientResponse (com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientResponse)22 Test (org.junit.Test)22 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)10 Endpoint (com.nike.riposte.server.http.Endpoint)5 ProxyRouterEndpoint (com.nike.riposte.server.http.ProxyRouterEndpoint)5 StandardEndpoint (com.nike.riposte.server.http.StandardEndpoint)5 ApiErrorWithMetadata (com.nike.backstopper.apierror.ApiErrorWithMetadata)3 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)2 ChannelPromise (io.netty.channel.ChannelPromise)2 SimpleProxyRouterEndpoint (com.nike.riposte.server.http.impl.SimpleProxyRouterEndpoint)1 ComponentTestUtils.createNettyHttpClientBootstrap (com.nike.riposte.server.testutils.ComponentTestUtils.createNettyHttpClientBootstrap)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 Channel (io.netty.channel.Channel)1 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)1 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)1