Skip to content

Commit

Permalink
[FIXED JENKINS-50470] Treat someList.someField as spread.
Browse files Browse the repository at this point in the history
See upstream PR at
jenkinsci/groovy-sandbox#46, but the gist is
that Groovy's normal behavior for this is to treat it the same as we
do spread cases - iterate over the list to get the value from each
object in the list and return the resulting list.
  • Loading branch information
abayer committed Mar 29, 2018
1 parent 858f1bf commit f7601ab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>groovy-sandbox</artifactId>
<version>1.18</version>
<version>1.19-20180329.140543-1</version> <!-- TODO: https://github.com/jenkinsci/groovy-sandbox/pull/46 -->
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
Expand Down
Expand Up @@ -1044,4 +1044,40 @@ public void checkedCastWhenAssignable() throws Exception {
"one",
nacl + " foo = new " + nacl + "(true, false); return foo.join('')");

}}
}

public static class SimpleNamedBean {
private String name;

@Whitelisted
public SimpleNamedBean(String n) {
this.name = n;
}

@Whitelisted
public String getName() {
return name;
}

// This is not whitelisted for test purposes to be sure we still do checks.
public String getOther() {
return name;
}
}

@Issue("JENKINS-50470")
@Test
public void checkedGetPropertyOnCollection() throws Exception {
String snb = SimpleNamedBean.class.getName();

// Before JENKINS-50470 fix, this would error out on "unclassified field java.util.ArrayList name"
assertEvaluate(new AnnotatedWhitelist(), Arrays.asList("a", "b", "c"),
"def l = [new " + snb + "('a'), new " + snb +"('b'), new " + snb + "('c')]\n" +
"return l.name\n");

// We should still be calling checkedGetProperty properly for the objects within the collection.
assertRejected(new AnnotatedWhitelist(), "method org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptorTest$SimpleNamedBean getOther",
"def l = [new " + snb + "('a'), new " + snb +"('b'), new " + snb + "('c')]\n" +
"return l.other\n");
}
}

0 comments on commit f7601ab

Please sign in to comment.