Search in sources :

Example 26 with FileWriteBuilder

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));
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) CopyArtifact(hudson.plugins.copyartifact.CopyArtifact) FreeStyleProject(hudson.model.FreeStyleProject) WorkflowMultiBranchProjectTest(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProjectTest) Test(org.junit.Test)

Example 27 with FileWriteBuilder

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()));
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) MockAuthorizationStrategy(org.jvnet.hudson.test.MockAuthorizationStrategy) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) CopyArtifact(hudson.plugins.copyartifact.CopyArtifact) FreeStyleProject(hudson.model.FreeStyleProject)

Example 28 with FileWriteBuilder

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));
}
Also used : MockQueueItemAuthenticator(org.jvnet.hudson.test.MockQueueItemAuthenticator) ArtifactArchiver(hudson.tasks.ArtifactArchiver) HashMap(java.util.HashMap) Authentication(org.acegisecurity.Authentication) MockAuthorizationStrategy(org.jvnet.hudson.test.MockAuthorizationStrategy) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) Test(org.junit.Test)

Example 29 with FileWriteBuilder

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));
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) MockAuthorizationStrategy(org.jvnet.hudson.test.MockAuthorizationStrategy) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) Test(org.junit.Test)

Example 30 with FileWriteBuilder

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}"));
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) MockAuthorizationStrategy(org.jvnet.hudson.test.MockAuthorizationStrategy) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) CopyArtifact(hudson.plugins.copyartifact.CopyArtifact) FreeStyleProject(hudson.model.FreeStyleProject)

Aggregations

FileWriteBuilder (hudson.plugins.copyartifact.testutils.FileWriteBuilder)37 ArtifactArchiver (hudson.tasks.ArtifactArchiver)37 Test (org.junit.Test)32 FreeStyleProject (hudson.model.FreeStyleProject)26 FreeStyleBuild (hudson.model.FreeStyleBuild)17 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)15 StringParameterDefinition (hudson.model.StringParameterDefinition)15 ParametersAction (hudson.model.ParametersAction)13 StringParameterValue (hudson.model.StringParameterValue)13 ParameterDefinition (hudson.model.ParameterDefinition)11 BuildTrigger (hudson.tasks.BuildTrigger)11 MockAuthorizationStrategy (org.jvnet.hudson.test.MockAuthorizationStrategy)11 Cause (hudson.model.Cause)10 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)9 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)6 CopyArtifact (hudson.plugins.copyartifact.CopyArtifact)4 File (java.io.File)4 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)4 Axis (hudson.matrix.Axis)3 AxisList (hudson.matrix.AxisList)3