Skip to content

Commit 457d204

Browse files
committed
Fix the failing test case FieldLevelSecurityTests#testParentChild_parentField.
1 parent 85d00cb commit 457d204

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,11 +1337,21 @@ public void testMTVApi() throws Exception {
13371337
assertThat(response.getResponses()[0].getResponse().getFields().terms("field2").size(), equalTo(1L));
13381338
}
13391339

1340-
public void testParentChild_parentField() {
1340+
public void testParentChild_parentField() throws Exception {
1341+
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject()
1342+
.startObject("_parent")
1343+
.field("type", "parent")
1344+
.endObject()
1345+
.startObject("properties")
1346+
.startObject("field1")
1347+
.field("type", "keyword")
1348+
.endObject()
1349+
.endObject()
1350+
.endObject();
13411351
assertAcked(prepareCreate("test")
13421352
.setSettings(Settings.builder().put("index.version.created", Version.V_5_6_0.id))
13431353
.addMapping("parent")
1344-
.addMapping("child", "_parent", "type=parent"));
1354+
.addMapping("child", mapping));
13451355
ensureGreen();
13461356

13471357
// index simple data
@@ -1388,7 +1398,25 @@ public void testParentChild_joinField() throws Exception {
13881398
source.put("join_field", joinField);
13891399
client().prepareIndex("test", "doc", "c2").setSource(source).setRouting("p1").get();
13901400
refresh();
1401+
13911402
verifyParentChild();
1403+
1404+
// Perform the same checks, but using an alias for field1.
1405+
SearchResponse searchResponse = client()
1406+
.filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD)))
1407+
.prepareSearch("test")
1408+
.setQuery(hasChildQuery("child", termQuery("alias", "yellow"), ScoreMode.None))
1409+
.get();
1410+
assertHitCount(searchResponse, 1L);
1411+
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
1412+
assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1"));
1413+
1414+
searchResponse = client()
1415+
.filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD)))
1416+
.prepareSearch("test")
1417+
.setQuery(hasChildQuery("child", termQuery("alias", "yellow"), ScoreMode.None))
1418+
.get();
1419+
assertHitCount(searchResponse, 0L);
13921420
}
13931421

13941422
private void verifyParentChild() {
@@ -1407,23 +1435,6 @@ private void verifyParentChild() {
14071435
.setQuery(hasChildQuery("child", termQuery("field1", "yellow"), ScoreMode.None))
14081436
.get();
14091437
assertHitCount(searchResponse, 0L);
1410-
1411-
// Perform the same checks, but using an alias for field1.
1412-
searchResponse = client()
1413-
.filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD)))
1414-
.prepareSearch("test")
1415-
.setQuery(hasChildQuery("child", termQuery("alias", "yellow"), ScoreMode.None))
1416-
.get();
1417-
assertHitCount(searchResponse, 1L);
1418-
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
1419-
assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("p1"));
1420-
1421-
searchResponse = client()
1422-
.filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD)))
1423-
.prepareSearch("test")
1424-
.setQuery(hasChildQuery("child", termQuery("alias", "yellow"), ScoreMode.None))
1425-
.get();
1426-
assertHitCount(searchResponse, 0L);
14271438
}
14281439

14291440
public void testUpdateApiIsBlocked() throws Exception {

0 commit comments

Comments
 (0)