Search in sources :

Example 21 with NettyHttpClientRequestBuilder

use of com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder in project riposte by Nike-Inc.

the class VerifyDecoderFailedResultIsHandledTest method endpoints_should_be_reachable_with_barely_valid_initial_line_length_values.

@DataProvider(value = { "STANDARD_ENDPOINT", "PROXY_ENDPOINT" })
@Test
public void endpoints_should_be_reachable_with_barely_valid_initial_line_length_values(EndpointTypeScenario scenario) throws Exception {
    // given
    String barelyAcceptableUri = generateUriForInitialLineLength(HttpMethod.GET, scenario.matchingPathBase, CUSTOM_REQUEST_DECODER_CONFIG.maxInitialLineLength());
    Pair<String, Object> barelyAcceptableHeader = generateHeaderForHeaderLineLength(CUSTOM_REQUEST_DECODER_CONFIG.maxHeaderSize());
    NettyHttpClientRequestBuilder request = request().withMethod(HttpMethod.GET).withUri(barelyAcceptableUri).withHeaders(barelyAcceptableHeader);
    // when
    NettyHttpClientResponse serverResponse = request.execute(scenario.serverPort, incompleteCallTimeoutMillis);
    // then
    assertThat(serverResponse.statusCode).isEqualTo(200);
    assertThat(serverResponse.payload).isEqualTo(scenario.successfulResponsePayload);
}
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 22 with NettyHttpClientRequestBuilder

use of com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder in project riposte by Nike-Inc.

the class VerifyCornerCasesComponentTest method invalid_http_call_with_invalid_URL_escaping_should_result_in_expected_400_error.

@Test
public void invalid_http_call_with_invalid_URL_escaping_should_result_in_expected_400_error() throws Exception {
    // given
    // Incorrectly escaped URLs cause a blowup in RequestInfoImpl when it tries to decode the URL. We can trigger
    // this by putting a % character that is not followed by a proper escape sequence.
    NettyHttpClientRequestBuilder request = request().withMethod(HttpMethod.GET).withUri("%notAnEscapeSequence");
    // when
    NettyHttpClientResponse response = request.execute(downstreamServerConfig.endpointsPort(), 3000);
    // then
    verifyErrorReceived(response.payload, response.statusCode, new ApiErrorWithMetadata(SampleCoreApiError.MALFORMED_REQUEST, Pair.of("cause", "Invalid HTTP request")));
}
Also used : ApiErrorWithMetadata(com.nike.backstopper.apierror.ApiErrorWithMetadata) NettyHttpClientResponse(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientResponse) NettyHttpClientRequestBuilder(com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder) 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