-
Notifications
You must be signed in to change notification settings - Fork 165
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
[JENKINS-68070] Adapt generic-whitelist to Java standard library changes in Java 15+ #394
Conversation
src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java
Outdated
Show resolved
Hide resolved
mvnd test -Dtest=org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.GenericWhitelistTest still fails on Java 17 with this PR:
|
Could switch script-security-plugin/Jenkinsfile Line 3 in f967fbe
|
As Jesse points out, there are some additional cases like this in
If you want to take care of this in this PR, that is fine with me; otherwise, I can file a new PR to cover those cases. I started down this path already and got the tests passing in Java 17 with this diff: diff --git a/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist b/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist
index edc554a..5504e45 100644
--- a/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist
+++ b/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist
@@ -774,6 +774,14 @@ staticField java.util.concurrent.TimeUnit HOURS
staticField java.util.concurrent.TimeUnit MILLISECONDS
staticField java.util.concurrent.TimeUnit MINUTES
staticField java.util.concurrent.TimeUnit SECONDS
+method java.util.random.RandomGenerator nextBoolean
+method java.util.random.RandomGenerator nextBytes byte[]
+method java.util.random.RandomGenerator nextDouble
+method java.util.random.RandomGenerator nextFloat
+method java.util.random.RandomGenerator nextGaussian
+method java.util.random.RandomGenerator nextInt
+method java.util.random.RandomGenerator nextInt int
+method java.util.random.RandomGenerator nextLong
method java.util.regex.MatchResult end
method java.util.regex.MatchResult end int
method java.util.regex.MatchResult group
diff --git a/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java b/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java
index ef31811..0f07191 100644
--- a/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java
+++ b/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java
@@ -37,6 +37,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Random;
import java.util.Set;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.EnumeratingWhitelist.MethodSignature;
@@ -125,7 +126,24 @@ public class StaticWhitelistTest {
// Overrides CharSequence.isEmpty in Java 15+.
new MethodSignature(String.class, "isEmpty", new Class<?>[0]),
// Does not exist until Java 15.
- new MethodSignature(CharSequence.class, "isEmpty", new Class<?>[0])
+ new MethodSignature(CharSequence.class, "isEmpty", new Class<?>[0]),
+ // Override the corresponding RandomGenerator methods in Java 17+.
+ new MethodSignature(Random.class, "nextBoolean", new Class<?>[0]),
+ new MethodSignature(Random.class, "nextBytes", new Class<?>[] {byte[].class}),
+ new MethodSignature(Random.class, "nextDouble", new Class<?>[0]),
+ new MethodSignature(Random.class, "nextFloat", new Class<?>[0]),
+ new MethodSignature(Random.class, "nextGaussian", new Class<?>[0]),
+ new MethodSignature(Random.class, "nextInt", new Class<?>[0]),
+ new MethodSignature(Random.class, "nextInt", new Class<?>[] {int.class}),
+ new MethodSignature(Random.class, "nextLong", new Class<?>[0]),
+ // Do not exist until Java 17.
+ new MethodSignature("java.util.random.RandomGenerator", "nextBoolean", new String[0]),
+ new MethodSignature("java.util.random.RandomGenerator", "nextBytes", new String[] {"byte[]"}),
+ new MethodSignature("java.util.random.RandomGenerator", "nextDouble", new String[0]),
+ new MethodSignature("java.util.random.RandomGenerator", "nextFloat", new String[0]),
+ new MethodSignature("java.util.random.RandomGenerator", "nextGaussian", new String[0]),
+ new MethodSignature("java.util.random.RandomGenerator", "nextInt", new String[0]),
+ new MethodSignature("java.util.random.RandomGenerator", "nextInt", new String[] {"int"}),
+ new MethodSignature("java.util.random.RandomGenerator", "nextLong", new String[0])
));
@Test public void sanity() throws Exception { However they then started failing on Java 11 because the |
Unfortunately that will not work so long as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
…y exception handling Co-authored-by: Jesse Glick <jglick@cloudbees.com>
@basil Thanks for the diff!
Do you have a stack trace for this? I ran the tests locally on Java 11 and they all passed. |
src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java
Outdated
Show resolved
Hide resolved
I must have been in error, since your branch at commit e137c1f passes |
…ify tests Co-authored-by: Jesse Glick <jglick@cloudbees.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
See JENKINS-68070.
Java 15 added a new
CharSequence.isEmpty
default method. This breaksStaticWhitelistTest
when running against Java 15+ becauseString.isEmpty
becomes an override. It would also causeRejectedAccessException
to be thrown for any sandboxed code that currently callsString.isEmpty
.This PR preemptively adds
CharSequence.isEmpty
togeneric-whitelist
so that everything should regardless of what Java version is being used.I have not actually tested this against Java 15+ myself, so marking the PR as a draft.