Search in sources :

Example 1 with HudsonPrivateSecurityRealm

use of hudson.security.HudsonPrivateSecurityRealm 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 2 with HudsonPrivateSecurityRealm

use of hudson.security.HudsonPrivateSecurityRealm in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testMultiBranchPipelineBranchSecurePermissions.

@Test
public void testMultiBranchPipelineBranchSecurePermissions() throws IOException, ExecutionException, InterruptedException {
    j.jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(false));
    j.jenkins.setAuthorizationStrategy(new LegacyAuthorizationStrategy());
    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.assertFalse(permissions.get("create"));
    Assert.assertTrue(permissions.get("read"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));
    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/branches/master/");
    permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertFalse(permissions.get("create"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));
    Assert.assertTrue(permissions.get("read"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) LegacyAuthorizationStrategy(hudson.security.LegacyAuthorizationStrategy) 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) HudsonPrivateSecurityRealm(hudson.security.HudsonPrivateSecurityRealm) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)2 HudsonPrivateSecurityRealm (hudson.security.HudsonPrivateSecurityRealm)2 LegacyAuthorizationStrategy (hudson.security.LegacyAuthorizationStrategy)2 Map (java.util.Map)2 Test (org.junit.Test)2 MockFolder (org.jvnet.hudson.test.MockFolder)2 FreeStyleProject (hudson.model.FreeStyleProject)1 Project (hudson.model.Project)1 BranchSource (jenkins.branch.BranchSource)1 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)1 GitSCMSource (jenkins.plugins.git.GitSCMSource)1 SCMSource (jenkins.scm.api.SCMSource)1 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)1