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 info.magnolia.test.hamcrest.NodeMatchers.*; |
37 |
|
import static org.hamcrest.CoreMatchers.allOf; |
38 |
|
import static org.junit.Assert.*; |
39 |
|
import static org.mockito.Mockito.mock; |
40 |
|
|
41 |
|
import info.magnolia.cms.security.MgnlGroupManager; |
42 |
|
import info.magnolia.cms.security.MgnlRoleManager; |
43 |
|
import info.magnolia.cms.security.MgnlUserManager; |
44 |
|
import info.magnolia.cms.security.Realm; |
45 |
|
import info.magnolia.cms.security.SecuritySupport; |
46 |
|
import info.magnolia.cms.security.SecuritySupportImpl; |
47 |
|
import info.magnolia.cms.security.User; |
48 |
|
import info.magnolia.context.MgnlContext; |
49 |
|
import info.magnolia.init.MagnoliaConfigurationProperties; |
50 |
|
import info.magnolia.jcr.util.NodeNameHelper; |
51 |
|
import info.magnolia.jcr.util.NodeTypes; |
52 |
|
import info.magnolia.jcr.util.NodeUtil; |
53 |
|
import info.magnolia.jcr.util.PropertyUtil; |
54 |
|
import info.magnolia.module.ModuleManagementException; |
55 |
|
import info.magnolia.module.ModuleVersionHandler; |
56 |
|
import info.magnolia.module.ModuleVersionHandlerTestCase; |
57 |
|
import info.magnolia.module.model.Version; |
58 |
|
import info.magnolia.repository.RepositoryConstants; |
59 |
|
import info.magnolia.test.ComponentsTestUtil; |
60 |
|
|
61 |
|
import java.util.Arrays; |
62 |
|
import java.util.List; |
63 |
|
|
64 |
|
import javax.jcr.Node; |
65 |
|
import javax.jcr.RepositoryException; |
66 |
|
import javax.jcr.Session; |
67 |
|
|
68 |
|
import org.junit.Before; |
69 |
|
import org.junit.Test; |
70 |
|
|
71 |
|
|
72 |
|
@link |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (72) |
Complexity: 7 |
Complexity Density: 0.11 |
|
74 |
|
public class RestIntegrationModuleVersionHandlerTest extends ModuleVersionHandlerTestCase { |
75 |
|
|
76 |
|
private SecuritySupportImpl securitySupport; |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
3 |
@Override... |
79 |
|
protected String getModuleDescriptorPath() { |
80 |
3 |
return "/META-INF/magnolia/rest-integration.xml"; |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
3 |
@Override... |
84 |
|
protected List<String> getModuleDescriptorPathsForTests() { |
85 |
3 |
return Arrays.asList( |
86 |
|
"/META-INF/magnolia/core.xml" |
87 |
|
); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
3 |
@Override... |
91 |
|
protected ModuleVersionHandler newModuleVersionHandlerForTests() { |
92 |
3 |
return new RestIntegrationModuleVersionHandler(); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
|
95 |
3 |
@Override... |
96 |
|
@Before |
97 |
|
public void setUp() throws Exception { |
98 |
3 |
super.setUp(); |
99 |
|
|
100 |
3 |
Session session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); |
101 |
|
|
102 |
|
|
103 |
3 |
Node server = NodeUtil.createPath(session.getRootNode(), "/server", NodeTypes.ContentNode.NAME); |
104 |
3 |
server.setProperty("admin", ""); |
105 |
3 |
NodeUtil.createPath(server, "/filters/servlets", NodeTypes.ContentNode.NAME); |
106 |
|
|
107 |
3 |
Session userSession = MgnlContext.getJCRSession(RepositoryConstants.USERS); |
108 |
3 |
NodeUtil.createPath(userSession.getRootNode(), "/system", NodeTypes.Folder.NAME); |
109 |
|
|
110 |
3 |
Session roleSession = MgnlContext.getJCRSession(RepositoryConstants.USER_ROLES); |
111 |
3 |
NodeUtil.createPath(roleSession.getRootNode(), "/security-base", NodeTypes.Role.NAME); |
112 |
|
|
113 |
3 |
NodeNameHelper nodeNameHelper = new NodeNameHelper(mock(MagnoliaConfigurationProperties.class)); |
114 |
|
|
115 |
3 |
MgnlUserManager mgnlUserManager = new MgnlUserManager(nodeNameHelper); |
116 |
3 |
mgnlUserManager.setRealmName(Realm.REALM_ALL.getName()); |
117 |
3 |
mgnlUserManager.setAllowCrossRealmDuplicateNames(true); |
118 |
|
|
119 |
|
|
120 |
3 |
mgnlUserManager.createUser("/system", "superuser", "superuser"); |
121 |
3 |
mgnlUserManager.createUser("/system", "anonymous", ""); |
122 |
|
|
123 |
|
|
124 |
3 |
securitySupport = new SecuritySupportImpl(); |
125 |
3 |
securitySupport.addUserManager(Realm.REALM_ALL.getName(), mgnlUserManager); |
126 |
3 |
securitySupport.setRoleManager(new MgnlRoleManager(nodeNameHelper)); |
127 |
3 |
securitySupport.setGroupManager(new MgnlGroupManager(nodeNameHelper)); |
128 |
3 |
ComponentsTestUtil.setInstance(SecuritySupport.class, securitySupport); |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
131 |
1 |
@Test... |
132 |
|
public void basicInstallSuperuserHasRoleRest() throws Exception { |
133 |
|
|
134 |
|
|
135 |
1 |
Session rolesSession = MgnlContext.getJCRSession(RepositoryConstants.USER_ROLES); |
136 |
1 |
User superuser = securitySupport.getUserManager().getUser("superuser"); |
137 |
1 |
User anonymous = securitySupport.getUserManager().getUser("anonymous"); |
138 |
|
|
139 |
1 |
assertFalse(superuser.hasRole("rest-admin")); |
140 |
1 |
assertFalse(anonymous.hasRole("rest-anonymous")); |
141 |
|
|
142 |
|
|
143 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(null); |
144 |
|
|
145 |
|
|
146 |
1 |
superuser = securitySupport.getUserManager().getUser("superuser"); |
147 |
1 |
anonymous = securitySupport.getUserManager().getUser("anonymous"); |
148 |
|
|
149 |
|
|
150 |
1 |
assertThat(rolesSession.getNode("/rest-editor"), nodeName("rest-editor")); |
151 |
1 |
assertThat(rolesSession.getNode("/rest-admin"), nodeName("rest-admin")); |
152 |
1 |
assertThat(rolesSession.getNode("/rest-anonymous"), nodeName("rest-anonymous")); |
153 |
|
|
154 |
1 |
assertTrue(superuser.hasRole("rest-admin")); |
155 |
1 |
assertTrue(anonymous.hasRole("rest-anonymous")); |
156 |
|
} |
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
158 |
1 |
@Test... |
159 |
|
public void updateFrom123ChangeRestEditorRoleToRestAdminRole() throws RepositoryException, ModuleManagementException { |
160 |
|
|
161 |
1 |
Session rolesSession = MgnlContext.getJCRSession(RepositoryConstants.USER_ROLES); |
162 |
1 |
NodeUtil.createPath(rolesSession.getRootNode(), "/rest", NodeTypes.Role.NAME); |
163 |
1 |
User superuser = securitySupport.getUserManager().getUser("superuser"); |
164 |
1 |
User anonymous = securitySupport.getUserManager().getUser("anonymous"); |
165 |
|
|
166 |
1 |
assertFalse(superuser.hasRole("rest-admin")); |
167 |
1 |
assertFalse(anonymous.hasRole("rest-anonymous")); |
168 |
|
|
169 |
|
|
170 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("1.2.3")); |
171 |
|
|
172 |
|
|
173 |
1 |
superuser = securitySupport.getUserManager().getUser("superuser"); |
174 |
1 |
anonymous = securitySupport.getUserManager().getUser("anonymous"); |
175 |
|
|
176 |
|
|
177 |
1 |
assertThat(rolesSession.getNode("/rest-editor"), nodeName("rest-editor")); |
178 |
1 |
assertThat(rolesSession.getNode("/rest-admin"), nodeName("rest-admin")); |
179 |
1 |
assertThat(rolesSession.getNode("/rest-anonymous"), nodeName("rest-anonymous")); |
180 |
|
|
181 |
1 |
assertTrue(superuser.hasRole("rest-admin")); |
182 |
1 |
assertFalse(superuser.hasRole("rest-editor")); |
183 |
1 |
assertFalse(superuser.hasRole("rest-anonymous")); |
184 |
1 |
assertTrue(anonymous.hasRole("rest-anonymous")); |
185 |
1 |
assertFalse(anonymous.hasRole("rest-admin")); |
186 |
|
} |
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
188 |
1 |
@Test... |
189 |
|
public void updateFrom12UpdatesRestEditorRole() throws Exception { |
190 |
|
|
191 |
1 |
Session rolesSession = MgnlContext.getJCRSession(RepositoryConstants.USER_ROLES); |
192 |
1 |
Node restNode = NodeUtil.createPath(rolesSession.getRootNode(), "/rest", NodeTypes.Role.NAME); |
193 |
1 |
PropertyUtil.setProperty(restNode, "description", "test"); |
194 |
1 |
PropertyUtil.setProperty(restNode, "title", "test"); |
195 |
|
|
196 |
1 |
Node aclRole = NodeUtil.createPath(restNode, "acl_userroles/0", NodeTypes.ContentNode.NAME); |
197 |
1 |
Node aclUri = NodeUtil.createPath(restNode, "acl_uri/0", NodeTypes.ContentNode.NAME); |
198 |
|
|
199 |
1 |
aclRole.setProperty("path", "/rest"); |
200 |
1 |
aclUri.setProperty("path", "/.rest*"); |
201 |
|
|
202 |
|
|
203 |
1 |
executeUpdatesAsIfTheCurrentlyInstalledVersionWas(Version.parseVersion("1.2.3")); |
204 |
|
|
205 |
|
|
206 |
1 |
assertThat(restNode, allOf( |
207 |
|
nodeName("rest-editor"), |
208 |
|
hasProperty("description", "This role grants GET/POST permissions to REST services APIs (nodes, properties), for a limited set of workspaces."), |
209 |
|
hasProperty("title", "REST Editor"))); |
210 |
|
|
211 |
1 |
assertThat(aclRole, hasProperty("path", "/rest-editor")); |
212 |
1 |
assertThat(aclUri, hasProperty("path", "/.rest/*")); |
213 |
|
} |
214 |
|
} |