mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-26 14:54:56 +00:00
test: add tests for scroll requests with document and field level security
Original commit: elastic/x-pack-elasticsearch@107b24e785
This commit is contained in:
parent
e51aa21575
commit
8e816bdfb9
@ -16,6 +16,7 @@ import org.elasticsearch.action.termvectors.TermVectorsRequest;
|
|||||||
import org.elasticsearch.action.termvectors.TermVectorsResponse;
|
import org.elasticsearch.action.termvectors.TermVectorsResponse;
|
||||||
import org.elasticsearch.action.update.UpdateRequest;
|
import org.elasticsearch.action.update.UpdateRequest;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.indices.IndicesRequestCache;
|
import org.elasticsearch.indices.IndicesRequestCache;
|
||||||
@ -675,6 +676,59 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase {
|
|||||||
assertThat(response.getMatches()[0].getId().string(), equalTo("1"));
|
assertThat(response.getMatches()[0].getId().string(), equalTo("1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testScroll() throws Exception {
|
||||||
|
assertAcked(client().admin().indices().prepareCreate("test")
|
||||||
|
.setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true))
|
||||||
|
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
||||||
|
);
|
||||||
|
final int numVisible = scaledRandomIntBetween(2, 10);
|
||||||
|
final int numInVisible = scaledRandomIntBetween(2, 10);
|
||||||
|
int id = 1;
|
||||||
|
for (int i = 0; i < numVisible; i++) {
|
||||||
|
client().prepareIndex("test", "type1", String.valueOf(id++)).setSource("field1", "value1").get();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < numInVisible; i++) {
|
||||||
|
client().prepareIndex("test", "type1", String.valueOf(id++)).setSource("field2", "value2").get();
|
||||||
|
client().prepareIndex("test", "type1", String.valueOf(id++)).setSource("field3", "value3").get();
|
||||||
|
}
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
SearchResponse response = null;
|
||||||
|
try {
|
||||||
|
response = client()
|
||||||
|
.filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD)))
|
||||||
|
.prepareSearch("test")
|
||||||
|
.setSize(1)
|
||||||
|
.setScroll(TimeValue.timeValueMinutes(1L))
|
||||||
|
.setQuery(termQuery("field1", "value1"))
|
||||||
|
.get();
|
||||||
|
do {
|
||||||
|
assertNoFailures(response);
|
||||||
|
assertThat(response.getHits().getTotalHits(), is((long) numVisible));
|
||||||
|
assertThat(response.getHits().getAt(0).getSource().size(), is(1));
|
||||||
|
assertThat(response.getHits().getAt(0).getSource().get("field1"), is("value1"));
|
||||||
|
|
||||||
|
if (response.getScrollId() == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
response = client()
|
||||||
|
.filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD)))
|
||||||
|
.prepareSearchScroll(response.getScrollId())
|
||||||
|
.setScroll(TimeValue.timeValueMinutes(1L))
|
||||||
|
.get();
|
||||||
|
} while (response.getHits().getHits().length > 0);
|
||||||
|
} finally {
|
||||||
|
if (response != null) {
|
||||||
|
String scrollId = response.getScrollId();
|
||||||
|
if (scrollId != null) {
|
||||||
|
client().prepareClearScroll().addScrollId(scrollId).get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testRequestCache() throws Exception {
|
public void testRequestCache() throws Exception {
|
||||||
assertAcked(client().admin().indices().prepareCreate("test")
|
assertAcked(client().admin().indices().prepareCreate("test")
|
||||||
.setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true))
|
.setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true))
|
||||||
|
@ -17,6 +17,7 @@ import org.elasticsearch.action.termvectors.TermVectorsRequest;
|
|||||||
import org.elasticsearch.action.termvectors.TermVectorsResponse;
|
import org.elasticsearch.action.termvectors.TermVectorsResponse;
|
||||||
import org.elasticsearch.action.update.UpdateRequest;
|
import org.elasticsearch.action.update.UpdateRequest;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.index.IndexModule;
|
import org.elasticsearch.index.IndexModule;
|
||||||
import org.elasticsearch.indices.IndicesRequestCache;
|
import org.elasticsearch.indices.IndicesRequestCache;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
@ -555,6 +556,58 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
|
|||||||
assertThat(response.getAllFieldStats().get("field2").getDocCount(), equalTo(1L));
|
assertThat(response.getAllFieldStats().get("field2").getDocCount(), equalTo(1L));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testScroll() throws Exception {
|
||||||
|
assertAcked(client().admin().indices().prepareCreate("test")
|
||||||
|
.setSettings(Settings.builder().put(IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING.getKey(), true))
|
||||||
|
.addMapping("type1", "field1", "type=text", "field2", "type=text", "field3", "type=text")
|
||||||
|
);
|
||||||
|
|
||||||
|
final int numDocs = scaledRandomIntBetween(2, 10);
|
||||||
|
for (int i = 0; i < numDocs; i++) {
|
||||||
|
client().prepareIndex("test", "type1", String.valueOf(i))
|
||||||
|
.setSource("field1", "value1", "field2", "value2", "field3", "value3")
|
||||||
|
.get();
|
||||||
|
}
|
||||||
|
refresh("test");
|
||||||
|
|
||||||
|
SearchResponse response = null;
|
||||||
|
try {
|
||||||
|
response = client()
|
||||||
|
.filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD)))
|
||||||
|
.prepareSearch("test")
|
||||||
|
.setScroll(TimeValue.timeValueMinutes(1L))
|
||||||
|
.setSize(1)
|
||||||
|
.setQuery(constantScoreQuery(termQuery("field1", "value1")))
|
||||||
|
.setFetchSource(true)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
do {
|
||||||
|
assertThat(response.getHits().getTotalHits(), is((long) numDocs));
|
||||||
|
assertThat(response.getHits().getHits().length, is(1));
|
||||||
|
assertThat(response.getHits().getAt(0).getSource().size(), is(1));
|
||||||
|
assertThat(response.getHits().getAt(0).getSource().get("field1"), is("value1"));
|
||||||
|
|
||||||
|
if (response.getScrollId() == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
response = client()
|
||||||
|
.filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD)))
|
||||||
|
.prepareSearchScroll(response.getScrollId())
|
||||||
|
.setScroll(TimeValue.timeValueMinutes(1L))
|
||||||
|
.get();
|
||||||
|
} while (response.getHits().getHits().length > 0);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (response != null) {
|
||||||
|
String scrollId = response.getScrollId();
|
||||||
|
if (scrollId != null) {
|
||||||
|
client().prepareClearScroll().addScrollId(scrollId).get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testQueryCache() throws Exception {
|
public void testQueryCache() throws Exception {
|
||||||
assertAcked(client().admin().indices().prepareCreate("test")
|
assertAcked(client().admin().indices().prepareCreate("test")
|
||||||
.setSettings(Settings.builder().put(IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING.getKey(), true))
|
.setSettings(Settings.builder().put(IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING.getKey(), true))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user