use of org.jenkinsci.test.acceptance.junit.WithPlugins 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.junit.WithPlugins 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.junit.WithPlugins in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_lookup_at_jenkins_root.
/**
* Verifies that relative job names are interpreted relative to the Jenkins root.
* Even if the seed job is located in a folder, a new generated job is relative
* to the Jenkins root.
*/
@Test
@WithPlugins("cloudbees-folder")
public void should_lookup_at_jenkins_root() {
Folder folder = runSeedJobInFolder("New_Job", JobDslLookupStrategy.JENKINS_ROOT);
FreeStyleJob newJob = getJob("New_Job");
assertThat(newJob, pageObjectExists());
newJob = folder.getJobs().get(FreeStyleJob.class, "New_Job");
assertThat(newJob, pageObjectDoesNotExist());
}
use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method job_filters_most_recent_3_jobs.
/**
* This test creates 5 jobs and builds them immediately. A list view is created with its job filter set to show the
* 3 jobs which were most recently built.
*/
@Test
@WithPlugins("view-job-filters")
public void job_filters_most_recent_3_jobs() {
List<Job> jobs = createAmountOfJobs(5, true);
String jobDslScript = "listView('" + LIST_VIEW_NAME + "') {\n" + " columns {\n" + " name()\n" + " }\n" + " jobs{\n" + " names('" + jobs.get(0).name + "','" + jobs.get(1).name + "','" + jobs.get(2).name + "','" + jobs.get(3).name + "','" + jobs.get(4).name + "')\n" + " }\n" + " jobFilters {\n" + " mostRecent {\n" + " maxToInclude(3)\n" + " }\n" + " }\n" + "}";
View view = openNewlyCreatedListView(jobDslScript, LIST_VIEW_NAME);
assertThat(view, not(containsJob(jobs.get(0))));
assertThat(view, not(containsJob(jobs.get(1))));
assertThat(view, containsJob(jobs.get(2)));
assertThat(view, containsJob(jobs.get(3)));
assertThat(view, containsJob(jobs.get(4)));
}
use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method job_filters_regex_name_exclude_matched.
/**
* This test creates a listView and 4 jobs. The job filters are checking the name with a regex and
* jobs matching the regex are excluded in the listView.
*/
@Test
@WithPlugins("view-job-filters")
public void job_filters_regex_name_exclude_matched() {
Job job1 = createJobWithName(EXAMPLE_DISABLED_NAME);
Job job2 = createJobWithName(EXAMPLE_ENABLED_NAME);
List<Job> jobs = createAmountOfJobs(2, false);
String jobDslScript = "listView('" + LIST_VIEW_NAME + "') {\n" + " columns {\n" + " name()\n" + " }\n" + " jobs{\n" + " names('" + job1.name + "','" + job2.name + "','" + jobs.get(0).name + "','" + jobs.get(1).name + "')\n" + " }\n" + " jobFilters {\n" + " regex {\n" + " matchType(MatchType.EXCLUDE_MATCHED)\n" + " matchValue(RegexMatchValue.NAME)\n" + " regex('" + LIST_VIEW_REGEX + "')\n" + " }\n" + " }\n" + "}";
View view = openNewlyCreatedListView(jobDslScript, LIST_VIEW_NAME);
assertThat(view, not(containsJob(job1)));
assertThat(view, not(containsJob(job2)));
assertThat(view, containsJob(jobs.get(0)));
assertThat(view, containsJob(jobs.get(1)));
}
Aggregations