Reenable SecurityIndexSearcherWrapperIntegrationTests (elastic/x-pack-elasticsearch#1894)
Original commit: elastic/x-pack-elasticsearch@03ff1bf9a5
This commit is contained in:
parent
10c37f0fa4
commit
e7e24c453c
|
@ -42,7 +42,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.IndexSettings;
|
import org.elasticsearch.index.IndexSettings;
|
||||||
import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
|
import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
|
||||||
import org.elasticsearch.index.engine.EngineException;
|
import org.elasticsearch.index.engine.EngineException;
|
||||||
import org.elasticsearch.index.query.AbstractQueryBuilder;
|
|
||||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||||
import org.elasticsearch.index.query.BoostingQueryBuilder;
|
import org.elasticsearch.index.query.BoostingQueryBuilder;
|
||||||
import org.elasticsearch.index.query.ConstantScoreQueryBuilder;
|
import org.elasticsearch.index.query.ConstantScoreQueryBuilder;
|
||||||
|
@ -135,7 +134,7 @@ public class SecurityIndexSearcherWrapper extends IndexSearcherWrapper {
|
||||||
String templateResult = evaluateTemplate(bytesReference.utf8ToString());
|
String templateResult = evaluateTemplate(bytesReference.utf8ToString());
|
||||||
try (XContentParser parser = XContentFactory.xContent(templateResult)
|
try (XContentParser parser = XContentFactory.xContent(templateResult)
|
||||||
.createParser(queryShardContext.getXContentRegistry(), templateResult)) {
|
.createParser(queryShardContext.getXContentRegistry(), templateResult)) {
|
||||||
QueryBuilder queryBuilder = AbstractQueryBuilder.parseInnerQueryBuilder(parser);
|
QueryBuilder queryBuilder = queryShardContext.parseInnerQueryBuilder(parser);
|
||||||
verifyRoleQuery(queryBuilder);
|
verifyRoleQuery(queryBuilder);
|
||||||
failIfQueryUsesClient(scriptService, queryBuilder, queryShardContext);
|
failIfQueryUsesClient(scriptService, queryBuilder, queryShardContext);
|
||||||
ParsedQuery parsedQuery = queryShardContext.toFilter(queryBuilder);
|
ParsedQuery parsedQuery = queryShardContext.toFilter(queryBuilder);
|
||||||
|
|
|
@ -26,13 +26,10 @@ import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContentParser;
|
|
||||||
import org.elasticsearch.index.IndexSettings;
|
import org.elasticsearch.index.IndexSettings;
|
||||||
import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
|
import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
import org.elasticsearch.index.query.AbstractQueryBuilder;
|
|
||||||
import org.elasticsearch.index.query.ParsedQuery;
|
import org.elasticsearch.index.query.ParsedQuery;
|
||||||
import org.elasticsearch.index.query.QueryParseContext;
|
|
||||||
import org.elasticsearch.index.query.QueryShardContext;
|
import org.elasticsearch.index.query.QueryShardContext;
|
||||||
import org.elasticsearch.index.query.TermQueryBuilder;
|
import org.elasticsearch.index.query.TermQueryBuilder;
|
||||||
import org.elasticsearch.index.query.TermsQueryBuilder;
|
import org.elasticsearch.index.query.TermsQueryBuilder;
|
||||||
|
@ -51,13 +48,13 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyBoolean;
|
import static org.mockito.Matchers.anyBoolean;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class SecurityIndexSearcherWrapperIntegrationTests extends ESTestCase {
|
public class SecurityIndexSearcherWrapperIntegrationTests extends ESTestCase {
|
||||||
|
|
||||||
@AwaitsFix(bugUrl="https://github.com/elastic/x-pack-elasticsearch/issues/1890")
|
|
||||||
public void testDLS() throws Exception {
|
public void testDLS() throws Exception {
|
||||||
ShardId shardId = new ShardId("_index", "_na_", 0);
|
ShardId shardId = new ShardId("_index", "_na_", 0);
|
||||||
MapperService mapperService = mock(MapperService.class);
|
MapperService mapperService = mock(MapperService.class);
|
||||||
|
@ -77,7 +74,6 @@ public class SecurityIndexSearcherWrapperIntegrationTests extends ESTestCase {
|
||||||
QueryShardContext realQueryShardContext = new QueryShardContext(shardId.id(), indexSettings, null, null, mapperService, null,
|
QueryShardContext realQueryShardContext = new QueryShardContext(shardId.id(), indexSettings, null, null, mapperService, null,
|
||||||
null, xContentRegistry(), client, null, () -> nowInMillis);
|
null, xContentRegistry(), client, null, () -> nowInMillis);
|
||||||
QueryShardContext queryShardContext = spy(realQueryShardContext);
|
QueryShardContext queryShardContext = spy(realQueryShardContext);
|
||||||
QueryParseContext queryParseContext = mock(QueryParseContext.class);
|
|
||||||
IndexSettings settings = IndexSettingsModule.newIndexSettings("_index", Settings.EMPTY);
|
IndexSettings settings = IndexSettingsModule.newIndexSettings("_index", Settings.EMPTY);
|
||||||
BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(settings, new BitsetFilterCache.Listener() {
|
BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(settings, new BitsetFilterCache.Listener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -146,8 +142,7 @@ public class SecurityIndexSearcherWrapperIntegrationTests extends ESTestCase {
|
||||||
DirectoryReader directoryReader = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(directory), shardId);
|
DirectoryReader directoryReader = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(directory), shardId);
|
||||||
for (int i = 0; i < numValues; i++) {
|
for (int i = 0; i < numValues; i++) {
|
||||||
ParsedQuery parsedQuery = new ParsedQuery(new TermQuery(new Term("field", values[i])));
|
ParsedQuery parsedQuery = new ParsedQuery(new TermQuery(new Term("field", values[i])));
|
||||||
when(queryShardContext.newParseContext(anyParser())).thenReturn(queryParseContext);
|
doReturn(new TermQueryBuilder("field", values[i])).when(queryShardContext).parseInnerQueryBuilder(any(XContentParser.class));
|
||||||
when(AbstractQueryBuilder.parseInnerQueryBuilder(anyParser())).thenReturn(new TermQueryBuilder("field", values[i]));
|
|
||||||
when(queryShardContext.toFilter(new TermsQueryBuilder("field", values[i]))).thenReturn(parsedQuery);
|
when(queryShardContext.toFilter(new TermsQueryBuilder("field", values[i]))).thenReturn(parsedQuery);
|
||||||
DirectoryReader wrappedDirectoryReader = wrapper.wrap(directoryReader);
|
DirectoryReader wrappedDirectoryReader = wrapper.wrap(directoryReader);
|
||||||
IndexSearcher indexSearcher = wrapper.wrap(new IndexSearcher(wrappedDirectoryReader));
|
IndexSearcher indexSearcher = wrapper.wrap(new IndexSearcher(wrappedDirectoryReader));
|
||||||
|
@ -164,15 +159,4 @@ public class SecurityIndexSearcherWrapperIntegrationTests extends ESTestCase {
|
||||||
directoryReader.close();
|
directoryReader.close();
|
||||||
directory.close();
|
directory.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
QueryShardContext is spied (not mocked!) and because of that when we report a matcher can't pass in null to
|
|
||||||
queryShardContext.newParseContext(...), so we pass in a dummy parser instances. This allows us to report a
|
|
||||||
matcher and queryShardContext.newParseContext(...) fail with NPE.
|
|
||||||
*/
|
|
||||||
private static XContentParser anyParser() {
|
|
||||||
any(XContentParser.class);
|
|
||||||
return new JsonXContentParser(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue