use of hudson.model.FreeStyleProject in project promoted-builds-plugin by jenkinsci.
the class ItemPathResolverTest method shouldProperlyHandleEqualNames.
@Test
public void shouldProperlyHandleEqualNames() throws Exception {
final MockFolder folder = rule.createFolder("FOO");
final FreeStyleProject prj = folder.createProject(FreeStyleProject.class, "FOO");
assertsPath("/FOO/FOO", null, prj);
assertsPath("FOO/FOO", null, prj);
// Addressing starts from the folder
assertsPath("FOO", folder, prj);
assertsPath("./FOO", folder, prj);
assertsPath(".", folder, folder);
assertsPath("../FOO", folder, folder);
assertsPath("../FOO/FOO", folder, prj);
// Addressing starts from the parent folder
assertsPath("FOO", prj, prj);
assertsPath("./FOO", prj, prj);
assertsPath(".", prj, folder);
assertsPath("../FOO", prj, folder);
assertsPath("../FOO/FOO", prj, prj);
}
use of hudson.model.FreeStyleProject in project promoted-builds-plugin by jenkinsci.
the class GroovyConditionTest method testMapScript.
@Test
public void testMapScript() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
final JobPropertyImpl property = new JobPropertyImpl(p);
final PromotionProcess promotionProcessEmptyMap = property.addProcess("emptyMap");
promotionProcessEmptyMap.conditions.add(new GroovyCondition(new SecureGroovyScript("[:]", false, null), "", ""));
final PromotionProcess promotionProcessNonEmptyMap = property.addProcess("nonEmptyMap");
promotionProcessNonEmptyMap.conditions.add(new GroovyCondition(new SecureGroovyScript("[foo: 'bar']", false, null), "", ""));
p = j.configRoundtrip(p);
final FreeStyleBuild build = j.buildAndAssertSuccess(p);
Assert.assertNull("Promotion was not expected", promotionProcessEmptyMap.isMet(build));
Assert.assertNotNull("Promotion was expected", promotionProcessNonEmptyMap.isMet(build));
}
use of hudson.model.FreeStyleProject in project promoted-builds-plugin by jenkinsci.
the class GroovyConditionTest method testBooleanScript.
@Test
public void testBooleanScript() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
final JobPropertyImpl property = new JobPropertyImpl(p);
final PromotionProcess promotionProcessTrue = property.addProcess("truePromotion");
promotionProcessTrue.conditions.add(new GroovyCondition(new SecureGroovyScript("true", false, null), "", ""));
final PromotionProcess promotionProcessFalse = property.addProcess("falsePromotion");
promotionProcessFalse.conditions.add(new GroovyCondition(new SecureGroovyScript("false", false, null), "", ""));
p = j.configRoundtrip(p);
final FreeStyleBuild build = j.buildAndAssertSuccess(p);
Assert.assertNotNull("Promotion was expected", promotionProcessTrue.isMet(build));
Assert.assertNull("Promotion was not expected", promotionProcessFalse.isMet(build));
}
use of hudson.model.FreeStyleProject 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.model.FreeStyleProject 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));
}
Aggregations