use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.
the class LegacyJobConfigMigrationMonitorMigrationTest method migrate_freestyle_to_freestyle.
@Test
public void migrate_freestyle_to_freestyle() throws Exception {
FreeStyleProject src = j.createFreeStyleProject();
src.getBuildersList().add(new FileWriteBuilder("artifact.txt", "artifact content"));
src.getPublishersList().add(new ArtifactArchiver("**/*"));
j.assertBuildStatusSuccess(src.scheduleBuild2(0));
FreeStyleProject dst = j.createFreeStyleProject();
dst.getBuildersList().add(new CopyArtifact(src.getFullName()));
j.assertBuildStatusSuccess(dst.scheduleBuild2(0));
CopyArtifactConfiguration.get().setMode(CopyArtifactCompatibilityMode.PRODUCTION);
j.assertBuildStatus(Result.FAILURE, dst.scheduleBuild2(0));
assertTrue(applyAutoMigrationToAll());
j.assertBuildStatusSuccess(dst.scheduleBuild2(0));
}
use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.
the class LegacyJobConfigMigrationMonitorTest method setupRestrictedJob.
private void setupRestrictedJob() throws Exception {
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
MockAuthorizationStrategy auth = new MockAuthorizationStrategy();
j.jenkins.setAuthorizationStrategy(auth);
FreeStyleProject toBeCopied = j.createFreeStyleProject("to-be-copied");
auth.grant(Item.READ).onItems(toBeCopied).to("admin");
toBeCopied.getBuildersList().add(new FileWriteBuilder("test.txt", "test"));
toBeCopied.getPublishersList().add(new ArtifactArchiver("**"));
FreeStyleProject copier = j.createFreeStyleProject("copier");
copier.getBuildersList().add(new CopyArtifact(toBeCopied.getFullName()));
}
use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.
the class CopyArtifactTest method artifactsPermissionWithAuthSuccess.
@Test
public void artifactsPermissionWithAuthSuccess() throws Exception {
System.setProperty("hudson.security.ArtifactsPermission", "true");
rule.jenkins.setSecurityRealm(rule.createDummySecurityRealm());
MockAuthorizationStrategy authStrategy = new MockAuthorizationStrategy();
rule.jenkins.setAuthorizationStrategy(authStrategy);
authStrategy.grant(Item.BUILD).onRoot().to("joe");
authStrategy.grant(Computer.BUILD).onRoot().to("joe");
FreeStyleProject src = rule.createFreeStyleProject();
src.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar"));
src.getPublishersList().add(new ArtifactArchiver("artifact.txt"));
authStrategy.grant(Item.READ).onItems(src).to("joe");
authStrategy.grant(Run.ARTIFACTS).onItems(src).to("joe");
rule.assertBuildStatusSuccess(src.scheduleBuild2(0));
FreeStyleProject dest = rule.createFreeStyleProject();
dest.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(src.getName(), "", new StatusBuildSelector(), "", "", false, false, true));
Map<String, Authentication> authMap = new HashMap<>();
authMap.put(dest.getFullName(), User.getById("joe", true).impersonate());
QueueItemAuthenticatorConfiguration.get().getAuthenticators().clear();
QueueItemAuthenticatorConfiguration.get().getAuthenticators().add(new MockQueueItemAuthenticator(authMap));
rule.assertBuildStatusSuccess(dest.scheduleBuild2(0));
}
use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.
the class CopyArtifactTest method artifactsPermissionAnonymousFailure.
@Test
public void artifactsPermissionAnonymousFailure() throws Exception {
System.setProperty("hudson.security.ArtifactsPermission", "true");
rule.jenkins.setSecurityRealm(rule.createDummySecurityRealm());
MockAuthorizationStrategy authStrategy = new MockAuthorizationStrategy();
rule.jenkins.setAuthorizationStrategy(authStrategy);
FreeStyleProject src = rule.createFreeStyleProject();
src.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar"));
src.getPublishersList().add(new ArtifactArchiver("artifact.txt"));
authStrategy.grant(Item.READ).onItems(src).toEveryone();
// Watch out: No Run.Artifacts permission.
// authStrategy.grant(Run.ARTIFACTS).onItems(src).toEveryone();
rule.assertBuildStatusSuccess(src.scheduleBuild2(0));
FreeStyleProject dest = rule.createFreeStyleProject();
dest.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(src.getName(), "", new StatusBuildSelector(), "", "", false, false, true));
rule.assertBuildStatus(Result.FAILURE, dest.scheduleBuild2(0));
}
use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.
the class LegacyJobConfigMigrationMonitorTest method setupParamJob.
private void setupParamJob() throws Exception {
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
MockAuthorizationStrategy auth = new MockAuthorizationStrategy();
j.jenkins.setAuthorizationStrategy(auth);
FreeStyleProject toBeCopiedAnonymous = j.createFreeStyleProject("to-be-copied_anonymous");
auth.grant(Item.READ, Item.CONFIGURE).onItems(toBeCopiedAnonymous).toEveryone();
toBeCopiedAnonymous.getBuildersList().add(new FileWriteBuilder("test.txt", "test"));
toBeCopiedAnonymous.getPublishersList().add(new ArtifactArchiver("**"));
// Originally this is configured without AuthorizationMatrixProperty,
// which results inheriting the global configuration,
// in contract to that other jobs doesn't inherit the global configuration
// MockAuthorizationStrategy doesn't provide feature to refuse inheriting
// in a specific job, so this job is configured to grant Item.READ to everyone,
// which was originally configured in the global configuration.
FreeStyleProject toBeCopiedNoauth = j.createFreeStyleProject("to-be-copied_noauth");
auth.grant(Item.READ).onItems(toBeCopiedNoauth).toEveryone();
toBeCopiedNoauth.getBuildersList().add(new FileWriteBuilder("test.txt", "test"));
toBeCopiedNoauth.getPublishersList().add(new ArtifactArchiver("**"));
FreeStyleProject toBeCopiedRestricted = j.createFreeStyleProject("to-be-copied_restricted");
auth.grant(Item.READ).onItems(toBeCopiedRestricted).to("leader", "admin");
toBeCopiedRestricted.getBuildersList().add(new FileWriteBuilder("test.txt", "test"));
toBeCopiedRestricted.getPublishersList().add(new ArtifactArchiver("**"));
FreeStyleProject copier = j.createFreeStyleProject("copier");
copier.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("sourceProject", "")));
copier.getBuildersList().add(new CopyArtifact("${sourceProject}"));
}
Aggregations