use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project elasticsearch by elastic.
the class HttpCompressionIT method testUncompressedResponseByDefault.
public void testUncompressedResponseByDefault() throws IOException {
RestClient client = client();
Response response = client.performRequest("GET", "/");
assertEquals(200, response.getStatusLine().getStatusCode());
assertNull(response.getHeader(HttpHeaders.CONTENT_ENCODING));
response = client.performRequest("POST", "/company/employees/1", Collections.emptyMap(), SAMPLE_DOCUMENT);
assertEquals(201, response.getStatusLine().getStatusCode());
assertNull(response.getHeader(HttpHeaders.CONTENT_ENCODING));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project elasticsearch by elastic.
the class CorsNotSetIT method testThatOmittingCorsHeaderDoesNotReturnAnything.
public void testThatOmittingCorsHeaderDoesNotReturnAnything() throws IOException {
Response response = getRestClient().performRequest("GET", "/");
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Credentials"), nullValue());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project elasticsearch by elastic.
the class CorsRegexIT method testThatRegularExpressionReturnsForbiddenOnNonMatch.
public void testThatRegularExpressionReturnsForbiddenOnNonMatch() throws IOException {
try {
getRestClient().performRequest("GET", "/", new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", "http://evil-host:9200"));
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());
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project elasticsearch by elastic.
the class CorsRegexIT method testThatSendingNoOriginHeaderReturnsNoAccessControlHeader.
public void testThatSendingNoOriginHeaderReturnsNoAccessControlHeader() throws IOException {
Response response = getRestClient().performRequest("GET", "/", new BasicHeader("User-Agent", "Mozilla Bar"));
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project elasticsearch by elastic.
the class DeprecationHttpIT method testUniqueDeprecationResponsesMergedTogether.
/**
* Attempts to do a scatter/gather request that expects unique responses per sub-request.
*/
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/19222")
public void testUniqueDeprecationResponsesMergedTogether() throws IOException {
final String[] indices = new String[randomIntBetween(2, 5)];
// add at least one document for each index
for (int i = 0; i < indices.length; ++i) {
indices[i] = "test" + i;
// create indices with a single shard to reduce noise; the query only deprecates uniquely by index anyway
assertTrue(prepareCreate(indices[i]).setSettings(Settings.builder().put("number_of_shards", 1)).get().isAcknowledged());
int randomDocCount = randomIntBetween(1, 2);
for (int j = 0; j < randomDocCount; ++j) {
index(indices[i], "type", Integer.toString(j), "{\"field\":" + j + "}");
}
}
refresh(indices);
final String commaSeparatedIndices = Stream.of(indices).collect(Collectors.joining(","));
final String body = "{\"query\":{\"bool\":{\"filter\":[{\"" + TestDeprecatedQueryBuilder.NAME + "\":{}}]}}}";
// trigger all index deprecations
Response response = getRestClient().performRequest("GET", "/" + commaSeparatedIndices + "/_search", Collections.emptyMap(), new StringEntity(body, ContentType.APPLICATION_JSON));
assertThat(response.getStatusLine().getStatusCode(), equalTo(OK.getStatus()));
final List<String> deprecatedWarnings = getWarningHeaders(response.getHeaders());
final List<Matcher<String>> headerMatchers = new ArrayList<>(indices.length);
for (String index : indices) {
headerMatchers.add(containsString(LoggerMessageFormat.format("[{}] index", (Object) index)));
}
assertThat(deprecatedWarnings, hasSize(headerMatchers.size()));
for (Matcher<String> headerMatcher : headerMatchers) {
assertThat(deprecatedWarnings, hasItem(headerMatcher));
}
}
Aggregations