12
12
import org .elasticsearch .bootstrap .TestBuildInfo ;
13
13
import org .elasticsearch .bootstrap .TestBuildInfoParser ;
14
14
import org .elasticsearch .bootstrap .TestScopeResolver ;
15
+ import org .elasticsearch .core .Booleans ;
15
16
import org .elasticsearch .core .Nullable ;
17
+ import org .elasticsearch .core .PathUtils ;
16
18
import org .elasticsearch .core .Strings ;
17
19
import org .elasticsearch .core .SuppressForbidden ;
18
20
import org .elasticsearch .entitlement .initialization .EntitlementInitialization ;
25
27
import org .elasticsearch .logging .Logger ;
26
28
import org .elasticsearch .plugins .PluginDescriptor ;
27
29
28
- import java .io .File ;
29
30
import java .io .IOException ;
30
31
import java .io .InputStream ;
31
32
import java .net .URL ;
@@ -74,7 +75,7 @@ private static <T> List<T> zeroOrOne(T item) {
74
75
}
75
76
76
77
public static boolean isEnabledForTest () {
77
- return Boolean . getBoolean ("es.entitlement.enableForTests" );
78
+ return Booleans . parseBoolean ("es.entitlement.enableForTests" );
78
79
}
79
80
80
81
public static void setActive (boolean newValue ) {
@@ -107,17 +108,20 @@ private static TestPolicyManager createPolicyManager(PathLookup pathLookup) thro
107
108
.toList ();
108
109
Map <String , Policy > pluginPolicies = parsePluginsPolicies (pluginsData );
109
110
111
+ String separator = System .getProperty ("path.separator" );
112
+
110
113
// In productions, plugins would have access to their respective bundle directories,
111
114
// and so they'd be able to read from their jars. In testing, we approximate this
112
115
// by considering the entire classpath to be "source paths" of all plugins. This
113
116
// also has the effect of granting read access to everything on the test-only classpath,
114
117
// which is fine, because any entitlement errors there could only be false positives.
115
118
String classPathProperty = System .getProperty ("java.class.path" );
119
+
116
120
Set <Path > classPathEntries ;
117
121
if (classPathProperty == null ) {
118
122
classPathEntries = Set .of ();
119
123
} else {
120
- classPathEntries = Arrays .stream (classPathProperty .split (File . pathSeparator )).map (Path :: of ).collect (toCollection (TreeSet ::new ));
124
+ classPathEntries = Arrays .stream (classPathProperty .split (separator )).map (PathUtils :: get ).collect (toCollection (TreeSet ::new ));
121
125
}
122
126
Map <String , Collection <Path >> pluginSourcePaths = pluginNames .stream ().collect (toMap (n -> n , n -> classPathEntries ));
123
127
@@ -128,7 +132,7 @@ private static TestPolicyManager createPolicyManager(PathLookup pathLookup) thro
128
132
if (testOnlyPathString == null ) {
129
133
testOnlyClassPath = Set .of ();
130
134
} else {
131
- testOnlyClassPath = Arrays .stream (testOnlyPathString .split (File . pathSeparator )).collect (toCollection (TreeSet ::new ));
135
+ testOnlyClassPath = Arrays .stream (testOnlyPathString .split (separator )).collect (toCollection (TreeSet ::new ));
132
136
}
133
137
134
138
return new TestPolicyManager (
0 commit comments