Search in sources :

Example 16 with JobDslBuildStep

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();
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) ScriptApproval(org.jenkinsci.test.acceptance.plugins.script_security.ScriptApproval) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 17 with JobDslBuildStep

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();
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 18 with JobDslBuildStep

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));
}
Also used : Pattern(java.util.regex.Pattern) JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 19 with JobDslBuildStep

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;
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob)

Example 20 with JobDslBuildStep

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));
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Aggregations

JobDslBuildStep (org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep)23 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)23 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)17 Test (org.junit.Test)17 Build (org.jenkinsci.test.acceptance.po.Build)13 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)10 GlobalSecurityConfig (org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)5 Pattern (java.util.regex.Pattern)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ScriptApproval (org.jenkinsci.test.acceptance.plugins.script_security.ScriptApproval)2 Folder (org.jenkinsci.test.acceptance.po.Folder)1 Job (org.jenkinsci.test.acceptance.po.Job)1 ListView (org.jenkinsci.test.acceptance.po.ListView)1 PluginManager (org.jenkinsci.test.acceptance.po.PluginManager)1 PluginSpec (org.jenkinsci.test.acceptance.update_center.PluginSpec)1