Search in sources :

Example 11 with ExtractableResponse

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

the class VerifyRequestAndResponseFilteringComponentTest method verify_filters_work_for_non_short_circuit_calls_for_endpoints_and_errors.

@DataProvider(value = { "false", "true" }, splitBy = "\\|")
@Test
public void verify_filters_work_for_non_short_circuit_calls_for_endpoints_and_errors(boolean forceError) throws IOException, InterruptedException {
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(BasicEndpoint.MATCHING_PATH).header(BasicEndpoint.FORCE_ERROR_HEADER_KEY, String.valueOf(forceError)).log().all().when().get().then().log().headers().extract();
    // Should have hit the endpoint
    if (forceError)
        verifyErrorReceived(response, BasicEndpoint.FORCED_ERROR);
    else
        assertThat(response.asString()).isEqualTo(BasicEndpoint.RESPONSE_PAYLOAD);
    // All the filter-specific request and response headers should be present.
    assertThat(response.headers().getValues(FIRST_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
    assertThat(response.headers().getValues(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_VALUE));
    assertThat(response.headers().getValues(FIRST_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_RESPONSE_HEADER_VALUE));
    assertThat(response.headers().getValues(SECOND_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
    assertThat(response.headers().getValues(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_VALUE));
    assertThat(response.headers().getValues(SECOND_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_RESPONSE_HEADER_VALUE));
    assertThat(response.headers().getValues(THIRD_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
    assertThat(response.headers().getValues(THIRD_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_VALUE));
    assertThat(response.headers().getValues(THIRD_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_RESPONSE_HEADER_VALUE));
    // The override request and response headers should be correct - last filter wins - so third filter for the request and first filter for the response
    assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_FIRST_CHUNK_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_REQUEST_FIRST_CHUNK_OVERRIDE_HEADER_VALUE));
    assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_VALUE));
    assertThat(response.headers().getValues(COMMON_FILTER_RESPONSE_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_RESPONSE_OVERRIDE_HEADER_KEY));
    // The cumulative request and response headers should be correct (contain all values from all filters)
    assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(FIRST_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE, SECOND_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE, THIRD_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE));
    assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(FIRST_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_VALUE, SECOND_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_VALUE, THIRD_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_VALUE));
    assertThat(response.headers().getValues(COMMON_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(THIRD_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY, SECOND_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY, FIRST_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY));
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 12 with ExtractableResponse

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

the class VerifyRequestAndResponseFilteringComponentTest method verify_filters_work_for_last_chunk_short_circuit_calls.

@DataProvider(value = { "false", "true" }, splitBy = "\\|")
@Test
public void verify_filters_work_for_last_chunk_short_circuit_calls(boolean hit404Path) throws IOException, InterruptedException {
    String basePath = (hit404Path) ? "/foobardoesnotexist" : BasicEndpoint.MATCHING_PATH;
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(basePath).header(SecondFilterShortCircuiting.SHOULD_SHORT_CIRCUIT_LAST_CHUNK, "true").log().all().when().get().then().log().headers().extract();
    //      * Should have thrown a 404 after the first chunk was fully filtered for an invalid 404 path.
    if (hit404Path)
        verifyErrorReceived(response, SampleCoreApiError.NOT_FOUND);
    else
        assertThat(response.asString()).isEqualTo(SecondFilterShortCircuiting.SHORT_CIRCUIT_LAST_CHUNK_RESPONSE_PAYLOAD);
    // Some of the filter-specific request and response headers should be present - the ones added after the short circuit should not be present.
    assertThat(response.headers().getValues(FIRST_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
    if (hit404Path) {
        // 404 prevents last chunk filters from running because the 404 exception is thrown after the first chunk is processed but before the last chunk.
        assertThat(response.headers().getValues(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEmpty();
    } else {
        assertThat(response.headers().getValues(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_VALUE));
    }
    assertThat(response.headers().getValues(FIRST_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_RESPONSE_HEADER_VALUE));
    assertThat(response.headers().getValues(SECOND_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
    if (hit404Path) {
        // 404 prevents last chunk filters from running because the 404 exception is thrown after the first chunk is processed but before the last chunk.
        assertThat(response.headers().getValues(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEmpty();
    } else {
        assertThat(response.headers().getValues(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_VALUE));
    }
    assertThat(response.headers().getValues(SECOND_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_RESPONSE_HEADER_VALUE));
    assertThat(response.headers().getValues(THIRD_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
    assertThat(response.header(THIRD_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isNull();
    assertThat(response.headers().getValues(THIRD_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_RESPONSE_HEADER_VALUE));
    // The override request and response headers should be correct based on when the short circuit occurred
    assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_FIRST_CHUNK_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_REQUEST_FIRST_CHUNK_OVERRIDE_HEADER_VALUE));
    if (hit404Path) {
        // 404 prevents last chunk filters from running because the 404 exception is thrown after the first chunk is processed but before the last chunk.
        assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_KEY)).isEmpty();
    } else {
        assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_VALUE));
    }
    assertThat(response.headers().getValues(COMMON_FILTER_RESPONSE_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_RESPONSE_OVERRIDE_HEADER_KEY));
    // The cumulative request and response headers should be correct based on when the short circuit occurred
    assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(FIRST_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE, SECOND_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE, THIRD_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE));
    if (hit404Path) {
        // 404 prevents last chunk filters from running because the 404 exception is thrown after the first chunk is processed but before the last chunk.
        assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_KEY)).isEmpty();
    } else {
        assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(FIRST_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_VALUE, SECOND_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_VALUE));
    }
    assertThat(response.headers().getValues(COMMON_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(THIRD_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY, SECOND_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY, FIRST_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY));
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 13 with ExtractableResponse

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

the class VerifyRequestAndResponseFilteringComponentTest method verify_filters_work_for_first_chunk_short_circuit_calls.

@DataProvider(value = { "false", "true" }, splitBy = "\\|")
@Test
public void verify_filters_work_for_first_chunk_short_circuit_calls(boolean attempt404Path) throws IOException, InterruptedException {
    String basePath = (attempt404Path) ? "/foobardoesnotexist" : BasicEndpoint.MATCHING_PATH;
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(basePath).header(SecondFilterShortCircuiting.SHOULD_SHORT_CIRCUIT_FIRST_CHUNK, "true").log().all().when().get().then().log().headers().extract();
    // Should *not* have hit the endpoint - should have short circuited on the first chunk, even if we tried to hit a 404 not found path.
    assertThat(response.asString()).isEqualTo(SecondFilterShortCircuiting.SHORT_CIRCUIT_FIRST_CHUNK_RESPONSE_PAYLOAD);
    // Some of the filter-specific request and response headers should be present - the ones added after the short circuit should not be present.
    assertThat(response.headers().getValues(FIRST_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
    assertThat(response.header(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isNull();
    assertThat(response.headers().getValues(FIRST_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_RESPONSE_HEADER_VALUE));
    assertThat(response.headers().getValues(SECOND_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
    assertThat(response.header(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isNull();
    assertThat(response.headers().getValues(SECOND_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_RESPONSE_HEADER_VALUE));
    assertThat(response.header(THIRD_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isNull();
    assertThat(response.header(THIRD_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isNull();
    assertThat(response.headers().getValues(THIRD_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_RESPONSE_HEADER_VALUE));
    // The override request and response headers should be correct based on when the short circuit occurred
    assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_FIRST_CHUNK_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_REQUEST_FIRST_CHUNK_OVERRIDE_HEADER_VALUE));
    assertThat(response.header(COMMON_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_KEY)).isNull();
    assertThat(response.headers().getValues(COMMON_FILTER_RESPONSE_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_RESPONSE_OVERRIDE_HEADER_KEY));
    // The cumulative request and response headers should be correct based on when the short circuit occurred
    assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(FIRST_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE, SECOND_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE));
    assertThat(response.header(COMMON_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_KEY)).isNull();
    assertThat(response.headers().getValues(COMMON_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(THIRD_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY, SECOND_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY, FIRST_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY));
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 14 with ExtractableResponse

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

the class VerifyPayloadHandlingComponentTest method verify_byte_array_response_payload_is_sent_as_is_with_no_modifications.

@Test
public void verify_byte_array_response_payload_is_sent_as_is_with_no_modifications() throws IOException, InterruptedException {
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(ByteArrayPayloadReturner.MATCHING_PATH).log().all().when().post().then().log().headers().statusCode(200).extract();
    byte[] responsePayload = response.asByteArray();
    String expectedHash = response.header(RESPONSE_PAYLOAD_HASH_HEADER_KEY);
    String actualHash = getHashForPayload(responsePayload);
    assertThat(actualHash).isEqualTo(expectedHash);
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 15 with ExtractableResponse

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

the class VerifyPreEndpointExecutionWorkChainComponentTest method verify_work_chain_stops_at_security_validator_if_security_validator_blows_up.

@Test
public void verify_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(WorkChainEndpoint.WORK_CHAIN_MATCHING_PATH).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)

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