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']"))));
}
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();
}
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();
}
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();
}
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"));
}
Aggregations