Skip to content

Commit

Permalink
Making it possible to use Groovy functions with def syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed May 1, 2014
1 parent 6b2c8b6 commit 90057e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.EnumeratingWhitelist;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist;
import org.kohsuke.groovy.sandbox.GroovyInterceptor;
import org.kohsuke.groovy.sandbox.impl.Checker;

@SuppressWarnings("rawtypes")
final class SandboxInterceptor extends GroovyInterceptor {
Expand Down Expand Up @@ -73,6 +74,10 @@ final class SandboxInterceptor extends GroovyInterceptor {
@Override public Object onStaticCall(GroovyInterceptor.Invoker invoker, Class receiver, String method, Object... args) throws Throwable {
Method m = GroovyCallSiteSelector.staticMethod(receiver, method, args);
if (m == null) {
if (receiver == Checker.class && method.startsWith("checked")) {
// TODO cf. defSyntax; this seems like a bug in the sandbox
return super.onStaticCall(invoker, receiver, method, args);
}
throw new RejectedAccessException("unclassified staticMethod " + EnumeratingWhitelist.getName(receiver) + " " + method + printArgumentTypes(args));
} else if (whitelist.permitsStaticMethod(m, args)) {
return super.onStaticCall(invoker, receiver, method, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,16 @@ public static final class Special {
}
}

@Ignore("TODO fails with: unclassified staticMethod org.kohsuke.groovy.sandbox.impl.Checker checkedCall java.lang.Class java.lang.Boolean java.lang.Boolean java.lang.String java.lang.Object[]")
@Test public void defSyntax() throws Exception {
String clazz = Unsafe.class.getName();
Whitelist w = new ProxyWhitelist(new AnnotatedWhitelist(), /* for some reason def syntax triggers this */new StaticWhitelist(Collections.singleton("method java.util.Collection toArray")));
assertEvaluate(w, "ok", "m(); def m() {" + clazz + ".ok()}");
assertEvaluate(w, "ok", "m(); def static m() {" + clazz + ".ok()}");
try {
assertEvaluate(w, "should be rejected", "m(); def m() {" + clazz + ".explode()}");
} catch (RejectedAccessException x) {
assertEquals("staticMethod " + clazz + " explode", x.getSignature());
}
}

public static final class Unsafe {
Expand Down

0 comments on commit 90057e9

Please sign in to comment.