Search in sources :

Example 81 with FreeStyleProject

use of hudson.model.FreeStyleProject in project blueocean-plugin by jenkinsci.

the class ArtifactsSecurity564 method testArtifactsWithPermissions.

/**
 * Uses matrix-auth to provide artifacts permission.
 *
 * If hudson.security.ArtifactsPermission is set then the user must have Run.ARTIFACTS set.
 *
 * @throws Exception
 */
@Issue("SECURITY-564")
@Test
public void testArtifactsWithPermissions() throws Exception {
    String JOB_NAME = "artifactPermissions";
    String artfictPath = "a/b/c";
    HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false);
    realm.createAccount("alice", "alice");
    realm.createAccount("bob", "bob");
    j.jenkins.setSecurityRealm(realm);
    GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy();
    j.jenkins.setAuthorizationStrategy(as);
    as.add(Hudson.READ, "alice");
    as.add(Item.READ, "alice");
    as.add(Run.ARTIFACTS, "alice");
    as.add(Hudson.READ, "bob");
    as.add(Item.READ, "bob");
    FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
    p.getBuildersList().add(new ArtifactBuilder(artfictPath, 100));
    p.getPublishersList().add(new ArtifactArchiver("**/*"));
    Run r = p.scheduleBuild2(0).waitForStart();
    r = j.waitForCompletion(r);
    List artifacts = request().authAlice().get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/artifacts").build(List.class);
    Assert.assertEquals(100, artifacts.size());
    Assert.assertEquals(0, ((Map) artifacts.get(0)).get("size"));
    Assert.assertEquals(artfictPath + "/0.txt", ((Map) artifacts.get(0)).get("path"));
    Assert.assertEquals("/job/artifactPermissions/1/artifact/" + artfictPath + "/0.txt", ((Map) artifacts.get(0)).get("url"));
    List artifactsBob = request().auth("bob", "bob").get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/artifacts").build(List.class);
    Assert.assertEquals(0, artifactsBob.size());
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) Run(hudson.model.Run) List(java.util.List) FreeStyleProject(hudson.model.FreeStyleProject) HudsonPrivateSecurityRealm(hudson.security.HudsonPrivateSecurityRealm) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 82 with FreeStyleProject

use of hudson.model.FreeStyleProject in project blueocean-plugin by jenkinsci.

the class BlueOceanWebURLBuilderTest method test_freestyle.

@Test
public void test_freestyle() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = jenkinsRule.createFolder("folder1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder two with spaces");
    FreeStyleProject freestyleProject = folder2.createProject(FreeStyleProject.class, "freestyle with spaces");
    String blueOceanURL;
    blueOceanURL = urlMapper.getUrl(freestyleProject);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Ffreestyle%20with%20spaces", blueOceanURL);
    FreeStyleBuild run = freestyleProject.scheduleBuild2(0).get();
    blueOceanURL = urlMapper.getUrl(run);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Ffreestyle%20with%20spaces/detail/freestyle%20with%20spaces/1", blueOceanURL);
}
Also used : FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 83 with FreeStyleProject

use of hudson.model.FreeStyleProject in project blueocean-plugin by jenkinsci.

the class BlueOceanWebURLBuilderTest method testCustomerUrlMapper.

@Test
public void testCustomerUrlMapper() throws Exception {
    FreeStyleProject freestyleProject = jenkinsRule.createProject(FreeStyleProject.class, "freestyle1");
    String url = urlMapper.getUrl(freestyleProject);
    assertEquals("/customerUrlMapper/freestyle1", url);
}
Also used : FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 84 with FreeStyleProject

use of hudson.model.FreeStyleProject in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method testOrganizationFolder.

/**
 * Tests the API when the organization root is a folder instead of the root jenkins. That organization should only
 * see the elements under that folder.
 */
@Test
@Issue({ "JENKINS-44176", "JENKINS-44270" })
public void testOrganizationFolder() throws IOException, ExecutionException, InterruptedException {
    FreeStyleProject jobOutSideOrg = j.createFreeStyleProject("pipelineOutsideOrgName");
    jobOutSideOrg.setDisplayName("pipelineOutsideOrg Display Name");
    MockFolder orgFolder = j.createFolder("TestOrgFolderName");
    orgFolder.setDisplayName("TestOrgFolderName Display Name");
    MockFolder folderOnOrg = orgFolder.createProject(MockFolder.class, "folderOnOrgName");
    folderOnOrg.setDisplayName("folderOnOrg Display Name");
    FreeStyleProject jobOnRootOrg = orgFolder.createProject(FreeStyleProject.class, "jobOnRootOrgName");
    jobOnRootOrg.setDisplayName("jobOnRootOrg Display Name");
    FreeStyleProject jobOnFolder = folderOnOrg.createProject(FreeStyleProject.class, "jobOnFolderName");
    jobOnFolder.setDisplayName("jobOnFolder Display Name");
    List<Map> pipelines = get("/search/?q=type:pipeline;organization:TestOrg;excludedFromFlattening:jenkins.branch.MultiBranchProject,hudson.matrix.MatrixProject", List.class);
    // Only what's inside the org folder should be returned
    Assert.assertEquals(3, pipelines.size());
    // The full name should not contain the organization folder name
    Map links;
    for (Map map : pipelines) {
        Assert.assertEquals("TestOrg", map.get("organization"));
        if (map.get("name").equals("folderOnOrgName")) {
            map.get("fullDisplayName").equals("folderOnOrg%20Display%20Name");
            map.get("fullName").equals("folderOnOrgName");
            checkLinks((Map) map.get("_links"), "/blue/rest/organizations/TestOrg/pipelines/folderOnOrgName/");
        } else if (map.get("name").equals("jobOnRootOrgName")) {
            map.get("fullDisplayName").equals("jobOnRootOrg%20Display%20Name");
            map.get("fullName").equals("jobOnRootOrgName");
            checkLinks((Map) map.get("_links"), "/blue/rest/organizations/TestOrg/pipelines/jobOnRootOrgName/");
        } else if (map.get("name").equals("jobOnFolderName")) {
            map.get("fullDisplayName").equals("folderOnOrg%20Display%20Name/jobOnFolder%20Display%20Name");
            map.get("fullName").equals("folderOnOrgName/jobOnFolderName");
            checkLinks((Map) map.get("_links"), "/blue/rest/organizations/TestOrg/pipelines/folderOnOrgName/pipelines/jobOnFolderName/");
        } else {
            Assert.fail("Item " + map.get("name") + " shouldn't be present");
        }
    }
}
Also used : FreeStyleProject(hudson.model.FreeStyleProject) MockFolder(org.jvnet.hudson.test.MockFolder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 85 with FreeStyleProject

use of hudson.model.FreeStyleProject in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method actionsTest.

@Test
public void actionsTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline1");
    p.getBuildersList().add(new Shell("echo hello!\nsleep 1"));
    FreeStyleBuild b = p.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b);
    Map resp = get("/organizations/jenkins/pipelines/pipeline1/", Map.class);
    List<Map> actions = (List<Map>) resp.get("actions");
    Assert.assertTrue(actions.isEmpty());
    actions = (List<Map>) ((Map) resp.get("latestRun")).get("actions");
    resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/", Map.class);
    actions = (List<Map>) resp.get("actions");
    Assert.assertTrue(actions.isEmpty());
    resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/?tree=*[*]", Map.class);
    actions = (List<Map>) resp.get("actions");
    Assert.assertFalse(actions.isEmpty());
}
Also used : Shell(hudson.tasks.Shell) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

FreeStyleProject (hudson.model.FreeStyleProject)88 Test (org.junit.Test)61 FreeStyleBuild (hudson.model.FreeStyleBuild)42 Shell (hudson.tasks.Shell)21 Map (java.util.Map)20 ImmutableMap (com.google.common.collect.ImmutableMap)17 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)14 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)13 ArrayList (java.util.ArrayList)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 StringParameterDefinition (hudson.model.StringParameterDefinition)10 MockFolder (org.jvnet.hudson.test.MockFolder)10 List (java.util.List)9 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)8 ImmutableList (com.google.common.collect.ImmutableList)7 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)7 Promotion (hudson.plugins.promoted_builds.Promotion)7 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)6 Run (hudson.model.Run)6 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)6