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