use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_use_script_approval.
/**
* Verifies that if script security for Job DSL scripts is enabled,
* scripts saved by non administrators that not run in a Groovy sandbox
* wont be executed.
* Administrators can approve scripts in the 'Script Approval' of the
* 'Manage Jenkins' area. Approved scripts can be executed.
*/
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_use_script_approval() {
setUpSecurity();
jenkins.login().doLogin(USER);
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("job('New_Job')");
jobDsl.setUseSandbox(false);
seedJob.save();
// Build should fail because script is saved from non administrator an not yet approved
Build build = seedJob.scheduleBuild().shouldFail();
assertThat(build.getConsole(), containsString("script not yet approved for use"));
jenkins.logout();
jenkins.login().doLogin(ADMIN);
// Build should fail because script is saved from non administrator an not yet approved
Build build2 = seedJob.scheduleBuild().shouldFail();
assertThat(build2.getConsole(), containsString("script not yet approved for use"));
ScriptApproval sa = new ScriptApproval(jenkins);
sa.open();
sa.find(seedJob.name).approve();
jenkins.logout();
jenkins.login().doLogin(USER);
// Build should succeed because script is approved now
seedJob.scheduleBuild().shouldSucceed();
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_approve_administrator_script_automatically.
/**
* Verifies that if script security for Job DSL scripts is enabled,
* scripts saved by non administrators that not run in a Groovy sandbox
* wont be executed.
* If a administrator saves the seed job, any DSL scripts it contains
* will be automatically approved. Afterwards the script
* can be executed.
*/
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_approve_administrator_script_automatically() {
setUpSecurity();
jenkins.login().doLogin(USER);
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("job('New_Job')");
jobDsl.setUseSandbox(false);
seedJob.save();
// Build should fail because script is saved from non administrator an not yet approved
Build build = seedJob.scheduleBuild().shouldFail();
assertThat(build.getConsole(), containsString("script not yet approved for use"));
jenkins.logout();
jenkins.login().doLogin(ADMIN);
// Build should fail because script is saved from non administrator an not yet approved
Build build2 = seedJob.scheduleBuild().shouldFail();
assertThat(build2.getConsole(), containsString("script not yet approved for use"));
seedJob.configure();
seedJob.save();
jenkins.logout();
jenkins.login().doLogin(USER);
// Build should succeed because job was saved from administrator
seedJob.scheduleBuild().shouldSucceed();
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_look_on_filesystem.
/**
* Verifies that a list of newline separated DSL scripts, located in the workspace,
* is read an executed in the same order as specified.
* Therefore the first script creates an folder. The second script creates a job
* in this folder. If the order is changed, the build will fail because the
* folder was not created yet.
*/
@Test
@WithPlugins("cloudbees-folder")
public void should_look_on_filesystem() {
FreeStyleJob seedJob = createSeedJob();
seedJob.copyResource(resource("/job_dsl_plugin/CreateFolder.groovy"));
seedJob.copyResource(resource("/job_dsl_plugin/CreateJobInFolder.groovy"));
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScriptTargetsOnFilesystem("CreateFolder.groovy", "CreateJobInFolder.groovy");
seedJob.save();
Build build = seedJob.scheduleBuild().shouldSucceed();
Pattern expected = Pattern.compile("Processing DSL script CreateFolder.groovy(\\s*)" + "Processing DSL script CreateJobInFolder.groovy");
assertThat(build.getConsole(), containsRegexp(expected));
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method executeRemovedConfigFilesAction.
/**
* Let a seed job run a Job DSL script that do not reference a previous generated config file anymore.
* @param action The action what to do when a previously generated config file is not referenced anymore.
* @return The executed seed job.
*/
private FreeStyleJob executeRemovedConfigFilesAction(JobDslRemovedConfigFilesAction action) {
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("configFiles {\n" + " customConfig {\n" + " id('123456789')\n" + " name('Old_Config_File')\n" + " comment('This is a comment.')\n" + " content('My Content')\n" + " providerId('')\n" + " }\n" + "}");
seedJob.save();
seedJob.scheduleBuild().shouldSucceed();
seedJob.configure(() -> {
jobDsl.setScript("configFiles {\n" + " customConfig {\n" + " id('456789123')\n" + " name('New_Config_File')\n" + " comment('This is a comment.')\n" + " content('My Content')\n" + " providerId('')\n" + " }\n" + "}");
jobDsl.setRemovedConfigFilesAction(action);
});
return seedJob;
}
use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_alert_if_generated_job_changed.
/**
* Verifies that an alert is shown on the project page of the generated job
* if it has been changed manually since it was generated by the seed job.
*/
@Test
public void should_alert_if_generated_job_changed() {
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("job('New_Job')");
seedJob.save();
seedJob.scheduleBuild().shouldSucceed();
FreeStyleJob generatedJob = getJob("New_Job");
generatedJob.open();
String alert = "This item has been changed manually since it was generated by the seed job.";
assertThat(driver, not(hasContent(alert)));
generatedJob.configure(() -> generatedJob.setDescription("New Description"));
assertThat(driver, hasContent(alert));
}
Aggregations