Skip to content

Commit

Permalink
Merge pull request #286 from jglick/fauxDescribable-JENKINS-54186
Browse files Browse the repository at this point in the history
[JENKINS-54186] ArgumentsActionImpl robustness against weird Describable
  • Loading branch information
dwnusbaum committed Apr 26, 2019
2 parents 62fb226 + 9edfcf6 commit fb55655
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,14 @@ Object sanitizeObjectAndRecordMutation(@CheckForNull Object o, @CheckForNull Env
} else if (tempVal instanceof UninstantiatedDescribable) {
tempVal = ((UninstantiatedDescribable)tempVal).toMap();
} else if (tempVal instanceof Describable) { // Raw Describables may not be safe to store, so we should explode it
m = DescribableModel.of(tempVal.getClass());
tempVal = m.uninstantiate2(o).toMap();
try {
m = DescribableModel.of(tempVal.getClass());
tempVal = m.uninstantiate2(o).toMap();
} catch (RuntimeException x) { // usually NoStaplerConstructorException, but could also be misc. UnsupportedOperationException
LOGGER.log(Level.FINE, "failed to store " + tempVal, x);
this.isUnmodifiedBySanitization = false;
return NotStoredReason.UNSERIALIZABLE;
}
}

if (isOversized(tempVal)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable;
import org.jenkinsci.plugins.workflow.testMetaStep.Curve;
import org.jvnet.hudson.test.LoggerRule;

/**
* Tests the input sanitization and step persistence here
Expand All @@ -72,6 +75,8 @@ public class ArgumentsActionImplTest {
@Rule
public JenkinsRule r = new JenkinsRule();

@Rule public LoggerRule logging = new LoggerRule();

/** Helper function to test direct file deserialization for an execution */
private void testDeserialize(FlowExecution execution) throws Exception {
if (!(execution instanceof CpsFlowExecution) || !(((CpsFlowExecution)execution).getStorage() instanceof SimpleXStreamFlowNodeStorage)) {
Expand Down Expand Up @@ -328,6 +333,18 @@ public boolean equals(Object ob) {
}
}

@Issue("JENKINS-54186")
@Test public void fauxDescribable() throws Exception {
logging.record(ArgumentsActionImpl.class, Level.FINE);
ArgumentsActionImpl impl = new ArgumentsActionImpl(Collections.singletonMap("curve", new Fractal()));
Map<String, Object> args = impl.getArguments();
Assert.assertThat(args, IsMapContaining.hasEntry("curve", ArgumentsAction.NotStoredReason.UNSERIALIZABLE));
}
public static final class Fractal extends Curve {
@Override public String getDescription() {
return "shape way too complex to describe";
}
}

@Test
@Issue("JENKINS-54032")
Expand Down

0 comments on commit fb55655

Please sign in to comment.