From bd834b7357403e23d681731416db111acb19fa72 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 11 Apr 2018 08:43:52 +0200 Subject: [PATCH] Remove legacy mapping code. (elastic/x-pack-elasticsearch#4258) This is a sibling of elastic/elasticsearch#29224. Original commit: elastic/x-pack-elasticsearch@1c16d86f7862c2203ea123486adf808b369d1908 --- ...SecurityIndexSearcherWrapperUnitTests.java | 9 --- .../DocumentAndFieldLevelSecurityTests.java | 4 +- .../DocumentLevelSecurityTests.java | 77 +------------------ .../FieldLevelSecurityRandomTests.java | 12 +-- .../integration/FieldLevelSecurityTests.java | 17 +--- 5 files changed, 11 insertions(+), 108 deletions(-) diff --git a/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/SecurityIndexSearcherWrapperUnitTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/SecurityIndexSearcherWrapperUnitTests.java index 75ee872031e..d02d7e5fe97 100644 --- a/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/SecurityIndexSearcherWrapperUnitTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/SecurityIndexSearcherWrapperUnitTests.java @@ -48,7 +48,6 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.cache.bitset.BitsetFilterCache; import org.elasticsearch.index.mapper.FieldNamesFieldMapper; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.mapper.ParentFieldMapper; import org.elasticsearch.index.mapper.SeqNoFieldMapper; import org.elasticsearch.index.mapper.SourceFieldMapper; import org.elasticsearch.index.query.BoolQueryBuilder; @@ -171,7 +170,6 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase { assertThat(result.getFilter().run("_type"), is(true)); assertThat(result.getFilter().run("_source"), is(true)); assertThat(result.getFilter().run("_routing"), is(true)); - assertThat(result.getFilter().run("_parent"), is(true)); assertThat(result.getFilter().run("_timestamp"), is(true)); assertThat(result.getFilter().run("_ttl"), is(true)); assertThat(result.getFilter().run("_size"), is(true)); @@ -216,13 +214,6 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase { assertResolved(new FieldPermissions(fieldPermissionDef(new String[] {"foo.*"}, null)), expected, "foo", "bar"); } - public void testParentChild() throws Exception { - Set expected = new HashSet<>(META_FIELDS); - expected.add(ParentFieldMapper.joinField("parent1")); - expected.add("foo"); - assertResolved(new FieldPermissions(fieldPermissionDef(new String[] {"foo"}, null)), expected, "bar"); - } - public void testDelegateSimilarity() throws Exception { IndexSettings settings = IndexSettingsModule.newIndexSettings("_index", Settings.EMPTY); BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(settings, new BitsetFilterCache.Listener() { diff --git a/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java b/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java index aa6f409ad2a..5326954635e 100644 --- a/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java @@ -134,7 +134,7 @@ public class DocumentAndFieldLevelSecurityTests extends SecurityIntegTestCase { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD))) .prepareSearch("test") - .addSort("_uid", SortOrder.ASC) + .addSort("_id", SortOrder.ASC) .get(); assertHitCount(response, 2); assertSearchHits(response, "1", "2"); @@ -214,7 +214,7 @@ public class DocumentAndFieldLevelSecurityTests extends SecurityIntegTestCase { response = client().filterWithHeader( Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD))) .prepareSearch("test") - .addSort("_uid", SortOrder.ASC) + .addSort("_id", SortOrder.ASC) .get(); assertHitCount(response, 2); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); diff --git a/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java b/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java index e958a39d56e..aa74b719637 100644 --- a/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java @@ -600,80 +600,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase { assertThat(termsAgg.getBuckets().size(), equalTo(1)); } - public void testChildrenAggregation() throws Exception { - assertAcked(client().admin().indices().prepareCreate("test") - .setSettings(Settings.builder().put("index.version.created", Version.V_5_6_0.id)) - .addMapping("type1", "field1", "type=text", "field2", "type=text") - .addMapping("type2", "_parent", "type=type1", "field3", "type=text,fielddata=true") - ); - client().prepareIndex("test", "type1", "1").setSource("field1", "value1") - .setRefreshPolicy(IMMEDIATE) - .get(); - client().prepareIndex("test", "type2", "2").setSource("field3", "value3") - .setParent("1") - .setRefreshPolicy(IMMEDIATE) - .get(); - - SearchResponse response = client().prepareSearch("test") - .setTypes("type1") - .addAggregation(JoinAggregationBuilders.children("children", "type2") - .subAggregation(AggregationBuilders.terms("field3").field("field3"))) - .get(); - assertHitCount(response, 1); - assertSearchHits(response, "1"); - - Children children = response.getAggregations().get("children"); - assertThat(children.getDocCount(), equalTo(1L)); - Terms termsAgg = children.getAggregations().get("field3"); - assertThat(termsAgg.getBuckets().get(0).getKeyAsString(), equalTo("value3")); - assertThat(termsAgg.getBuckets().get(0).getDocCount(), equalTo(1L)); - - response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) - .prepareSearch("test") - .setTypes("type1") - .addAggregation(JoinAggregationBuilders.children("children", "type2") - .subAggregation(AggregationBuilders.terms("field3").field("field3"))) - .get(); - assertHitCount(response, 1); - assertSearchHits(response, "1"); - - children = response.getAggregations().get("children"); - assertThat(children.getDocCount(), equalTo(0L)); - termsAgg = children.getAggregations().get("field3"); - assertThat(termsAgg.getBuckets().size(), equalTo(0)); - - response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) - .prepareSearch("test") - .setTypes("type1") - .addAggregation(JoinAggregationBuilders.children("children", "type2") - .subAggregation(AggregationBuilders.terms("field3").field("field3"))) - .get(); - assertHitCount(response, 1); - assertSearchHits(response, "1"); - - children = response.getAggregations().get("children"); - assertThat(children.getDocCount(), equalTo(0L)); - termsAgg = children.getAggregations().get("field3"); - assertThat(termsAgg.getBuckets().size(), equalTo(0)); - } - - public void testParentChild_parentField() { - assertAcked(prepareCreate("test") - .setSettings(Settings.builder().put("index.version.created", Version.V_5_6_0.id)) - .addMapping("parent") - .addMapping("child", "_parent", "type=parent", "field1", "type=text", "field2", "type=text", "field3", "type=text")); - ensureGreen(); - - // index simple data - client().prepareIndex("test", "parent", "p1").setSource("field1", "value1").get(); - client().prepareIndex("test", "child", "c1").setSource("field2", "value2").setParent("p1").get(); - client().prepareIndex("test", "child", "c2").setSource("field2", "value2").setParent("p1").get(); - client().prepareIndex("test", "child", "c3").setSource("field3", "value3").setParent("p1").get(); - refresh(); - verifyParentChild(); - } - - public void testParentChild_joinField() throws Exception { + public void testParentChild() throws Exception { XContentBuilder mapping = jsonBuilder().startObject() .startObject("properties") .startObject("join_field") @@ -725,7 +652,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase { searchResponse = client().prepareSearch("test") .setQuery(hasParentQuery("parent", matchAllQuery(), false)) - .addSort("_uid", SortOrder.ASC) + .addSort("_id", SortOrder.ASC) .get(); assertHitCount(searchResponse, 3L); assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("c1")); diff --git a/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java b/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java index 2a8e9e7a0f8..995b91d3628 100644 --- a/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityRandomTests.java @@ -181,7 +181,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase { SearchResponse actual = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .prepareSearch("test") - .addSort("_uid", SortOrder.ASC) + .addSort("_id", SortOrder.ASC) .setQuery(QueryBuilders.boolQuery() .should(QueryBuilders.termQuery("field1", "value")) .should(QueryBuilders.termQuery("field2", "value")) @@ -189,7 +189,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase { ) .get(); SearchResponse expected = client().prepareSearch("test") - .addSort("_uid", SortOrder.ASC) + .addSort("_id", SortOrder.ASC) .setQuery(QueryBuilders.boolQuery() .should(QueryBuilders.termQuery("field1", "value")) ) @@ -202,7 +202,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase { actual = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) .prepareSearch("test") - .addSort("_uid", SortOrder.ASC) + .addSort("_id", SortOrder.ASC) .setQuery(QueryBuilders.boolQuery() .should(QueryBuilders.termQuery("field1", "value")) .should(QueryBuilders.termQuery("field2", "value")) @@ -210,7 +210,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase { ) .get(); expected = client().prepareSearch("test") - .addSort("_uid", SortOrder.ASC) + .addSort("_id", SortOrder.ASC) .setQuery(QueryBuilders.boolQuery() .should(QueryBuilders.termQuery("field2", "value")) ) @@ -223,7 +223,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase { actual = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD))) .prepareSearch("test") - .addSort("_uid", SortOrder.ASC) + .addSort("_id", SortOrder.ASC) .setQuery(QueryBuilders.boolQuery() .should(QueryBuilders.termQuery("field1", "value")) .should(QueryBuilders.termQuery("field2", "value")) @@ -231,7 +231,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase { ) .get(); expected = client().prepareSearch("test") - .addSort("_uid", SortOrder.ASC) + .addSort("_id", SortOrder.ASC) .setQuery(QueryBuilders.boolQuery() .should(QueryBuilders.termQuery("field3", "value")) ) diff --git a/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java b/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java index b13c0dca8f3..7d31edb3749 100644 --- a/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java @@ -1219,22 +1219,7 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { assertThat(response.getResponses()[0].getResponse().getFields().terms("field2").size(), equalTo(1L)); } - public void testParentChild_parentField() { - assertAcked(prepareCreate("test") - .setSettings(Settings.builder().put("index.version.created", Version.V_5_6_0.id)) - .addMapping("parent") - .addMapping("child", "_parent", "type=parent")); - ensureGreen(); - - // index simple data - client().prepareIndex("test", "parent", "p1").setSource("{}", XContentType.JSON).get(); - client().prepareIndex("test", "child", "c1").setSource("field1", "red").setParent("p1").get(); - client().prepareIndex("test", "child", "c2").setSource("field1", "yellow").setParent("p1").get(); - refresh(); - verifyParentChild(); - } - - public void testParentChild_joinField() throws Exception { + public void testParentChild() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder().startObject() .startObject("properties") .startObject("join_field")