Skip to content

Commit 92bd724

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 cfc003d commit 92bd724

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,11 @@ public boolean implies(ProtectionDomain domain, Permission permission) {
177177
private static void addClassCodebase(Map<String, URL> codebases, String name, String classname) {
178178
try {
179179
Class<?> clazz = BootstrapForTesting.class.getClassLoader().loadClass(classname);
180-
if (codebases.put(name, clazz.getProtectionDomain().getCodeSource().getLocation()) != null) {
181-
throw new IllegalStateException("Already added " + name + " codebase for testing");
180+
URL location = clazz.getProtectionDomain().getCodeSource().getLocation();
181+
if (location.toString().endsWith(".jar") == false) {
182+
if (codebases.put(name, location) != null) {
183+
throw new IllegalStateException("Already added " + name + " codebase for testing");
184+
}
182185
}
183186
} catch (ClassNotFoundException e) {
184187
// no class, fall through to not add. this can happen for any tests that do not include

0 commit comments

Comments
 (0)