diff options
Diffstat (limited to 'test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java')
-rw-r--r-- | test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java b/test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java index 6878408379..b2ce5ebd86 100644 --- a/test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java +++ b/test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java @@ -20,13 +20,8 @@ package org.elasticsearch.bootstrap; import com.carrotsearch.randomizedtesting.RandomizedRunner; - import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.util.TestSecurityManager; import org.elasticsearch.SecureSM; -import org.elasticsearch.bootstrap.Bootstrap; -import org.elasticsearch.bootstrap.ESPolicy; -import org.elasticsearch.bootstrap.Security; import org.elasticsearch.common.Strings; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.io.PathUtils; @@ -55,16 +50,16 @@ import java.util.Set; import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean; -/** +/** * Initializes natives and installs test security manager * (init'd early by base classes to ensure it happens regardless of which - * test case happens to be first, test ordering, etc). + * test case happens to be first, test ordering, etc). * <p> * The idea is to mimic as much as possible what happens with ES in production * mode (e.g. assign permissions and install security manager the same way) */ public class BootstrapForTesting { - + // TODO: can we share more code with the non-test side here // without making things complex??? @@ -83,10 +78,10 @@ public class BootstrapForTesting { // initialize probes Bootstrap.initializeProbes(); - + // initialize sysprops BootstrapInfo.getSystemProperties(); - + // check for jar hell try { JarHell.checkJarHell(); @@ -130,7 +125,7 @@ public class BootstrapForTesting { if (System.getProperty("tests.maven") == null) { perms.add(new RuntimePermission("setIO")); } - + // add bind permissions for testing // ephemeral ports (note, on java 7 before update 51, this is a different permission) // this should really be the only one allowed for tests, otherwise they have race conditions @@ -138,7 +133,7 @@ public class BootstrapForTesting { // ... but tests are messy. like file permissions, just let them live in a fantasy for now. // TODO: cut over all tests to bind to ephemeral ports perms.add(new SocketPermission("localhost:1024-", "listen,resolve")); - + // read test-framework permissions final Policy testFramework = Security.readPolicy(Bootstrap.class.getResource("test-framework.policy"), JarHell.parseClassPath()); final Policy esPolicy = new ESPolicy(perms, getPluginPermissions(), true); @@ -172,7 +167,7 @@ public class BootstrapForTesting { } } - /** + /** * we dont know which codesources belong to which plugin, so just remove the permission from key codebases * like core, test-framework, etc. this way tests fail if accesscontroller blocks are missing. */ @@ -182,7 +177,7 @@ public class BootstrapForTesting { if (pluginPolicies.isEmpty()) { return Collections.emptyMap(); } - + // compute classpath minus obvious places, all other jars will get the permission. Set<URL> codebases = new HashSet<>(Arrays.asList(parseClassPathWithSymlinks())); Set<URL> excluded = new HashSet<>(Arrays.asList( @@ -198,13 +193,13 @@ public class BootstrapForTesting { Assert.class.getProtectionDomain().getCodeSource().getLocation() )); codebases.removeAll(excluded); - + // parse each policy file, with codebase substitution from the classpath final List<Policy> policies = new ArrayList<>(); for (URL policyFile : pluginPolicies) { policies.add(Security.readPolicy(policyFile, codebases.toArray(new URL[codebases.size()]))); } - + // consult each policy file for those codebases Map<String,Policy> map = new HashMap<>(); for (URL url : codebases) { |