Search in sources :

Example 1 with Folder

use of com.cloudbees.hudson.plugins.folder.Folder in project blueocean-plugin by jenkinsci.

the class CachesTest method setup.

@Before
public void setup() {
    jenkins = mock(Jenkins.class);
    when(jenkins.getFullName()).thenReturn("");
    Folder folder = mock(Folder.class);
    when(folder.getParent()).thenReturn(jenkins);
    when(folder.getFullName()).thenReturn("/Repo");
    when(jenkins.getItem("/Repo")).thenReturn(folder);
    job = mock(Job.class);
    when(job.getParent()).thenReturn(folder);
    when(job.getFullName()).thenReturn("cool-branch");
    when(jenkins.getItemByFullName("/Repo/cool-branch", Job.class)).thenReturn(job);
}
Also used : Jenkins(jenkins.model.Jenkins) Folder(com.cloudbees.hudson.plugins.folder.Folder) Job(hudson.model.Job) Before(org.junit.Before)

Example 2 with Folder

use of com.cloudbees.hudson.plugins.folder.Folder in project configuration-as-code-plugin by jenkinsci.

the class RoleStrategyTest method shouldReadRolesCorrectly.

@Test
@Issue("Issue #48")
@ConfiguredWithCode("RoleStrategy1.yml")
public void shouldReadRolesCorrectly() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    User admin = User.get("admin");
    User user1 = User.get("user1");
    User user2 = User.get("user2");
    Computer agent1 = j.jenkins.getComputer("agent1");
    Computer agent2 = j.jenkins.getComputer("agent2");
    Folder folderA = j.jenkins.createProject(Folder.class, "A");
    FreeStyleProject jobA1 = folderA.createProject(FreeStyleProject.class, "1");
    Folder folderB = j.jenkins.createProject(Folder.class, "B");
    FreeStyleProject jobB2 = folderB.createProject(FreeStyleProject.class, "2");
    AuthorizationStrategy s = j.jenkins.getAuthorizationStrategy();
    assertThat("Authorization Strategy has been read incorrectly", s, instanceOf(RoleBasedAuthorizationStrategy.class));
    RoleBasedAuthorizationStrategy rbas = (RoleBasedAuthorizationStrategy) s;
    Map<Role, Set<String>> globalRoles = rbas.getGrantedRoles(RoleBasedAuthorizationStrategy.GLOBAL);
    assertThat(globalRoles.size(), equalTo(2));
    // Admin has configuration access
    assertHasPermission(admin, j.jenkins, Jenkins.ADMINISTER, Jenkins.READ);
    assertHasPermission(user1, j.jenkins, Jenkins.READ);
    assertHasNoPermission(user1, j.jenkins, Jenkins.ADMINISTER, Jenkins.RUN_SCRIPTS);
    // Folder A is restricted to admin
    assertHasPermission(admin, folderA, Item.CONFIGURE);
    assertHasPermission(user1, folderA, Item.READ, Item.DISCOVER);
    assertHasNoPermission(user1, folderA, Item.CONFIGURE, Item.DELETE, Item.BUILD);
    // But they have access to jobs in Folder A
    assertHasPermission(admin, folderA, Item.CONFIGURE, Item.CANCEL);
    assertHasPermission(user1, jobA1, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    assertHasPermission(user2, jobA1, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    assertHasNoPermission(user1, folderA, Item.CANCEL);
    // FolderB is editable by user2, but he cannot delete it
    assertHasPermission(user2, folderB, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD);
    assertHasNoPermission(user2, folderB, Item.DELETE);
    assertHasNoPermission(user1, folderB, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    // Only user1 can run on agent1, but he still cannot configure it
    assertHasPermission(admin, agent1, Computer.CONFIGURE, Computer.DELETE, Computer.BUILD);
    assertHasPermission(user1, agent1, Computer.BUILD);
    assertHasNoPermission(user1, agent1, Computer.CONFIGURE, Computer.DISCONNECT);
    // Same user still cannot build on agent2
    assertHasNoPermission(user1, agent2, Computer.BUILD);
}
Also used : Role(com.michelin.cio.hudson.plugins.rolestrategy.Role) AuthorizationStrategy(hudson.security.AuthorizationStrategy) RoleBasedAuthorizationStrategy(com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy) User(hudson.model.User) Set(java.util.Set) Computer(hudson.model.Computer) Folder(com.cloudbees.hudson.plugins.folder.Folder) FreeStyleProject(hudson.model.FreeStyleProject) RoleBasedAuthorizationStrategy(com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 3 with Folder

use of com.cloudbees.hudson.plugins.folder.Folder in project support-core-plugin by jenkinsci.

the class SupportAbstractItemActionTest method generateFreestyleBundleDefaultsAndCheckContent.

/*
     * Integration test that simulates the user action of clicking the button to generate the bundle from a Freestyle job.
     */
@Test
public void generateFreestyleBundleDefaultsAndCheckContent() throws Exception {
    Folder folder = j.createProject(Folder.class, "testFolder");
    FreeStyleProject p = folder.createProject(FreeStyleProject.class, "testFreestyle");
    QueueTaskFuture<FreeStyleBuild> freeStyleBuildQueueTaskFuture = p.scheduleBuild2(0);
    FreeStyleBuild fBuild = freeStyleBuildQueueTaskFuture.waitForStart();
    j.waitForCompletion(fBuild);
    // Check that the generation does not show any warnings
    ZipFile z = SupportTestUtils.generateBundleWithoutWarnings(p.getUrl(), new SupportAbstractItemAction(j.jenkins.getItemByFullName("testFolder/testFreestyle", FreeStyleProject.class)), SupportPlugin.class, j.createWebClient());
    String itemEntryPrefix = "items/testFolder/jobs/testFreestyle";
    assertNotNull(z.getEntry("manifest.md"));
    assertNotNull(z.getEntry(itemEntryPrefix + "/config.xml"));
    assertNotNull(z.getEntry(itemEntryPrefix + "/nextBuildNumber"));
    assertNotNull(z.getEntry(itemEntryPrefix + "/builds/1/build.xml"));
    assertNotNull(z.getEntry(itemEntryPrefix + "/builds/1/log"));
}
Also used : ZipFile(java.util.zip.ZipFile) FreeStyleBuild(hudson.model.FreeStyleBuild) Folder(com.cloudbees.hudson.plugins.folder.Folder) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 4 with Folder

use of com.cloudbees.hudson.plugins.folder.Folder in project gogs-webhook-plugin by jenkinsci.

the class GogsWebHookPluginsTest method testCloudBeesFolder.

@Test
public void testCloudBeesFolder() throws Exception {
    Folder folder = createFolder(FOLDERNAME);
    FreeStyleProject project = folder.createProject(FreeStyleProject.class, PROJECTNAME);
    Job job = GogsUtils.find(FOLDERNAME + "/" + PROJECTNAME, Job.class);
    assertEquals("Couldn't find " + FOLDERNAME + "/" + PROJECTNAME, job, project);
}
Also used : Folder(com.cloudbees.hudson.plugins.folder.Folder) FreeStyleProject(hudson.model.FreeStyleProject) Job(hudson.model.Job) Test(org.junit.Test)

Example 5 with Folder

use of com.cloudbees.hudson.plugins.folder.Folder in project configuration-as-code-plugin by jenkinsci.

the class RoleStrategyTest method shouldReadRolesCorrectly.

@Test
@Issue("Issue #48")
@ConfiguredWithCode("RoleStrategy1.yml")
public void shouldReadRolesCorrectly() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    User admin = User.getById("admin", false);
    User user1 = User.getById("user1", false);
    User user2 = User.getById("user2", true);
    Computer agent1 = j.jenkins.getComputer("agent1");
    Computer agent2 = j.jenkins.getComputer("agent2");
    Folder folderA = j.jenkins.createProject(Folder.class, "A");
    FreeStyleProject jobA1 = folderA.createProject(FreeStyleProject.class, "1");
    Folder folderB = j.jenkins.createProject(Folder.class, "B");
    folderB.createProject(FreeStyleProject.class, "2");
    AuthorizationStrategy s = j.jenkins.getAuthorizationStrategy();
    assertThat("Authorization Strategy has been read incorrectly", s, instanceOf(RoleBasedAuthorizationStrategy.class));
    RoleBasedAuthorizationStrategy rbas = (RoleBasedAuthorizationStrategy) s;
    Map<Role, Set<String>> globalRoles = rbas.getGrantedRoles(RoleType.Global);
    assertThat(globalRoles.size(), equalTo(2));
    // Admin has configuration access
    assertHasPermission(admin, j.jenkins, Jenkins.ADMINISTER, Jenkins.READ);
    assertHasPermission(user1, j.jenkins, Jenkins.READ);
    assertHasNoPermission(user1, j.jenkins, Jenkins.ADMINISTER);
    // Folder A is restricted to admin
    assertHasPermission(admin, folderA, Item.CONFIGURE);
    assertHasPermission(user1, folderA, Item.READ, Item.DISCOVER);
    assertHasNoPermission(user1, folderA, Item.CONFIGURE, Item.DELETE, Item.BUILD);
    // But they have access to jobs in Folder A
    assertHasPermission(admin, folderA, Item.CONFIGURE, Item.CANCEL);
    assertHasPermission(user1, jobA1, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    assertHasPermission(user2, jobA1, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    assertHasNoPermission(user1, folderA, Item.CANCEL);
    // FolderB is editable by user2, but he cannot delete it
    assertHasPermission(user2, folderB, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD);
    assertHasNoPermission(user2, folderB, Item.DELETE);
    assertHasNoPermission(user1, folderB, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    // Only user1 can run on agent1, but he still cannot configure it
    assertHasPermission(admin, agent1, Computer.CONFIGURE, Computer.DELETE, Computer.BUILD);
    assertHasPermission(user1, agent1, Computer.BUILD);
    assertHasNoPermission(user1, agent1, Computer.CONFIGURE, Computer.DISCONNECT);
    // Same user still cannot build on agent2
    assertHasNoPermission(user1, agent2, Computer.BUILD);
}
Also used : Role(com.michelin.cio.hudson.plugins.rolestrategy.Role) AuthorizationStrategy(hudson.security.AuthorizationStrategy) RoleBasedAuthorizationStrategy(com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy) User(hudson.model.User) Set(java.util.Set) Computer(hudson.model.Computer) Folder(com.cloudbees.hudson.plugins.folder.Folder) FreeStyleProject(hudson.model.FreeStyleProject) RoleBasedAuthorizationStrategy(com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Aggregations

Folder (com.cloudbees.hudson.plugins.folder.Folder)12 Test (org.junit.Test)10 AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)5 CredentialsStore (com.cloudbees.plugins.credentials.CredentialsStore)5 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)5 FreeStyleProject (hudson.model.FreeStyleProject)4 ArrayList (java.util.ArrayList)4 AWSCredentialsImpl (com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsImpl)3 AmazonWebServicesCredentials (com.cloudbees.jenkins.plugins.awscredentials.AmazonWebServicesCredentials)3 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)3 UsernamePasswordCredentialsImpl (com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl)3 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)3 Role (com.michelin.cio.hudson.plugins.rolestrategy.Role)2 RoleBasedAuthorizationStrategy (com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy)2 Computer (hudson.model.Computer)2 Job (hudson.model.Job)2 User (hudson.model.User)2 AuthorizationStrategy (hudson.security.AuthorizationStrategy)2 ListBoxModel (hudson.util.ListBoxModel)2 Set (java.util.Set)2