Skip to content

Commit 677d99d

Browse files
committed
Add the classpath to the source path list for every plugin
1 parent fc49559 commit 677d99d

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

test/framework/src/main/java/org/elasticsearch/entitlement/bootstrap/TestEntitlementBootstrap.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
import java.util.Map;
3838
import java.util.Set;
3939
import java.util.TreeSet;
40-
import java.util.stream.Collectors;
4140

41+
import static java.util.stream.Collectors.toCollection;
42+
import static java.util.stream.Collectors.toMap;
4243
import static org.elasticsearch.entitlement.runtime.policy.PathLookup.BaseDir.CONFIG;
4344
import static org.elasticsearch.entitlement.runtime.policy.PathLookup.BaseDir.TEMP;
4445

@@ -56,7 +57,7 @@ public static void bootstrap(@Nullable Path tempDir, @Nullable Path configDir) t
5657
return;
5758
}
5859
TestPathLookup pathLookup = new TestPathLookup(Map.of(TEMP, zeroOrOne(tempDir), CONFIG, zeroOrOne(configDir)));
59-
policyManager = createPolicyManager(pathLookup);
60+
policyManager = createPolicyManager(tempDir, configDir);
6061
EntitlementInitialization.initializeArgs = new EntitlementInitialization.InitializeArgs(pathLookup, Set.of(), policyManager);
6162
logger.debug("Loading entitlement agent");
6263
EntitlementBootstrap.loadAgent(EntitlementBootstrap.findAgentJar(), EntitlementInitialization.class.getName());
@@ -88,7 +89,7 @@ public static void reset() {
8889
}
8990
}
9091

91-
private static TestPolicyManager createPolicyManager(PathLookup pathLookup) throws IOException {
92+
private static TestPolicyManager createPolicyManager(Path tempDir, Path configDir) throws IOException {
9293
var pluginsTestBuildInfo = TestBuildInfoParser.parseAllPluginTestBuildInfo();
9394
var serverTestBuildInfo = TestBuildInfoParser.parseServerTestBuildInfo();
9495
var scopeResolver = TestScopeResolver.createScopeResolver(serverTestBuildInfo, pluginsTestBuildInfo);
@@ -99,16 +100,30 @@ private static TestPolicyManager createPolicyManager(PathLookup pathLookup) thro
99100
.map(descriptor -> new TestPluginData(descriptor.getName(), descriptor.isModular(), false))
100101
.toList();
101102
Map<String, Policy> pluginPolicies = parsePluginsPolicies(pluginsData);
102-
Map<String, Collection<Path>> pluginSourcePaths = Map.of();
103103

104+
// In productions, plugins would have access to their respective bundle directories,
105+
// and so they'd be able to read from their jars. In testing, we approximate this
106+
// by considering the entire classpath to be "source paths" of all plugins. This
107+
// also has the effect of granting read access to everything on the test-only classpath,
108+
// which is fine, because any entitlement errors there could only be false positives.
109+
String classPathProperty = System.getProperty("java.class.path");
110+
Set<Path> classPathEntries;
111+
if (classPathProperty == null) {
112+
classPathEntries = Set.of();
113+
} else {
114+
classPathEntries = Arrays.stream(classPathProperty.split(":")).map(Path::of).collect(toCollection(TreeSet::new));
115+
}
116+
Map<String, Collection<Path>> pluginSourcePaths = pluginNames.stream().collect(toMap(n -> n, n -> classPathEntries));
117+
118+
PathLookup pathLookup = new TestPathLookup(Map.of(TEMP, zeroOrOne(tempDir), CONFIG, zeroOrOne(configDir)));
104119
FilesEntitlementsValidation.validate(pluginPolicies, pathLookup);
105120

106121
String testOnlyPathProperty = System.getProperty("es.entitlement.testOnlyPath");
107122
Set<String> testOnlyClassPath;
108123
if (testOnlyPathProperty == null) {
109124
testOnlyClassPath = Set.of();
110125
} else {
111-
testOnlyClassPath = Arrays.stream(testOnlyPathProperty.split(":")).collect(Collectors.toCollection(TreeSet::new));
126+
testOnlyClassPath = Arrays.stream(testOnlyPathProperty.split(":")).collect(toCollection(TreeSet::new));
112127
}
113128

114129
return new TestPolicyManager(

0 commit comments

Comments
 (0)