Skip to content

Commit c47fea3

Browse files
committed
Merge branch 'fix-geoip-access-after-reindex-new-test' into fix-geoip-access-after-reindex
2 parents 9f653e1 + 4308559 commit c47fea3

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

server/src/test/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolverTests.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@
1313
import org.elasticsearch.common.settings.Settings;
1414
import org.elasticsearch.common.util.concurrent.ThreadContext;
1515
import org.elasticsearch.core.Tuple;
16+
import org.elasticsearch.index.IndexVersion;
1617
import org.elasticsearch.indices.EmptySystemIndices;
1718
import org.elasticsearch.indices.InvalidIndexNameException;
19+
import org.elasticsearch.indices.SystemIndexDescriptor;
20+
import org.elasticsearch.indices.SystemIndices;
1821
import org.elasticsearch.test.ESTestCase;
22+
import org.elasticsearch.xcontent.XContentBuilder;
1923

24+
import java.io.IOException;
25+
import java.io.UncheckedIOException;
2026
import java.util.List;
2127
import java.util.Set;
2228
import java.util.concurrent.TimeUnit;
2329
import java.util.function.Supplier;
2430

31+
import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;
32+
import static org.elasticsearch.indices.SystemIndices.SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY;
33+
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
2534
import static org.hamcrest.Matchers.contains;
2635
import static org.hamcrest.Matchers.containsInAnyOrder;
2736
import static org.hamcrest.Matchers.either;
@@ -227,6 +236,71 @@ private boolean isIndexVisible(String index, String selector) {
227236
);
228237
}
229238

239+
public void testIsNetNewSystemIndexVisible() {
240+
final Settings settings = Settings.builder()
241+
.put("index.number_of_replicas", 0)
242+
.put("index.number_of_shards", 1)
243+
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
244+
.build();
245+
246+
final Settings hiddenSettings = Settings.builder().put(settings).put("index.hidden", true).build();
247+
248+
final IndexMetadata foo = IndexMetadata.builder(".foo").settings(hiddenSettings).system(true).build();
249+
final IndexMetadata barReindexed = IndexMetadata.builder(".bar-reindexed")
250+
.settings(hiddenSettings)
251+
.system(true)
252+
.putAlias(AliasMetadata.builder(".bar").isHidden(true).build())
253+
.build();
254+
final IndexMetadata other = IndexMetadata.builder("other").settings(settings).build();
255+
256+
final SystemIndexDescriptor fooDescriptor = SystemIndexDescriptor.builder()
257+
.setDescription("foo indices")
258+
.setOrigin("foo origin")
259+
.setPrimaryIndex(".foo")
260+
.setIndexPattern(".foo*")
261+
.setSettings(settings)
262+
.setMappings(mappings())
263+
.setNetNew()
264+
.build();
265+
final SystemIndexDescriptor barDescriptor = SystemIndexDescriptor.builder()
266+
.setDescription("bar indices")
267+
.setOrigin("bar origin")
268+
.setPrimaryIndex(".bar")
269+
.setIndexPattern(".bar*")
270+
.setSettings(settings)
271+
.setMappings(mappings())
272+
.setNetNew()
273+
.build();
274+
final SystemIndices systemIndices = new SystemIndices(
275+
List.of(new SystemIndices.Feature("name", "description", List.of(fooDescriptor, barDescriptor)))
276+
);
277+
278+
final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
279+
threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "false");
280+
indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices);
281+
indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver);
282+
283+
metadata = Metadata.builder().put(foo, true).put(barReindexed, true).put(other, true).build();
284+
285+
assertThat(isIndexVisible("other", "*"), is(true));
286+
assertThat(isIndexVisible(".foo", "*"), is(false));
287+
assertThat(isIndexVisible(".bar", "*"), is(false));
288+
}
289+
290+
private static XContentBuilder mappings() {
291+
try (XContentBuilder builder = jsonBuilder()) {
292+
return builder.startObject()
293+
.startObject(SINGLE_MAPPING_NAME)
294+
.startObject("_meta")
295+
.field(SystemIndexDescriptor.VERSION_META_KEY, 0)
296+
.endObject()
297+
.endObject()
298+
.endObject();
299+
} catch (IOException e) {
300+
throw new UncheckedIOException(e);
301+
}
302+
}
303+
230304
private List<String> resolveAbstractionsSelectorNotAllowed(List<String> expressions) {
231305
return resolveAbstractions(expressions, IndicesOptions.strictExpandHiddenNoSelectors(), defaultMask);
232306
}

0 commit comments

Comments
 (0)