Skip to content

Commit 561005f

Browse files
mattweberrjernst
authored andcommitted
Fix classpath security checks for external tests. (#33066)
This commit checks that when we manually add a class to the codebase map, that it does in-fact not exist on the classpath in a jar. This will only be true if we are using the test framework externally such as when a user develops a plugin.
1 parent a29af74 commit 561005f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,12 @@ public boolean implies(ProtectionDomain domain, Permission permission) {
173173
/** Add the codebase url of the given classname to the codebases map, if the class exists. */
174174
private static void addClassCodebase(Map<String, URL> codebases, String name, String classname) {
175175
try {
176-
Class clazz = BootstrapForTesting.class.getClassLoader().loadClass(classname);
177-
if (codebases.put(name, clazz.getProtectionDomain().getCodeSource().getLocation()) != null) {
178-
throw new IllegalStateException("Already added " + name + " codebase for testing");
176+
Class<?> clazz = BootstrapForTesting.class.getClassLoader().loadClass(classname);
177+
URL location = clazz.getProtectionDomain().getCodeSource().getLocation();
178+
if (location.toString().endsWith(".jar") == false) {
179+
if (codebases.put(name, location) != null) {
180+
throw new IllegalStateException("Already added " + name + " codebase for testing");
181+
}
179182
}
180183
} catch (ClassNotFoundException e) {
181184
// no class, fall through to not add. this can happen for any tests that do not include

0 commit comments

Comments
 (0)