Search in sources :

Example 46 with Response

use of org.elasticsearch.client.Response in project elasticsearch by elastic.

the class CorsNotSetIT method testCorsSettingDefaultBehaviourDoesNotReturnAnything.

public void testCorsSettingDefaultBehaviourDoesNotReturnAnything() throws IOException {
    String corsValue = "http://localhost:9200";
    Response response = getRestClient().performRequest("GET", "/", new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue));
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
    assertThat(response.getHeader("Access-Control-Allow-Credentials"), nullValue());
}
Also used : Response(org.elasticsearch.client.Response) BasicHeader(org.apache.http.message.BasicHeader)

Example 47 with Response

use of org.elasticsearch.client.Response in project elasticsearch by elastic.

the class CorsRegexIT method testThatPreFlightRequestReturnsNullOnNonMatch.

public void testThatPreFlightRequestReturnsNullOnNonMatch() throws IOException {
    try {
        getRestClient().performRequest("OPTIONS", "/", new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", "http://evil-host:9200"), new BasicHeader("Access-Control-Request-Method", "GET"));
        fail("request should have failed");
    } catch (ResponseException e) {
        Response response = e.getResponse();
        // a rejected origin gets a FORBIDDEN - 403
        assertThat(response.getStatusLine().getStatusCode(), is(403));
        assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
        assertThat(response.getHeader("Access-Control-Allow-Methods"), nullValue());
    }
}
Also used : Response(org.elasticsearch.client.Response) ResponseException(org.elasticsearch.client.ResponseException) BasicHeader(org.apache.http.message.BasicHeader)

Example 48 with Response

use of org.elasticsearch.client.Response in project elasticsearch by elastic.

the class CorsRegexIT method testThatRegularExpressionIsNotAppliedWithoutCorrectBrowserOnMatch.

public void testThatRegularExpressionIsNotAppliedWithoutCorrectBrowserOnMatch() throws IOException {
    Response response = getRestClient().performRequest("GET", "/");
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
}
Also used : Response(org.elasticsearch.client.Response)

Example 49 with Response

use of org.elasticsearch.client.Response in project elasticsearch by elastic.

the class CorsRegexIT method testThatRegularExpressionWorksOnMatch.

public void testThatRegularExpressionWorksOnMatch() throws IOException {
    String corsValue = "http://localhost:9200";
    Response response = getRestClient().performRequest("GET", "/", new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue));
    assertResponseWithOriginheader(response, corsValue);
    corsValue = "https://localhost:9200";
    response = getRestClient().performRequest("GET", "/", new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue));
    assertResponseWithOriginheader(response, corsValue);
    assertThat(response.getHeader("Access-Control-Allow-Credentials"), is("true"));
}
Also used : Response(org.elasticsearch.client.Response) BasicHeader(org.apache.http.message.BasicHeader)

Example 50 with Response

use of org.elasticsearch.client.Response in project elasticsearch by elastic.

the class CorsRegexIT method testThatPreFlightRequestWorksOnMatch.

public void testThatPreFlightRequestWorksOnMatch() throws IOException {
    String corsValue = "http://localhost:9200";
    Response response = getRestClient().performRequest("OPTIONS", "/", new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue), new BasicHeader("Access-Control-Request-Method", "GET"));
    assertResponseWithOriginheader(response, corsValue);
    assertNotNull(response.getHeader("Access-Control-Allow-Methods"));
}
Also used : Response(org.elasticsearch.client.Response) BasicHeader(org.apache.http.message.BasicHeader)

Aggregations

Response (org.elasticsearch.client.Response)75 IOException (java.io.IOException)24 Request (org.elasticsearch.client.Request)19 BasicHeader (org.apache.http.message.BasicHeader)14 NStringEntity (org.apache.http.nio.entity.NStringEntity)14 HttpEntity (org.apache.http.HttpEntity)13 ResponseException (org.elasticsearch.client.ResponseException)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 HashMap (java.util.HashMap)9 RestClient (org.elasticsearch.client.RestClient)8 Map (java.util.Map)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7 ArrayList (java.util.ArrayList)6 RestBulkItemResponse (org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse)6 JSONArray (org.json.simple.JSONArray)6 JSONObject (org.json.simple.JSONObject)6 JSONParser (org.json.simple.parser.JSONParser)6 ParseException (org.json.simple.parser.ParseException)6 InputStream (java.io.InputStream)5 StringEntity (org.apache.http.entity.StringEntity)5