10
10
package org .elasticsearch .validation ;
11
11
12
12
import org .elasticsearch .cluster .service .ClusterService ;
13
+ import org .elasticsearch .common .Strings ;
13
14
import org .elasticsearch .common .settings .ClusterSettings ;
14
- import org .elasticsearch .common .settings .Setting ;
15
15
import org .elasticsearch .common .settings .Settings ;
16
16
import org .elasticsearch .common .util .concurrent .ThreadContext ;
17
17
import org .elasticsearch .common .util .set .Sets ;
18
18
import org .elasticsearch .test .ESTestCase ;
19
19
import org .elasticsearch .threadpool .ThreadPool ;
20
20
import org .junit .BeforeClass ;
21
21
22
- import java .util .HashSet ;
22
+ import java .util .ArrayList ;
23
+ import java .util .List ;
23
24
import java .util .Set ;
24
25
25
26
import static org .mockito .Mockito .mock ;
28
29
public class DotPrefixValidatorTests extends ESTestCase {
29
30
private final OperatorValidator <?> opV = new OperatorValidator <>();
30
31
private final NonOperatorValidator <?> nonOpV = new NonOperatorValidator <>();
31
- private static final Set <Setting <?>> settings ;
32
32
33
33
private static ClusterService clusterService ;
34
- private static ClusterSettings clusterSettings ;
35
-
36
- static {
37
- Set <Setting <?>> cSettings = new HashSet <>(ClusterSettings .BUILT_IN_CLUSTER_SETTINGS );
38
- cSettings .add (DotPrefixValidator .VALIDATE_DOT_PREFIXES );
39
- settings = cSettings ;
40
- }
41
34
42
35
@ BeforeClass
43
36
public static void beforeClass () {
37
+ List <String > allowed = new ArrayList <>(DotPrefixValidator .IGNORED_INDEX_PATTERNS_SETTING .getDefault (Settings .EMPTY ));
38
+ // Add a new allowed pattern for testing
39
+ allowed .add ("\\ .potato\\ d+" );
40
+ Settings settings = Settings .builder ()
41
+ .put (DotPrefixValidator .IGNORED_INDEX_PATTERNS_SETTING .getKey (), Strings .collectionToCommaDelimitedString (allowed ))
42
+ .build ();
44
43
clusterService = mock (ClusterService .class );
45
- clusterSettings = new ClusterSettings (Settings .EMPTY , Sets .newHashSet (DotPrefixValidator .VALIDATE_DOT_PREFIXES ));
44
+ ClusterSettings clusterSettings = new ClusterSettings (
45
+ settings ,
46
+ Sets .newHashSet (DotPrefixValidator .VALIDATE_DOT_PREFIXES , DotPrefixValidator .IGNORED_INDEX_PATTERNS_SETTING )
47
+ );
46
48
when (clusterService .getClusterSettings ()).thenReturn (clusterSettings );
47
- when (clusterService .getSettings ()).thenReturn (Settings . EMPTY );
49
+ when (clusterService .getSettings ()).thenReturn (settings );
48
50
when (clusterService .threadPool ()).thenReturn (mock (ThreadPool .class ));
49
51
}
50
52
@@ -74,6 +76,13 @@ public void testValidation() {
74
76
nonOpV .validateIndices (Set .of (".slo-observability.summary-v2.3" ));
75
77
nonOpV .validateIndices (Set .of (".slo-observability.summary-v2.3-2024-01-01" ));
76
78
nonOpV .validateIndices (Set .of ("<.slo-observability.summary-v3.3.{2024-10-16||/M{yyyy-MM-dd|UTC}}>" ));
79
+ nonOpV .validateIndices (Set .of (".entities.v1.latest.builtin_services_from_ecs_data" ));
80
+ nonOpV .validateIndices (Set .of (".entities.v92.latest.eggplant.potato" ));
81
+ nonOpV .validateIndices (Set .of ("<.entities.v12.latest.eggplant-{M{yyyy-MM-dd|UTC}}>" ));
82
+
83
+ // Test pattern added to the settings
84
+ nonOpV .validateIndices (Set .of (".potato5" ));
85
+ nonOpV .validateIndices (Set .of ("<.potato5>" ));
77
86
}
78
87
79
88
private void assertFails (Set <String > indices ) {
@@ -85,7 +94,7 @@ private void assertFails(Set<String> indices) {
85
94
);
86
95
}
87
96
88
- private class NonOperatorValidator <R > extends DotPrefixValidator <R > {
97
+ private static class NonOperatorValidator <R > extends DotPrefixValidator <R > {
89
98
90
99
private NonOperatorValidator () {
91
100
super (new ThreadContext (Settings .EMPTY ), clusterService );
@@ -107,7 +116,7 @@ boolean isInternalRequest() {
107
116
}
108
117
}
109
118
110
- private class OperatorValidator <R > extends NonOperatorValidator <R > {
119
+ private static class OperatorValidator <R > extends NonOperatorValidator <R > {
111
120
@ Override
112
121
boolean isInternalRequest () {
113
122
return true ;
0 commit comments