summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java
diff options
context:
space:
mode:
authorJay Modi <jaymode@users.noreply.github.com>2017-02-02 14:07:13 -0500
committerGitHub <noreply@github.com>2017-02-02 14:07:13 -0500
commit7520a107bee67099338813728147d2aee25ed240 (patch)
tree22828e74c5aa601c185c36c7463665fbfeaa4c51 /core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java
parentb41d5747f0bd67dad05c8168312ba456bcdaebda (diff)
Optionally require a valid content type for all rest requests with content (#22691)
This change adds a strict mode for xcontent parsing on the rest layer. The strict mode will be off by default for 5.x and in a separate commit will be enabled by default for 6.0. The strict mode, which can be enabled by setting `http.content_type.required: true` in 5.x, will require that all incoming rest requests have a valid and supported content type header before the request is dispatched. In the non-strict mode, the Content-Type header will be inspected and if it is not present or not valid, we will continue with auto detection of content like we have done previously. The content type header is parsed to the matching XContentType value with the only exception being for plain text requests. This value is then passed on with the content bytes so that we can reduce the number of places where we need to auto-detect the content type. As part of this, many transport requests and builders were updated to provide methods that accepted the XContentType along with the bytes and the methods that would rely on auto-detection have been deprecated. In the non-strict mode, deprecation warnings are issued whenever a request with body doesn't provide the Content-Type header. See #19388
Diffstat (limited to 'core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java')
-rw-r--r--core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java37
1 files changed, 19 insertions, 18 deletions
diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java b/core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java
index e2fca8b411..518b775d7f 100644
--- a/core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java
+++ b/core/src/test/java/org/elasticsearch/ingest/IngestMetadataTests.java
@@ -42,10 +42,10 @@ public class IngestMetadataTests extends ESTestCase {
public void testFromXContent() throws IOException {
PipelineConfiguration pipeline = new PipelineConfiguration(
- "1",new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}")
+ "1", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON
);
PipelineConfiguration pipeline2 = new PipelineConfiguration(
- "2",new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field1\", \"value\": \"_value1\"}}]}")
+ "2", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field1\", \"value\": \"_value1\"}}]}"), XContentType.JSON
);
Map<String, PipelineConfiguration> map = new HashMap<>();
map.put(pipeline.getId(), pipeline);
@@ -72,14 +72,14 @@ public class IngestMetadataTests extends ESTestCase {
BytesReference pipelineConfig = new BytesArray("{}");
Map<String, PipelineConfiguration> pipelines = new HashMap<>();
- pipelines.put("1", new PipelineConfiguration("1", pipelineConfig));
- pipelines.put("2", new PipelineConfiguration("2", pipelineConfig));
+ pipelines.put("1", new PipelineConfiguration("1", pipelineConfig, XContentType.JSON));
+ pipelines.put("2", new PipelineConfiguration("2", pipelineConfig, XContentType.JSON));
IngestMetadata ingestMetadata1 = new IngestMetadata(pipelines);
pipelines = new HashMap<>();
- pipelines.put("1", new PipelineConfiguration("1", pipelineConfig));
- pipelines.put("3", new PipelineConfiguration("3", pipelineConfig));
- pipelines.put("4", new PipelineConfiguration("4", pipelineConfig));
+ pipelines.put("1", new PipelineConfiguration("1", pipelineConfig, XContentType.JSON));
+ pipelines.put("3", new PipelineConfiguration("3", pipelineConfig, XContentType.JSON));
+ pipelines.put("4", new PipelineConfiguration("4", pipelineConfig, XContentType.JSON));
IngestMetadata ingestMetadata2 = new IngestMetadata(pipelines);
IngestMetadata.IngestMetadataDiff diff = (IngestMetadata.IngestMetadataDiff) ingestMetadata2.diff(ingestMetadata1);
@@ -92,13 +92,13 @@ public class IngestMetadataTests extends ESTestCase {
IngestMetadata endResult = (IngestMetadata) diff.apply(ingestMetadata2);
assertThat(endResult, not(equalTo(ingestMetadata1)));
assertThat(endResult.getPipelines().size(), equalTo(3));
- assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig)));
- assertThat(endResult.getPipelines().get("3"), equalTo(new PipelineConfiguration("3", pipelineConfig)));
- assertThat(endResult.getPipelines().get("4"), equalTo(new PipelineConfiguration("4", pipelineConfig)));
+ assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig, XContentType.JSON)));
+ assertThat(endResult.getPipelines().get("3"), equalTo(new PipelineConfiguration("3", pipelineConfig, XContentType.JSON)));
+ assertThat(endResult.getPipelines().get("4"), equalTo(new PipelineConfiguration("4", pipelineConfig, XContentType.JSON)));
pipelines = new HashMap<>();
- pipelines.put("1", new PipelineConfiguration("1", new BytesArray("{}")));
- pipelines.put("2", new PipelineConfiguration("2", new BytesArray("{}")));
+ pipelines.put("1", new PipelineConfiguration("1", new BytesArray("{}"), XContentType.JSON));
+ pipelines.put("2", new PipelineConfiguration("2", new BytesArray("{}"), XContentType.JSON));
IngestMetadata ingestMetadata3 = new IngestMetadata(pipelines);
diff = (IngestMetadata.IngestMetadataDiff) ingestMetadata3.diff(ingestMetadata1);
@@ -108,12 +108,12 @@ public class IngestMetadataTests extends ESTestCase {
endResult = (IngestMetadata) diff.apply(ingestMetadata3);
assertThat(endResult, equalTo(ingestMetadata1));
assertThat(endResult.getPipelines().size(), equalTo(2));
- assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig)));
- assertThat(endResult.getPipelines().get("2"), equalTo(new PipelineConfiguration("2", pipelineConfig)));
+ assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig, XContentType.JSON)));
+ assertThat(endResult.getPipelines().get("2"), equalTo(new PipelineConfiguration("2", pipelineConfig, XContentType.JSON)));
pipelines = new HashMap<>();
- pipelines.put("1", new PipelineConfiguration("1", new BytesArray("{}")));
- pipelines.put("2", new PipelineConfiguration("2", new BytesArray("{\"key\" : \"value\"}")));
+ pipelines.put("1", new PipelineConfiguration("1", new BytesArray("{}"), XContentType.JSON));
+ pipelines.put("2", new PipelineConfiguration("2", new BytesArray("{\"key\" : \"value\"}"), XContentType.JSON));
IngestMetadata ingestMetadata4 = new IngestMetadata(pipelines);
diff = (IngestMetadata.IngestMetadataDiff) ingestMetadata4.diff(ingestMetadata1);
@@ -123,7 +123,8 @@ public class IngestMetadataTests extends ESTestCase {
endResult = (IngestMetadata) diff.apply(ingestMetadata4);
assertThat(endResult, not(equalTo(ingestMetadata1)));
assertThat(endResult.getPipelines().size(), equalTo(2));
- assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig)));
- assertThat(endResult.getPipelines().get("2"), equalTo(new PipelineConfiguration("2", new BytesArray("{\"key\" : \"value\"}"))));
+ assertThat(endResult.getPipelines().get("1"), equalTo(new PipelineConfiguration("1", pipelineConfig, XContentType.JSON)));
+ assertThat(endResult.getPipelines().get("2"),
+ equalTo(new PipelineConfiguration("2", new BytesArray("{\"key\" : \"value\"}"), XContentType.JSON)));
}
}