-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2872c41
commit 850a20a
Showing
3 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...est/java/com/michelin/cio/hudson/plugins/rolestrategy/GrantingDisabledPermissionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.michelin.cio.hudson.plugins.rolestrategy; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
|
||
import hudson.model.Item; | ||
import hudson.model.Job; | ||
import hudson.model.User; | ||
import hudson.security.ACL; | ||
import hudson.security.ACLContext; | ||
import hudson.security.HudsonPrivateSecurityRealm; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import jenkins.model.Jenkins; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class GrantingDisabledPermissionTest { | ||
|
||
@Rule | ||
public JenkinsRule r = new JenkinsRule(); | ||
|
||
@Test | ||
public void grantDisabledPermissionTest() throws Exception { | ||
HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(true, false, null); | ||
realm.createAccount("admin", "admin"); | ||
realm.createAccount("alice", "alice"); | ||
r.jenkins.setSecurityRealm(realm); | ||
|
||
RoleMap roleMap = new RoleMap(); | ||
Role adminRole = new Role("admin-role", new HashSet<>(Collections.singletonList(Jenkins.ADMINISTER))); | ||
roleMap.addRole(adminRole); | ||
Role manage = new Role("manage-role", new HashSet<>(Collections.singletonList(Jenkins.MANAGE))); | ||
roleMap.addRole(manage); | ||
roleMap.assignRole(adminRole, "admin"); | ||
roleMap.assignRole(manage, "alice"); | ||
|
||
Map<String, RoleMap> constructorArg = new HashMap<>(); | ||
constructorArg.put("globalRoles", roleMap); | ||
|
||
r.jenkins.setAuthorizationStrategy(new RoleBasedAuthorizationStrategy(constructorArg)); | ||
|
||
try (ACLContext ctx = ACL.as2(User.get("alice").impersonate2())) { | ||
assertFalse(Jenkins.get().hasPermission(Jenkins.MANAGE)); | ||
} | ||
} | ||
} |