use of hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval in project promoted-builds-plugin by jenkinsci.
the class ManualConditionTest method testManualPromotionProcessViaWebClient.
public void testManualPromotionProcessViaWebClient() throws Exception {
FreeStyleProject p = createFreeStyleProject();
ExtensionList<Descriptor> list = hudson.getExtensionList(Descriptor.class);
list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
JobPropertyImpl base = new JobPropertyImpl(p);
p.addProperty(base);
PromotionProcess foo = base.addProcess("foo");
ManualCondition condition = new ManualCondition();
condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_1", "bogus_value_1", "Bog parameter"));
condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter"));
foo.conditions.add(condition);
FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
assertNull(b1.getAction(ManualApproval.class));
HtmlPage page = createWebClient().getPage(b1, "promotion");
//Approve Promotion
List<HtmlForm> forms = getFormsByName(page, "approve");
assertFalse(forms.isEmpty());
assertTrue(forms.size() == 1);
HtmlForm form = forms.get(0);
List<HtmlElement> parameters = getFormParameters(form);
assertTrue(parameters.size() == condition.getParameterDefinitions().size());
for (HtmlElement param : parameters) {
HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
v.setAttribute("value", v.getAttribute("value") + "1");
}
submit(forms.get(0));
ManualApproval approval = b1.getAction(ManualApproval.class);
assertNotNull(approval);
SortedMap<Integer, Promotion> builds = foo.getBuildsAsMap();
assertNotNull(builds);
assertTrue(builds.size() == 1);
//Re-Execute approved promotion
page = createWebClient().getPage(b1, "promotion");
forms = getFormsByName(page, "build");
assertFalse(forms.isEmpty());
assertTrue(forms.size() == 1);
form = forms.get(0);
parameters = getFormParameters(form);
assertTrue(parameters.size() == condition.getParameterDefinitions().size());
for (HtmlElement param : parameters) {
HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
v.setAttribute("value", v.getAttribute("value") + "2");
}
submit(form);
builds = foo.getBuildsAsMap();
assertTrue(builds.size() == 2);
List<ManualApproval> actions = b1.getActions(ManualApproval.class);
assertTrue(actions.size() == 1);
PromotedBuildAction buildActions = b1.getAction(PromotedBuildAction.class);
int buildIndex = 1;
String valueSufix = "1";
List<Promotion> promotions = new ArrayList<Promotion>();
promotions.addAll(builds.values());
Collections.reverse(promotions);
for (Promotion build : promotions) {
List<ParameterDefinition> values = build.getParameterDefinitionsWithValue();
assertTrue(values.size() == condition.getParameterDefinitions().size());
for (ParameterDefinition v : values) {
assertTrue(v instanceof StringParameterDefinition);
String pvalue = ((StringParameterDefinition) v).getDefaultValue();
assertTrue(pvalue.endsWith(valueSufix));
}
buildIndex++;
valueSufix += buildIndex;
}
for (Status status : buildActions.getPromotions()) {
assertNotNull(status.getLast() != null);
List<ParameterDefinition> values = status.getLast().getParameterDefinitionsWithValue();
assertTrue(values.size() == condition.getParameterDefinitions().size());
}
}
use of hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval in project promoted-builds-plugin by jenkinsci.
the class ManualConditionTest method testManualPromotionProcessWithInvalidParam.
@Issue("SECURITY-170")
public /**
* Verify that the plugin is tolerant against SECURITY-170 in Manual conditions
*/
void testManualPromotionProcessWithInvalidParam() throws Exception {
FreeStyleProject p = createFreeStyleProject();
ExtensionList<Descriptor> list = hudson.getExtensionList(Descriptor.class);
list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
JobPropertyImpl base = new JobPropertyImpl(p);
p.addProperty(base);
PromotionProcess foo = base.addProcess("foo");
ManualCondition condition = new ManualCondition();
condition.getParameterDefinitions().add(new StringParameterDefinition("FOO", "BAR", "Test parameter"));
foo.conditions.add(condition);
FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
// Promote a build. Also add one invalid parameter
List<ParameterValue> paramValues = condition.createDefaultValues();
paramValues.add(new StringParameterValue("INVALID_PARAM", "hacked!"));
assertBuildStatusSuccess(condition.approve(b1, foo, paramValues));
ManualApproval manualApproval = b1.getAction(ManualApproval.class);
assertNotNull(manualApproval);
List<ParameterValue> parameterValues = manualApproval.badge.getParameterValues();
// Verify that the build succeeds && has no INVALID_PARAM
PromotedBuildAction statuses = b1.getAction(PromotedBuildAction.class);
assertNotNull(statuses);
assertNotNull(statuses.getPromotions());
assertFalse(statuses.getPromotions().isEmpty());
Promotion pb = base.getItem("foo").getBuildByNumber(1);
assertNotNull("INVALID_PARAM should not be injected into the environment", pb.getEnvironment(TaskListener.NULL).get("INVALID_PARAM", null));
}
use of hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval in project promoted-builds-plugin by jenkinsci.
the class PromotionTargetActionTest method test1.
/**
* When a project is created, built, and renamed, then the old build is created,
* that results in NPE.
*/
public void test1() throws Exception {
FreeStyleProject up = createFreeStyleProject("up");
up.setCustomWorkspace(createTmpDir().getPath());
// promote if the downstream passes
JobPropertyImpl promotion = new JobPropertyImpl(up);
up.addProperty(promotion);
PromotionProcess proc = promotion.addProcess("promo");
proc.conditions.add(new ManualCondition());
FreeStyleBuild b = assertBuildStatusSuccess(up.scheduleBuild2(0));
b.addAction(new ManualApproval(proc.getName(), Collections.<ParameterValue>emptyList()));
b.save();
// check for promotion
Promotion p = assertBuildStatusSuccess(proc.considerPromotion2(b));
up.renameTo("up2");
assertSame(b, p.getTarget());
}
Aggregations