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