Search in sources :

Example 1 with MockFolder

use of org.jvnet.hudson.test.MockFolder in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testMultiBranchPipelineBranchUnsecurePermissions.

@Test
public void testMultiBranchPipelineBranchUnsecurePermissions() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    WorkflowMultiBranchProject mp = folder1.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    mp.scheduleBuild2(0).getFuture().get();
    Map r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");
    Map<String, Boolean> permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertTrue(permissions.get("create"));
    Assert.assertTrue(permissions.get("read"));
    Assert.assertTrue(permissions.get("start"));
    Assert.assertTrue(permissions.get("stop"));
    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/branches/master/");
    permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertTrue(permissions.get("create"));
    Assert.assertTrue(permissions.get("start"));
    Assert.assertTrue(permissions.get("stop"));
    Assert.assertTrue(permissions.get("read"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) MockFolder(org.jvnet.hudson.test.MockFolder) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 2 with MockFolder

use of org.jvnet.hudson.test.MockFolder in project blueocean-plugin by jenkinsci.

the class LinkResolverTest method nestedFolderJobLinkResolveTest.

@Test
public void nestedFolderJobLinkResolveTest() throws IOException {
    Project f = j.createFreeStyleProject("fstyle1");
    MockFolder folder1 = j.createFolder("folder1");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    MockFolder folder3 = folder2.createProject(MockFolder.class, "folder3");
    Project p2 = folder2.createProject(FreeStyleProject.class, "test2");
    Project p3 = folder3.createProject(FreeStyleProject.class, "test3");
    WorkflowJob pipelineJob1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    pipelineJob1.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" + "    node {\n" + "       sh \"echo here\"\n" + "    }\n" + "\n"));
    WorkflowJob pipelineJob2 = folder2.createProject(WorkflowJob.class, "pipeline2");
    pipelineJob2.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" + "    node {\n" + "       sh \"echo here\"\n" + "    }\n" + "\n"));
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/pipeline1/", LinkResolver.resolveLink(pipelineJob1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/pipeline2/", LinkResolver.resolveLink(pipelineJob2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/fstyle1/", LinkResolver.resolveLink(f).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/", LinkResolver.resolveLink(folder1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/test1/", LinkResolver.resolveLink(p1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/", LinkResolver.resolveLink(folder2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/test2/", LinkResolver.resolveLink(p2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/", LinkResolver.resolveLink(folder3).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/pipelines/test3/", LinkResolver.resolveLink(p3).getHref());
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) MockFolder(org.jvnet.hudson.test.MockFolder) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Test(org.junit.Test)

Example 3 with MockFolder

use of org.jvnet.hudson.test.MockFolder in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method PipelineSecureWithAnonymousUserPermissionTest.

@Test
public void PipelineSecureWithAnonymousUserPermissionTest() throws IOException {
    j.jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(false));
    j.jenkins.setAuthorizationStrategy(new LegacyAuthorizationStrategy());
    MockFolder folder = j.createFolder("folder1");
    Project p = folder.createProject(FreeStyleProject.class, "test1");
    Map response = get("/organizations/jenkins/pipelines/folder1/pipelines/test1");
    validatePipeline(p, response);
    Map<String, Boolean> permissions = (Map<String, Boolean>) response.get("permissions");
    Assert.assertFalse(permissions.get("create"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));
    assertTrue(permissions.get("read"));
    response = get("/organizations/jenkins/pipelines/folder1/");
    permissions = (Map<String, Boolean>) response.get("permissions");
    Assert.assertFalse(permissions.get("create"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));
    assertTrue(permissions.get("read"));
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) LegacyAuthorizationStrategy(hudson.security.LegacyAuthorizationStrategy) MockFolder(org.jvnet.hudson.test.MockFolder) HudsonPrivateSecurityRealm(hudson.security.HudsonPrivateSecurityRealm) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 4 with MockFolder

use of org.jvnet.hudson.test.MockFolder in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method getNestedFolderPipelineTest.

@Test
public void getNestedFolderPipelineTest() throws IOException {
    MockFolder folder1 = j.createFolder("folder1");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    folder2.setDisplayName("My folder2");
    MockFolder folder3 = folder1.createProject(MockFolder.class, "folder3");
    Project p2 = folder2.createProject(FreeStyleProject.class, "test2");
    List<Map> topFolders = get("/organizations/jenkins/pipelines/", List.class);
    assertEquals(1, topFolders.size());
    Map response = get("/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/test2");
    validatePipeline(p2, response);
    List<Map> pipelines = get("/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/", List.class);
    assertEquals(1, pipelines.size());
    validatePipeline(p2, pipelines.get(0));
    pipelines = get("/organizations/jenkins/pipelines/folder1/pipelines/", List.class);
    assertEquals(3, pipelines.size());
    assertEquals("folder2", pipelines.get(0).get("name"));
    assertEquals("folder1/folder2", pipelines.get(0).get("fullName"));
    assertEquals("folder1/My%20folder2", pipelines.get(0).get("fullDisplayName"));
    response = get("/organizations/jenkins/pipelines/folder1");
    assertEquals("folder1", response.get("name"));
    assertEquals("folder1", response.get("displayName"));
    assertEquals(2, response.get("numberOfFolders"));
    assertEquals(1, response.get("numberOfPipelines"));
    assertEquals("folder1", response.get("fullName"));
    String clazz = (String) response.get("_class");
    response = get("/classes/" + clazz + "/");
    assertNotNull(response);
    List<String> classes = (List<String>) response.get("classes");
    assertTrue(!classes.contains("hudson.model.Job") && classes.contains("io.jenkins.blueocean.rest.model.BluePipeline") && classes.contains("io.jenkins.blueocean.rest.model.BluePipelineFolder") && classes.contains("com.cloudbees.hudson.plugins.folder.AbstractFolder"));
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MockFolder(org.jvnet.hudson.test.MockFolder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 5 with MockFolder

use of org.jvnet.hudson.test.MockFolder in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method PipelineUnsecurePermissionTest.

@Test
public void PipelineUnsecurePermissionTest() throws IOException {
    MockFolder folder = j.createFolder("folder1");
    Project p = folder.createProject(FreeStyleProject.class, "test1");
    Map response = get("/organizations/jenkins/pipelines/folder1/pipelines/test1");
    validatePipeline(p, response);
    Map<String, Boolean> permissions = (Map<String, Boolean>) response.get("permissions");
    assertTrue(permissions.get("create"));
    assertTrue(permissions.get("start"));
    assertTrue(permissions.get("stop"));
    assertTrue(permissions.get("read"));
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) MockFolder(org.jvnet.hudson.test.MockFolder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)22 MockFolder (org.jvnet.hudson.test.MockFolder)22 FreeStyleProject (hudson.model.FreeStyleProject)18 Project (hudson.model.Project)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 Map (java.util.Map)10 FreeStyleBuild (hudson.model.FreeStyleBuild)4 BranchSource (jenkins.branch.BranchSource)4 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)4 GitSCMSource (jenkins.plugins.git.GitSCMSource)4 SCMSource (jenkins.scm.api.SCMSource)4 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)4 User (hudson.model.User)3 ImmutableList (com.google.common.collect.ImmutableList)2 EnvVars (hudson.EnvVars)2 Action (hudson.model.Action)2 ParameterValue (hudson.model.ParameterValue)2 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)2 HudsonPrivateSecurityRealm (hudson.security.HudsonPrivateSecurityRealm)2 LegacyAuthorizationStrategy (hudson.security.LegacyAuthorizationStrategy)2