Search in sources :

Example 21 with JobDslBuildStep

use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_disallow_importing_groovy_classes_when_script_security_enabled.

/**
 * Verifies that if script security for Job DSL scripts is enabled and Jenkins
 * security is enabled, it is not possible to import Groovy classes from the
 * workspace.
 */
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_disallow_importing_groovy_classes_when_script_security_enabled() {
    GlobalSecurityConfig sc = setUpSecurity();
    jenkins.login().doLogin(ADMIN);
    FreeStyleJob seedJob = createSeedJob();
    seedJob.copyResource(resource("/job_dsl_plugin/MyUtilities.groovy"), "utilities/MyUtilities.groovy");
    JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
    jobDsl.setScript("import utilities.MyUtilities\n" + "\n" + "def newJob = job('New_Job')\n" + "MyUtilities.addDescription(newJob)");
    seedJob.save();
    // Build should fail because importing Groovy classes not allowed if script security is enabled
    Build build = seedJob.scheduleBuild().shouldFail();
    assertThat(build.getConsole(), containsString("unable to resolve class utilities.MyUtilities"));
    sc.configure(() -> sc.setJobDslScriptSecurity(false));
    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) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 22 with JobDslBuildStep

use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method is_ignoreMissingFiles_shown_right.

/**
 * Tests if the checkbox ignoreMissingFiles is shown when the
 * radiobutton 'Look on Filesystem' is selected,
 * and not shown if the radiobutton 'Use the provided DSL script'
 * is selected.
 */
@Test
public void is_ignoreMissingFiles_shown_right() {
    FreeStyleJob seedJob = createSeedJob();
    JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
    assertThat(jobDsl.isIgnoreMissingFilesShown(), is(true));
    jobDsl.clickUseScriptText();
    assertThat(jobDsl.isIgnoreMissingFilesShown(), is(false));
    jobDsl.clickLookOnFilesystem();
    assertThat(jobDsl.isIgnoreMissingFilesShown(), is(true));
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 23 with JobDslBuildStep

use of org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_unstable_on_deprecated_features.

/**
 * Verifies whether the build will be marked as unstable if deprecated
 * features are used.
 * By default, only a warning is printed to the build log.
 * If the function is used, the build will be marked as unstable.
 */
@Test
@WithPlugins("config-file-provider")
public void should_unstable_on_deprecated_features() {
    FreeStyleJob seedJob = createSeedJob();
    JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
    jobDsl.setScript("customConfigFile('New_Config_File')");
    seedJob.save();
    Build build = seedJob.scheduleBuild().shouldSucceed();
    assertThat(build.getConsole(), containsString("Warning: (script, line 1) customConfigFile is deprecated"));
    seedJob.configure(() -> jobDsl.setUnstableOnDeprecation(true));
    build = seedJob.scheduleBuild().shouldBeUnstable();
    assertThat(build.getConsole(), containsString("Warning: (script, line 1) customConfigFile is deprecated"));
}
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)

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