Skip to content

Commit

Permalink
Support Java 17 in Security637Test (#6384)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Mar 17, 2022
1 parent 6cf8486 commit fff3bd3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/src/test/java/jenkins/security/Security637Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeNoException;

import hudson.EnvVars;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.FreeStyleProject;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import hudson.slaves.DumbSlave;
import hudson.util.VersionNumber;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL;
Expand All @@ -61,7 +64,10 @@ public class Security637Test {
@Issue("SECURITY-637")
public void urlSafeDeserialization_handler_inSameJVMRemotingContext() throws Throwable {
sessions.then(j -> {
DumbSlave slave = j.createOnlineSlave();
EnvVars envVars = new VersionNumber(System.getProperty("java.specification.version")).isOlderThan(new VersionNumber("9"))
? null
: new EnvVars("JAVA_TOOL_OPTIONS", "--add-opens=java.base/java.net=ALL-UNNAMED");
DumbSlave slave = j.createOnlineSlave(null, envVars);
String unsafeHandlerClassName = slave.getChannel().call(new URLHandlerCallable(new URL("https://www.google.com/")));
assertThat(unsafeHandlerClassName, containsString("SafeURLStreamHandler"));

Expand Down Expand Up @@ -187,7 +193,11 @@ public void urlSafeDeserialization_inXStreamContext() throws Throwable {
assertNotNull(project);

Field handlerField = URL.class.getDeclaredField("handler");
handlerField.setAccessible(true);
try {
handlerField.setAccessible(true);
} catch (RuntimeException e) {
assumeNoException(e);
}

URLJobProperty urlJobProperty = project.getProperty(URLJobProperty.class);
for (URL url : urlJobProperty.urlSet) {
Expand Down

0 comments on commit fff3bd3

Please sign in to comment.