Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to disable jarhell check for tests on 2.2 with test.jarhell.check #16174

Merged
merged 1 commit into from
Jan 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ public class BootstrapForTesting {
// initialize probes
Bootstrap.initializeProbes();

// check for jar hell
try {
JarHell.checkJarHell();
} catch (Exception e) {
throw new RuntimeException("found jar hell in test classpath", e);
if (systemPropertyAsBoolean("tests.jarhell.check", true)) {
// check for jar hell
try {
JarHell.checkJarHell();
} catch (Exception e) {
throw new RuntimeException("found jar hell in test classpath", e);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log that jar hell has been deactivated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no logger here anyway... hot topic :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha! I was pretty sure you were going to answer that :)

}

// install security manager if requested
Expand Down Expand Up @@ -130,15 +132,15 @@ 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
perms.add(new SocketPermission("localhost:0", "listen,resolve"));
// ... 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);
Expand Down Expand Up @@ -172,7 +174,7 @@ public boolean implies(ProtectionDomain domain, Permission permission) {
}
}

/**
/**
* 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.
*/
Expand All @@ -182,7 +184,7 @@ static Map<String,Policy> getPluginPermissions() throws Exception {
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(
Expand All @@ -198,13 +200,13 @@ static Map<String,Policy> getPluginPermissions() throws Exception {
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) {
Expand Down