|
13 | 13 | import org.elasticsearch.common.settings.Settings; |
14 | 14 | import org.elasticsearch.common.util.concurrent.ThreadContext; |
15 | 15 | import org.elasticsearch.core.Tuple; |
| 16 | +import org.elasticsearch.index.IndexVersion; |
16 | 17 | import org.elasticsearch.indices.EmptySystemIndices; |
17 | 18 | import org.elasticsearch.indices.InvalidIndexNameException; |
| 19 | +import org.elasticsearch.indices.SystemIndexDescriptor; |
| 20 | +import org.elasticsearch.indices.SystemIndices; |
18 | 21 | import org.elasticsearch.test.ESTestCase; |
| 22 | +import org.elasticsearch.xcontent.XContentBuilder; |
19 | 23 |
|
| 24 | +import java.io.IOException; |
| 25 | +import java.io.UncheckedIOException; |
20 | 26 | import java.util.List; |
21 | 27 | import java.util.Set; |
22 | 28 | import java.util.concurrent.TimeUnit; |
23 | 29 | import java.util.function.Supplier; |
24 | 30 |
|
| 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; |
25 | 34 | import static org.hamcrest.Matchers.contains; |
26 | 35 | import static org.hamcrest.Matchers.containsInAnyOrder; |
27 | 36 | import static org.hamcrest.Matchers.either; |
@@ -220,13 +229,80 @@ private boolean isIndexVisible(String index, String selector) { |
220 | 229 | "*", |
221 | 230 | selector, |
222 | 231 | index, |
223 | | - IndicesOptions.strictExpandOpen(), |
| 232 | + IndicesOptions.strictExpandHidden(), |
224 | 233 | metadata, |
225 | 234 | indexNameExpressionResolver, |
226 | 235 | true |
227 | 236 | ); |
228 | 237 | } |
229 | 238 |
|
| 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 | + .setVersionMetaKey("version") |
| 260 | + .setPrimaryIndex(".foo") |
| 261 | + .setIndexPattern(".foo*") |
| 262 | + .setSettings(settings) |
| 263 | + .setMappings(mappings()) |
| 264 | + .setNetNew() |
| 265 | + .build(); |
| 266 | + final SystemIndexDescriptor barDescriptor = SystemIndexDescriptor.builder() |
| 267 | + .setDescription("bar indices") |
| 268 | + .setOrigin("bar origin") |
| 269 | + .setVersionMetaKey("version") |
| 270 | + .setPrimaryIndex(".bar") |
| 271 | + .setIndexPattern(".bar*") |
| 272 | + .setSettings(settings) |
| 273 | + .setMappings(mappings()) |
| 274 | + .setNetNew() |
| 275 | + .build(); |
| 276 | + final SystemIndices systemIndices = new SystemIndices( |
| 277 | + List.of(new SystemIndices.Feature("name", "description", List.of(fooDescriptor, barDescriptor))) |
| 278 | + ); |
| 279 | + |
| 280 | + final ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
| 281 | + threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "false"); |
| 282 | + indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices); |
| 283 | + indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver); |
| 284 | + |
| 285 | + metadata = Metadata.builder().put(foo, true).put(barReindexed, true).put(other, true).build(); |
| 286 | + |
| 287 | + assertThat(isIndexVisible("other", "*"), is(true)); |
| 288 | + assertThat(isIndexVisible(".foo", "*"), is(false)); |
| 289 | + assertThat(isIndexVisible(".bar", "*"), is(false)); |
| 290 | + } |
| 291 | + |
| 292 | + private static XContentBuilder mappings() { |
| 293 | + try (XContentBuilder builder = jsonBuilder()) { |
| 294 | + return builder.startObject() |
| 295 | + .startObject(SINGLE_MAPPING_NAME) |
| 296 | + .startObject("_meta") |
| 297 | + .field(SystemIndexDescriptor.VERSION_META_KEY, 0) |
| 298 | + .endObject() |
| 299 | + .endObject() |
| 300 | + .endObject(); |
| 301 | + } catch (IOException e) { |
| 302 | + throw new UncheckedIOException(e); |
| 303 | + } |
| 304 | + } |
| 305 | + |
230 | 306 | private List<String> resolveAbstractionsSelectorNotAllowed(List<String> expressions) { |
231 | 307 | return resolveAbstractions(expressions, IndicesOptions.strictExpandHiddenNoSelectors(), defaultMask); |
232 | 308 | } |
|
0 commit comments