Search in sources :

Example 1 with ExtractableResponse

use of io.restassured.response.ExtractableResponse in project riposte by Nike-Inc.

the class VerifyRequestSizeValidationComponentTest method should_return_expected_response_when_ContentLength_header_not_exceeding_endpoint_overridden_request_size.

@Test
public void should_return_expected_response_when_ContentLength_header_not_exceeding_endpoint_overridden_request_size() {
    ExtractableResponse response = given().baseUri(BASE_URI).port(serverConfig.endpointsPort()).basePath(BasicEndpointWithRequestSizeValidationOverride.MATCHING_PATH).log().all().body(generatePayloadOfSizeInBytes(BasicEndpointWithRequestSizeValidationOverride.MAX_REQUEST_SIZE)).when().post().then().log().headers().extract();
    assertThat(response.statusCode()).isEqualTo(HttpResponseStatus.OK.code());
    assertThat(response.asString()).isEqualTo(BasicEndpointWithRequestSizeValidationOverride.RESPONSE_PAYLOAD);
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 2 with ExtractableResponse

use of io.restassured.response.ExtractableResponse in project riposte by Nike-Inc.

the class VerifyPreEndpointExecutionWorkChainComponentTest method verify_proxy_work_chain_stops_at_security_validator_if_security_validator_blows_up.

@Test
public void verify_proxy_work_chain_stops_at_security_validator_if_security_validator_blows_up() throws IOException, InterruptedException {
    String fooValue = UUID.randomUUID().toString();
    String postData = objectMapper.writeValueAsString(new PostObj(fooValue));
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(WorkChainProxyEndpoint.PROXY_MATCHING_PATH).header(PROXY_ROUTER_DESTINATION_PORT_HEADER_KEY, String.valueOf(downstreamServerConfig.endpointsPort())).header(BLOW_UP_IN_SECURITY_VALIDATOR_HEADER_KEY, "true").body(postData).log().all().when().post().then().log().all().extract();
    Thread.sleep(10);
    verifyErrorReceived(response, SECURITY_VALIDATOR_API_ERROR);
    verifyAsyncWorkerChainExecution(1, 0, 0, false, false);
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 3 with ExtractableResponse

use of io.restassured.response.ExtractableResponse in project riposte by Nike-Inc.

the class VerifyResponseHttpStatusCodeHandlingRfcCorrectnessComponentTest method verify_response_status_code_scenarios.

@Test
@UseDataProvider("responseStatusCodeScenariosDataProvider")
public void verify_response_status_code_scenarios(int desiredStatusCode, boolean shouldReturnEmptyPayload) {
    for (int i = 0; i < 3; i++) {
        // Run this scenario 3 times in quick succession to catch potential keep-alive connection pooling issues.
        logger.info("=== RUN " + i + " ===");
        String callId = UUID.randomUUID().toString();
        ExtractableResponse response = given().config(config().redirect(redirectConfig().followRedirects(false))).baseUri("http://localhost").port(edgeRouterServerConfig.endpointsPort()).basePath(BackendEndpoint.MATCHING_PATH).header(BackendEndpoint.DESIRED_RESPONSE_HTTP_STATUS_CODE_HEADER_KEY, String.valueOf(desiredStatusCode)).header(BackendEndpoint.SHOULD_RETURN_EMPTY_PAYLOAD_BODY_HEADER_KEY, String.valueOf(shouldReturnEmptyPayload)).header(BackendEndpoint.CALL_ID_REQUEST_HEADER_KEY, callId).when().get().then().extract();
        assertThat(response.statusCode()).isEqualTo(desiredStatusCode);
        assertThat(response.header(CALL_ID_RESPONSE_HEADER_KEY)).isEqualTo(callId);
        if (isContentAlwaysEmptyStatusCode(desiredStatusCode)) {
            assertThat(response.asString()).isNullOrEmpty();
            assertThat(response.header(CONTENT_LENGTH)).isEqualTo("0");
            assertThat(response.header(TRANSFER_ENCODING)).isNull();
        } else {
            assertThat(response.header(CONTENT_LENGTH)).isNull();
            assertThat(response.header(TRANSFER_ENCODING)).isEqualTo(CHUNKED);
            if (shouldReturnEmptyPayload)
                assertThat(response.asString()).isNullOrEmpty();
            else
                assertThat(response.asString()).isEqualTo(callId + BackendEndpoint.NON_EMPTY_PAYLOAD);
        }
        logger.info("=== END RUN " + i + " ===");
    }
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) StandardEndpoint(com.nike.riposte.server.http.StandardEndpoint) Endpoint(com.nike.riposte.server.http.Endpoint) SimpleProxyRouterEndpoint(com.nike.riposte.server.http.impl.SimpleProxyRouterEndpoint) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with ExtractableResponse

use of io.restassured.response.ExtractableResponse in project riposte by Nike-Inc.

the class VerifyRequestSizeValidationComponentTest method should_return_bad_request_when_ContentLength_header_exceeds_global_configured_max_request_size.

@Test
public void should_return_bad_request_when_ContentLength_header_exceeds_global_configured_max_request_size() throws IOException {
    ExtractableResponse response = given().baseUri(BASE_URI).port(serverConfig.endpointsPort()).basePath(BasicEndpoint.MATCHING_PATH).log().all().body(generatePayloadOfSizeInBytes(GLOBAL_MAX_REQUEST_SIZE + 1)).when().post().then().log().headers().extract();
    assertThat(response.statusCode()).isEqualTo(HttpResponseStatus.BAD_REQUEST.code());
    assertBadRequestErrorMessageAndMetadata(response.asString());
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 5 with ExtractableResponse

use of io.restassured.response.ExtractableResponse in project riposte by Nike-Inc.

the class VerifyRequestSizeValidationComponentTest method should_return_bad_request_when_ContentLength_header_exceeds_endpoint_overridden_configured_max_request_size.

@Test
public void should_return_bad_request_when_ContentLength_header_exceeds_endpoint_overridden_configured_max_request_size() throws IOException {
    ExtractableResponse response = given().baseUri(BASE_URI).port(serverConfig.endpointsPort()).basePath(BasicEndpointWithRequestSizeValidationOverride.MATCHING_PATH).log().all().body(generatePayloadOfSizeInBytes(BasicEndpointWithRequestSizeValidationOverride.MAX_REQUEST_SIZE + 1)).when().post().then().log().headers().extract();
    assertThat(response.statusCode()).isEqualTo(HttpResponseStatus.BAD_REQUEST.code());
    assertBadRequestErrorMessageAndMetadata(response.asString());
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Aggregations

ExtractableResponse (io.restassured.response.ExtractableResponse)32 Test (org.junit.Test)30 Endpoint (com.nike.riposte.server.http.Endpoint)5 StandardEndpoint (com.nike.riposte.server.http.StandardEndpoint)5 Response (io.restassured.response.Response)4 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)3 ApiError (com.nike.backstopper.apierror.ApiError)1 ApiErrorBase (com.nike.backstopper.apierror.ApiErrorBase)1 SimpleProxyRouterEndpoint (com.nike.riposte.server.http.impl.SimpleProxyRouterEndpoint)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1