Search in sources :

Example 71 with Response

use of org.graylog.shaded.elasticsearch7.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 72 with Response

use of org.graylog.shaded.elasticsearch7.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 73 with Response

use of org.graylog.shaded.elasticsearch7.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 74 with Response

use of org.graylog.shaded.elasticsearch7.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 75 with Response

use of org.graylog.shaded.elasticsearch7.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)111 Request (org.elasticsearch.client.Request)38 IOException (java.io.IOException)33 HttpEntity (org.apache.http.HttpEntity)24 NStringEntity (org.apache.http.nio.entity.NStringEntity)21 Test (org.junit.Test)20 HashMap (java.util.HashMap)17 Map (java.util.Map)14 BasicHeader (org.apache.http.message.BasicHeader)14 ResponseException (org.elasticsearch.client.ResponseException)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 RestClient (org.elasticsearch.client.RestClient)11 ArrayList (java.util.ArrayList)10 RestBulkItemResponse (org.janusgraph.diskstorage.es.rest.RestBulkResponse.RestBulkItemResponse)10 StringEntity (org.apache.http.entity.StringEntity)9 SearchResponse (org.elasticsearch.action.search.SearchResponse)9 InputStream (java.io.InputStream)8 JSONObject (org.json.simple.JSONObject)8 MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7