Skip to content
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-61438] Demonstration of IAE from Stapler #185

Merged
merged 5 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
buildPlugin(configurations: [
[ platform: "linux", jdk: "8", jenkins: null ],
[ platform: "linux", jdk: "11", jenkins: "2.249" ],
[ platform: "windows", jdk: "8", jenkins: "2.235.3", javaLevel: "8" ],
[ platform: "linux", jdk: "11", jenkins: "2.235.3", javaLevel: "8" ]
])
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,35 @@
package jenkins.branch;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.ChoiceParameterDefinition;
import hudson.model.ItemGroup;
import hudson.model.Job;
import hudson.model.ParameterDefinition;
import hudson.model.StringParameterDefinition;
import hudson.model.TopLevelItem;
import hudson.util.VersionNumber;
import integration.harness.BasicDummyStepBranchProperty;
import integration.harness.BasicMultiBranchProject;
import java.util.Arrays;
import java.util.Collections;

import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import jenkins.scm.impl.mock.MockSCMController;
import jenkins.scm.impl.mock.MockSCMDiscoverBranches;
import jenkins.scm.impl.mock.MockSCMSource;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.*;
import static org.junit.Assume.assumeThat;

public class ParameterDefinitionBranchPropertyTest {
/**
Expand Down Expand Up @@ -116,6 +118,39 @@ public void jobDecorator_Job_implementing_ParameterizedJob() throws Exception {
assertThat(new ParameterDefinitionBranchPropertyImpl().jobDecorator((Class) ParamJob.class), notNullValue());
}

@Issue("JENKINS-61438")
@Test
public void choiceParameterIssue() throws Exception {
assumeThat(Jenkins.getVersion(), greaterThanOrEqualTo(new VersionNumber("2.242")));
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches()));
ParameterDefinitionBranchPropertyImpl instance = new ParameterDefinitionBranchPropertyImpl();
instance.setParameterDefinitions(Collections.<ParameterDefinition>singletonList(
new ChoiceParameterDefinition("CHOOSE", new String[] { "a", "b" }, "choose one")
));
source.setStrategy(new DefaultBranchPropertyStrategy(new BranchProperty[]{
instance, new BasicDummyStepBranchProperty()
}));
prj.getSourcesList().add(source);
r.configRoundtrip(prj);
jglick marked this conversation as resolved.
Show resolved Hide resolved
assertThat(prj.getSources().get(0).getStrategy(), instanceOf(DefaultBranchPropertyStrategy.class));
DefaultBranchPropertyStrategy strategy =
(DefaultBranchPropertyStrategy) prj.getSources().get(0).getStrategy();
assertThat(strategy.getProps().get(0), instanceOf(ParameterDefinitionBranchPropertyImpl.class));
ParameterDefinitionBranchPropertyImpl property = (ParameterDefinitionBranchPropertyImpl) strategy.getProps().get(0);
assertThat(property.getParameterDefinitions(), contains(
allOf(
instanceOf(ChoiceParameterDefinition.class),
hasProperty("name", is("CHOOSE")),
hasProperty("choices", is(Arrays.asList("a", "b"))),
hasProperty("description", is("choose one"))
)
));
}
}
@Test
public void configRoundtrip() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
Expand Down