use of org.jenkinsci.test.acceptance.po.FreeStyleJob in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method createJobAndBuild.
/**
* This method creates a new job and builds it.
* @return the newly created job
*/
private Job createJobAndBuild() {
FreeStyleJob job = jenkins.jobs.create(FreeStyleJob.class);
job.scheduleBuild();
return job;
}
use of org.jenkinsci.test.acceptance.po.FreeStyleJob in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_use_grooy_sandbox_no_whitelisted_content.
/**
* Verifies that if script security for Job DSL scripts is enabled,
* scripts with not whitelisted content saved by non administrators
* wont be executed even it should run in a Groovy sandbox.
* Administrators can approve this content in the 'Script Approval' of the
* 'Manage Jenkins' area. Approved scripts can be executed.
*/
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm", "authorize-project" })
public void should_use_grooy_sandbox_no_whitelisted_content() {
GlobalSecurityConfig sc = setUpSecurity();
runBuildAsUserWhoTriggered(sc);
jenkins.login().doLogin(USER);
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("def jobNames = [\"First_Job\", \"Second_Job\"].toArray()\n" + "\n" + "for(name in jobNames) {\n" + " job(name)\n" + "}");
jobDsl.setUseSandbox(true);
seedJob.save();
// Build should fail because script contains not whitelisted content.
// It don't matter that the script runs in sandbox.
Build build = seedJob.scheduleBuild().shouldFail();
assertThat(build.getConsole(), containsString("Scripts not permitted to use method java.util.Collection toArray"));
jenkins.logout();
jenkins.login().doLogin(ADMIN);
ScriptApproval sa = new ScriptApproval(jenkins);
sa.open();
sa.findSignature("toArray").approve();
jenkins.logout();
jenkins.login().doLogin(USER);
// Build should succeed because the not whitelisted content was approved.
seedJob.scheduleBuild().shouldSucceed();
}
use of org.jenkinsci.test.acceptance.po.FreeStyleJob in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method runSeedJobInFolder.
/**
* Creates and executes a seed job in a folder. The seed job generates a new job
* with the specified lookup strategy.
* @param jobName The name the job to generate.
* @param strategy The context to use for relative job names.
* @return The folder in which the seed job is located.
*/
private Folder runSeedJobInFolder(String jobName, JobDslLookupStrategy strategy) {
final Folder folder = jenkins.jobs.create(Folder.class, "Folder");
FreeStyleJob seedJob = folder.getJobs().create(FreeStyleJob.class, "Seed");
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("job('" + jobName + "')");
jobDsl.setLookupStrategy(strategy);
seedJob.save();
seedJob.scheduleBuild().shouldSucceed();
return folder;
}
use of org.jenkinsci.test.acceptance.po.FreeStyleJob in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_delete_removed_views.
/**
* Verifies whether a previously generated view will be deleted if it
* is not referenced anymore.
*/
@Test
public void should_delete_removed_views() {
FreeStyleJob seedJob = executeRemovedViewAction(JobDslRemovedViewAction.DELETE);
Build build = seedJob.scheduleBuild().shouldSucceed();
Pattern expected = Pattern.compile("Unreferenced views:(\\s*)GeneratedView[{]name='Old_View'}(\\s*)Removed views:(\\s*)GeneratedView[{]name='Old_View'}");
assertThat(build.getConsole(), containsRegexp(expected));
ListView oldView = getView("Old_View");
assertThat(oldView, pageObjectDoesNotExist());
}
use of org.jenkinsci.test.acceptance.po.FreeStyleJob in project acceptance-test-harness by jenkinsci.
the class DashboardViewPluginTest method buildStatisticsPortlet_totalBuilds.
@Test
public void buildStatisticsPortlet_totalBuilds() {
DashboardView v = createDashboardView();
BuildStatisticsPortlet stats = v.addBottomPortlet(BuildStatisticsPortlet.class);
v.save();
FreeStyleJob successJob = createFreeStyleJob();
FreeStyleJob failingJob = createFailingFreeStyleJob();
FreeStyleJob unstableJob = createUnstableFreeStyleJob();
buildUnstableJob(unstableJob);
buildSuccessfulJob(successJob);
buildSuccessfulJob(successJob);
buildFailingJob(failingJob);
v.open();
assertThat(stats.getNumberOfBuilds(JobType.TOTAL), is(4));
}
Aggregations