Search in sources :

Example 26 with ExtractableResponse

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

the class VerifyBeforeAndAfterSecurityRequestAndResponseFiltersComponentTest method shouldExecuteBeforeAndAfterRequestAndResponseFilters.

@Test
public void shouldExecuteBeforeAndAfterRequestAndResponseFilters() {
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(BasicEndpoint.MATCHING_PATH).header(FORCE_SECURITY_ERROR_HEADER_KEY, "false").log().all().when().get().then().log().headers().extract();
    // Validate that the security validator was called and that it did not throw an exception.
    assertThat(response.statusCode()).isEqualTo(200);
    assertThat(response.header(SECURITY_VALIDATOR_EXECUTED_HEADER_KEY)).isEqualTo("true");
    assertThat(response.header(SECURITY_VALIDATOR_THREW_ERROR_HEADER_KEY)).isEqualTo("false");
    // Validate request filter methods were called.
    assertThat(response.header(BEFORE_SECURITY_FIRST_CHUNK_FILTER_REQUEST_METHOD_EXECUTED_KEY)).isEqualTo("true");
    assertThat(response.header(BEFORE_SECURITY_LAST_CHUNK_FILTER_REQUEST_METHOD_EXECUTED_KEY)).isEqualTo("true");
    assertThat(response.header(AFTER_SECURITY_FIRST_CHUNK_FILTER_REQUEST_METHOD_EXECUTED_KEY)).isEqualTo("true");
    assertThat(response.header(AFTER_SECURITY_LAST_CHUNK_FILTER_REQUEST_METHOD_EXECUTED_KEY)).isEqualTo("true");
    // Validate response filter method was called.
    assertThat(response.header(BEFORE_SECURITY_RESPONSE_FILTER_METHOD_EXECUTED_KEY)).isEqualTo(BEFORE_SECURITY_RESPONSE_FILTER_METHOD_EXECUTED_PAYLOAD);
    assertThat(response.header(AFTER_SECURITY_RESPONSE_FILTER_METHOD_EXECUTED_KEY)).isEqualTo(AFTER_SECURITY_RESPONSE_FILTER_METHOD_EXECUTED_PAYLOAD);
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 27 with ExtractableResponse

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

the class VerifyPayloadHandlingComponentTest method verify_proxy_router_call_works_for_non_ssl_downstream_system.

@Test
public void verify_proxy_router_call_works_for_non_ssl_downstream_system() throws JsonProcessingException {
    SerializableObject widget = new SerializableObject(UUID.randomUUID().toString(), generateRandomBytes(32));
    String requestPayload = objectMapper.writeValueAsString(widget);
    String payloadHash = getHashForPayload(requestPayload.getBytes(CharsetUtil.UTF_8));
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(DownstreamProxyNonSsl.MATCHING_PATH).header(REQUEST_PAYLOAD_HASH_HEADER_KEY, payloadHash).body(requestPayload).log().all().when().post().then().log().all().statusCode(200).extract();
    String responsePayload = response.asString();
    assertThat(responsePayload).isEqualTo("success_proxy_downstream_endpoint_call_ssl_false");
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 28 with ExtractableResponse

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

the class VerifyPayloadHandlingComponentTest method verify_request_payload_received_for_string_input_type.

@Test
public void verify_request_payload_received_for_string_input_type() {
    String requestPayload = UUID.randomUUID().toString();
    String payloadHash = getHashForPayload(requestPayload.getBytes(CharsetUtil.UTF_8));
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(StringTypeDeserializer.MATCHING_PATH).header(REQUEST_PAYLOAD_HASH_HEADER_KEY, payloadHash).body(requestPayload).log().all().when().post().then().log().all().statusCode(200).extract();
    String responsePayload = response.asString();
    assertThat(responsePayload).isEqualTo("success_string");
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 29 with ExtractableResponse

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

the class VerifyPayloadHandlingComponentTest method verify_proxy_router_call_works_for_ssl_downstream_system.

@Test
public void verify_proxy_router_call_works_for_ssl_downstream_system() throws JsonProcessingException {
    SerializableObject widget = new SerializableObject(UUID.randomUUID().toString(), generateRandomBytes(32));
    String requestPayload = objectMapper.writeValueAsString(widget);
    String payloadHash = getHashForPayload(requestPayload.getBytes(CharsetUtil.UTF_8));
    ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(DownstreamProxySsl.MATCHING_PATH).header(REQUEST_PAYLOAD_HASH_HEADER_KEY, payloadHash).body(requestPayload).log().all().when().post().then().log().all().statusCode(200).extract();
    String responsePayload = response.asString();
    assertThat(responsePayload).isEqualTo("success_proxy_downstream_endpoint_call_ssl_true");
}
Also used : ExtractableResponse(io.restassured.response.ExtractableResponse) Test(org.junit.Test)

Example 30 with ExtractableResponse

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

the class VerifyPayloadHandlingComponentTest method verify_CharSequence_response_payload_is_sent_as_is_with_no_modifications.

@Test
public void verify_CharSequence_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(CharSequencePayloadReturner.MATCHING_PATH).log().all().when().post().then().log().all().statusCode(200).extract();
    String responsePayload = response.asString();
    String expectedHash = response.header(RESPONSE_PAYLOAD_HASH_HEADER_KEY);
    String actualHash = getHashForPayload(responsePayload.getBytes(CharsetUtil.UTF_8));
    assertThat(actualHash).isEqualTo(expectedHash);
}
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