Skip to content
Permalink
Browse files

[JENKINS-25119] Added a test for additional methods in the Groovy env…

…ironment.
  • Loading branch information
ikedam committed Feb 1, 2015
1 parent 1261315 commit d90c1f5c5c4523157f7c42dd0bd410376ed5a78b
@@ -388,6 +388,16 @@ private Unsafe() {}
assertEvaluate(new GenericWhitelist(), Collections.singletonMap("part0", "one\ntwo"), "def list = [['one', 'two']]; def map = [:]; for (int i = 0; i < list.size(); i++) {map[\"part${i}\"] = list.get(i).join(\"\\n\")}; map");
}

@Issue("JENKINS-25119")
@Test public void groovyAdditionalMethod() throws Exception {
try {
assertEvaluate(new ProxyWhitelist(), "should fail", "'123'.toInteger();");
} catch (RejectedAccessException x) {
assertNotNull(x.toString(), x.getSignature());
}
assertEvaluate(new StaticWhitelist("staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods toInteger java.lang.String"), new Integer(123), "'123'.toInteger();");
}

private static void assertEvaluate(Whitelist whitelist, final Object expected, final String script) {
final GroovyShell shell = new GroovyShell(GroovySandbox.createSecureCompilerConfiguration());
Object actual = GroovySandbox.run(shell.parse(script), whitelist);

0 comments on commit d90c1f5

Please sign in to comment.
You can’t perform that action at this time.