1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.rest.setup; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
import static org.mockito.Mockito.mock; |
38 |
|
|
39 |
|
import info.magnolia.cms.security.MgnlRoleManager; |
40 |
|
import info.magnolia.cms.security.MgnlUserManager; |
41 |
|
import info.magnolia.cms.security.SecuritySupport; |
42 |
|
import info.magnolia.cms.security.SecuritySupportImpl; |
43 |
|
import info.magnolia.cms.security.User; |
44 |
|
import info.magnolia.context.MgnlContext; |
45 |
|
import info.magnolia.init.MagnoliaConfigurationProperties; |
46 |
|
import info.magnolia.jcr.util.NodeNameHelper; |
47 |
|
import info.magnolia.jcr.util.NodeTypes; |
48 |
|
import info.magnolia.module.delta.TaskExecutionException; |
49 |
|
import info.magnolia.objectfactory.Components; |
50 |
|
import info.magnolia.repository.RepositoryConstants; |
51 |
|
import info.magnolia.test.ComponentsTestUtil; |
52 |
|
import info.magnolia.test.RepositoryTestCase; |
53 |
|
|
54 |
|
import javax.jcr.AccessDeniedException; |
55 |
|
import javax.jcr.Session; |
56 |
|
|
57 |
|
import org.junit.After; |
58 |
|
import org.junit.Before; |
59 |
|
import org.junit.Test; |
60 |
|
|
61 |
|
import com.google.common.collect.ImmutableMap; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 4 |
Complexity Density: 0.16 |
|
63 |
|
public class RemoveRoleFromUserTaskTest extends RepositoryTestCase { |
64 |
|
|
65 |
|
private MgnlUserManager userManager; |
66 |
|
private MgnlRoleManager roleManager; |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
68 |
1 |
@Before... |
69 |
|
@Override |
70 |
|
public void setUp() throws Exception { |
71 |
1 |
super.setUp(); |
72 |
1 |
Session session = MgnlContext.getJCRSession(RepositoryConstants.USERS); |
73 |
1 |
session.getRootNode().addNode("admin"); |
74 |
1 |
Session sessionRoles = MgnlContext.getJCRSession(RepositoryConstants.USER_ROLES); |
75 |
1 |
sessionRoles.getRootNode().addNode("testFolder", NodeTypes.Folder.NAME); |
76 |
1 |
NodeNameHelper nodeNameHelper = new NodeNameHelper(mock(MagnoliaConfigurationProperties.class)); |
77 |
1 |
userManager = new MgnlUserManager(nodeNameHelper); |
78 |
1 |
roleManager = new MgnlRoleManager(nodeNameHelper) { |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
79 |
1 |
@Override... |
80 |
|
protected void validateRoleName(String name) { |
81 |
|
|
82 |
|
} |
83 |
|
}; |
84 |
1 |
userManager.setRealmName("admin"); |
85 |
1 |
ComponentsTestUtil.setImplementation(SecuritySupport.class, SecuritySupportImpl.class); |
86 |
1 |
SecuritySupportImpl securitySupport = (SecuritySupportImpl) Components.getComponent(SecuritySupport.class); |
87 |
1 |
securitySupport.setRoleManager(roleManager); |
88 |
1 |
securitySupport.setUserManagers(ImmutableMap.of("admin", userManager)); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
91 |
1 |
@After... |
92 |
|
@Override |
93 |
|
public void tearDown() throws Exception { |
94 |
1 |
super.tearDown(); |
95 |
1 |
ComponentsTestUtil.clear(); |
96 |
1 |
MgnlContext.setInstance(null); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
99 |
1 |
@Test... |
100 |
|
public void removeRoleFromUser() throws AccessDeniedException, TaskExecutionException { |
101 |
|
|
102 |
1 |
User user = userManager.createUser("test", "test"); |
103 |
1 |
roleManager.createRole("rest-editor"); |
104 |
1 |
userManager.addRole(user, "rest-editor"); |
105 |
|
|
106 |
|
|
107 |
1 |
user = userManager.getUser("test"); |
108 |
|
|
109 |
1 |
assertTrue(user.hasRole("rest-editor")); |
110 |
1 |
RemoveRoleFromUserTask task = new RemoveRoleFromUserTask("Test Task", "test", "rest-editor"); |
111 |
|
|
112 |
1 |
task.execute(null); |
113 |
|
|
114 |
|
|
115 |
1 |
user = userManager.getUser("test"); |
116 |
|
|
117 |
|
|
118 |
1 |
assertFalse(user.hasRole("rest-editor")); |
119 |
|
} |
120 |
|
} |