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.assertTrue; |
37 |
|
import static org.mockito.Mockito.mock; |
38 |
|
|
39 |
|
import info.magnolia.cms.security.MgnlRoleManager; |
40 |
|
import info.magnolia.cms.security.SecuritySupport; |
41 |
|
import info.magnolia.cms.security.SecuritySupportImpl; |
42 |
|
import info.magnolia.context.MgnlContext; |
43 |
|
import info.magnolia.init.MagnoliaConfigurationProperties; |
44 |
|
import info.magnolia.jcr.util.NodeNameHelper; |
45 |
|
import info.magnolia.jcr.util.NodeTypes; |
46 |
|
import info.magnolia.jcr.util.NodeUtil; |
47 |
|
import info.magnolia.module.ModuleVersionHandler; |
48 |
|
import info.magnolia.module.ModuleVersionHandlerTestCase; |
49 |
|
import info.magnolia.repository.RepositoryConstants; |
50 |
|
import info.magnolia.test.ComponentsTestUtil; |
51 |
|
|
52 |
|
import java.util.Arrays; |
53 |
|
import java.util.List; |
54 |
|
|
55 |
|
import javax.jcr.Node; |
56 |
|
import javax.jcr.NodeIterator; |
57 |
|
import javax.jcr.RepositoryException; |
58 |
|
import javax.jcr.Session; |
59 |
|
|
60 |
|
import org.junit.Before; |
61 |
|
import org.junit.Test; |
62 |
|
|
63 |
|
|
64 |
|
@link |
65 |
|
|
|
|
| 91.4% |
Uncovered Elements: 3 (35) |
Complexity: 9 |
Complexity Density: 0.36 |
|
66 |
|
public class RestContentDeliveryModuleVersionHandlerTest extends ModuleVersionHandlerTestCase { |
67 |
|
|
68 |
|
private SecuritySupportImpl securitySupport; |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
1 |
@Override... |
71 |
|
protected String getModuleDescriptorPath() { |
72 |
1 |
return "/META-INF/magnolia/rest-content-delivery.xml"; |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
1 |
@Override... |
76 |
|
protected List<String> getModuleDescriptorPathsForTests() { |
77 |
1 |
return Arrays.asList( |
78 |
|
"/META-INF/magnolia/core.xml" |
79 |
|
); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
1 |
@Override... |
83 |
|
protected ModuleVersionHandler newModuleVersionHandlerForTests() { |
84 |
1 |
return new RestContentDeliveryModuleVersionHandler(); |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
87 |
1 |
@Override... |
88 |
|
@Before |
89 |
|
public void setUp() throws Exception { |
90 |
1 |
super.setUp(); |
91 |
1 |
Session session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
92 |
|
|
93 |
|
|
94 |
1 |
Node server = NodeUtil.createPath(session.getRootNode(), "/server", NodeTypes.ContentNode.NAME); |
95 |
1 |
server.setProperty("admin", ""); |
96 |
|
|
97 |
1 |
NodeNameHelper nodeNameHelper = new NodeNameHelper(mock(MagnoliaConfigurationProperties.class)); |
98 |
|
|
99 |
|
|
100 |
1 |
securitySupport = new SecuritySupportImpl(); |
101 |
1 |
securitySupport.setRoleManager(new MgnlRoleManager(nodeNameHelper)); |
102 |
1 |
ComponentsTestUtil.setInstance(SecuritySupport.class, securitySupport); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
105 |
1 |
@Test... |
106 |
|
public void basicInstallRestEditorRoleGrantedPermission() throws Exception { |
107 |
|
|
108 |
1 |
Session rolesSession = MgnlContext.getJCRSession(RepositoryConstants.USER_ROLES); |
109 |
1 |
NodeUtil.createPath(rolesSession.getRootNode(), "/rest-editor", NodeTypes.Role.NAME); |
110 |
1 |
NodeUtil.createPath(rolesSession.getRootNode(), "/rest-anonymous", NodeTypes.Role.NAME); |
111 |
|
|
112 |
|
|
113 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
114 |
|
|
115 |
|
|
116 |
1 |
Node restEditor = rolesSession.getNode("/rest-editor/acl_uri"); |
117 |
1 |
Node restAnonymous = rolesSession.getNode("/rest-anonymous/acl_uri"); |
118 |
|
|
119 |
1 |
assertTrue(verifyRoleNode(restEditor)); |
120 |
1 |
assertTrue(verifyRoleNode(restAnonymous)); |
121 |
|
|
122 |
|
} |
123 |
|
|
|
|
| 70% |
Uncovered Elements: 3 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
124 |
2 |
private boolean verifyRoleNode(Node roleNode) throws RepositoryException {... |
125 |
2 |
NodeIterator restEditorNodes = roleNode.getNodes(); |
126 |
2 |
while (restEditorNodes.hasNext()) { |
127 |
2 |
Node node = (Node) restEditorNodes.next(); |
128 |
2 |
if ("/.rest/delivery/*".equals(node.getProperty("path").getString()) && new Long(8).equals(node.getProperty("permissions").getLong())) { |
129 |
2 |
return true; |
130 |
|
} |
131 |
|
} |
132 |
0 |
return false; |
133 |
|
} |
134 |
|
|
135 |
|
} |