Search in sources :

Example 26 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_delete_removed_config_files.

/**
 * Verifies whether a previously generated config file will be deleted if it
 * is not referenced anymore.
 */
@Test
@WithPlugins("config-file-provider")
public void should_delete_removed_config_files() {
    FreeStyleJob seedJob = executeRemovedConfigFilesAction(JobDslRemovedConfigFilesAction.DELETE);
    Build build = seedJob.scheduleBuild().shouldSucceed();
    Pattern expected = Pattern.compile("Unreferenced config files:(\\s*)GeneratedConfigFile[{]name='Old_Config_File', id='123456789'}");
    assertThat(build.getConsole(), containsRegexp(expected));
    ConfigFileProvider configFileProvider = new ConfigFileProvider(jenkins);
    configFileProvider.open();
    assertThat(driver, not(hasElement(by.xpath("//a[@href='editConfig?id=123456789']"))));
}
Also used : Pattern(java.util.regex.Pattern) Build(org.jenkinsci.test.acceptance.po.Build) ConfigFileProvider(org.jenkinsci.test.acceptance.plugins.config_file_provider.ConfigFileProvider) 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 27 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_use_script_security.

/**
 * 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, because they are not approved.
 * If script security for Job DSL scripts is disabled, the script can be executed.
 */
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_use_script_security() {
    GlobalSecurityConfig sc = 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"));
    sc.configure(() -> sc.setJobDslScriptSecurity(false));
    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) 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 28 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_use_grooy_sandbox_whitelisted_content.

/**
 * Verifies that if script security for Job DSL scripts is enabled,
 * scripts saved by non administrators can run in a Groovy sandbox
 * without approval. All Job DSL methods are whitelisted by default.
 */
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm", "authorize-project" })
public void should_use_grooy_sandbox_whitelisted_content() {
    GlobalSecurityConfig sc = setUpSecurity();
    runBuildAsUserWhoTriggered(sc);
    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"));
    seedJob.configure(() -> jobDsl.setUseSandbox(true));
    // Build should succeed because the script runs in Groovy sandbox
    // and only Job DSL methods are used.
    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 29 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins 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();
}
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) 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 30 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class ArtifactoryPluginTest method maven_integration.

@Test
@WithPlugins("maven-plugin")
@Ignore
@Issue("JENKINS-66791")
public void maven_integration() {
    installSomeMaven(jenkins);
    final ArtifactoryContainer artifactory = artifactoryContainer.get();
    waitForArtifactory(artifactory);
    configureArtifactory(artifactory);
    MavenModuleSet job = jenkins.jobs.create(MavenModuleSet.class);
    job.configure();
    job.copyDir(resource("/artifactory_plugin/multimodule/"));
    job.goals.set("install");
    job.options("-verbose");
    ArtifactoryPublisher publisher = job.addPublisher(ArtifactoryPublisher.class);
    publisher.refresh();
    job.save();
    Build build = job.startBuild().shouldSucceed();
    String log = build.getConsole();
    assertThat(log, containsString("Initializing Artifactory Build-Info Recording"));
    assertThat(log, containsString("Deploying artifact"));
    assertThat(log, containsRegexp("Deploying build (info|descriptor) to: " + artifactory.getURL() + "/api/build"));
}
Also used : ArtifactoryContainer(org.jenkinsci.test.acceptance.docker.fixtures.ArtifactoryContainer) Build(org.jenkinsci.test.acceptance.po.Build) ArtifactoryPublisher(org.jenkinsci.test.acceptance.plugins.artifactory.ArtifactoryPublisher) Matchers.containsString(org.hamcrest.Matchers.containsString) MavenModuleSet(org.jenkinsci.test.acceptance.plugins.maven.MavenModuleSet) Ignore(org.junit.Ignore) Issue(org.jvnet.hudson.test.Issue) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) DockerTest(org.jenkinsci.test.acceptance.junit.DockerTest) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Aggregations

WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)89 Test (org.junit.Test)89 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)71 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)53 Build (org.jenkinsci.test.acceptance.po.Build)39 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)31 Issue (org.jvnet.hudson.test.Issue)25 Job (org.jenkinsci.test.acceptance.po.Job)19 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)15 WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)15 ListView (org.jenkinsci.test.acceptance.po.ListView)13 View (org.jenkinsci.test.acceptance.po.View)13 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)12 WithCredentials (org.jenkinsci.test.acceptance.junit.WithCredentials)11 JobDslBuildStep (org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep)10 Matchers.containsString (org.hamcrest.Matchers.containsString)9 GlobalSecurityConfig (org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)9 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)8 Ignore (org.junit.Ignore)8 WarningsAction (org.jenkinsci.test.acceptance.plugins.warnings.WarningsAction)5