This is an automated email from the ASF dual-hosted git repository.
angela pushed a commit to branch SLING-9692
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git
The following commit(s) were added to refs/heads/SLING-9692 by this push:
new 9c926b1 SLING-9692 : Add support for principal-based access control
entries (tests)
9c926b1 is described below
commit 9c926b19ecab70bdf94c9d2112540276a40a497d
Author: angela <[email protected]>
AuthorDate: Fri Jan 15 11:43:55 2021 +0100
SLING-9692 : Add support for principal-based access control entries (tests)
---
.../feature/cpconverter/handlers/ParseResult.java | 16 ++++++
.../RepPrincipalPolicyEntryHandlerTest.java | 60 ++++++++++++++++++----
2 files changed, 66 insertions(+), 10 deletions(-)
diff --git
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ParseResult.java
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ParseResult.java
index 3952f3a..2a8c75b 100644
---
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ParseResult.java
+++
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ParseResult.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
package org.apache.sling.feature.cpconverter.handlers;
import org.apache.sling.feature.Extension;
diff --git
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
index 1fb2495..11dbe1f 100644
---
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
+++
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
@@ -127,16 +127,19 @@ public final class RepPrincipalPolicyEntryHandlerTest {
}
@Test
- public void parseOtherUserHomeSubtree() throws Exception {
- Extension repoinitExtension = parseAndSetRepoinit("service4",
"random4").getRepoinitExtension();
+ public void parseOtherUserHomeMissing() throws Exception {
+ SystemUser systemUser4 = createSystemUser("service4", "random4");
+
+ Extension repoinitExtension =
parseAndSetRepoinit(getPolicyPath(systemUser4),
systemUser4).getRepoinitExtension();
assertNotNull(repoinitExtension);
assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
String expected =
"create service user service4 with path
/home/users/system/services" + System.lineSeparator() +
- "set principal ACL for service4\n" +
- "allow jcr:read,rep:userManagement on home(service3)\n" +
- "end\n";
+ "set principal ACL for service4" + System.lineSeparator() +
+ // since service3 is not known to the AclManager it treats the
effective path as a regular node.
+ "allow jcr:read,rep:userManagement on
/home/users/system/services/random3" + System.lineSeparator() +
+ "end"+ System.lineSeparator();
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -146,15 +149,52 @@ public final class RepPrincipalPolicyEntryHandlerTest {
assertFalse(operations.isEmpty());
}
- private ParseResult parseAndSetRepoinit(@NotNull String systemUsersName,
@NotNull String nodeName) throws Exception {
+ @Test
+ public void parseOtherUserHome() throws Exception {
+ SystemUser systemUser3 = createSystemUser("service3", "random3");
+ SystemUser systemUser4 = createSystemUser("service4", "random4");
+
+ Extension repoinitExtension =
parseAndSetRepoinit(getPolicyPath(systemUser4), systemUser4,
systemUser3).getRepoinitExtension();
+ assertNotNull(repoinitExtension);
+ assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
+
+ String expected =
+ "create service user service4 with path
/home/users/system/services" + System.lineSeparator() +
+ "create service user service3 with path
/home/users/system/services" + System.lineSeparator() +
+ "set principal ACL for service4" + System.lineSeparator() +
+ "allow jcr:read,rep:userManagement on home(service3)" +
System.lineSeparator() +
+ "end"+ System.lineSeparator();
+
+ String actual = repoinitExtension.getText();
+ assertEquals(expected, actual);
+
+ RepoInitParser repoInitParser = new RepoInitParserService();
+ List<Operation> operations = repoInitParser.parse(new
StringReader(actual));
+ assertFalse(operations.isEmpty());
+ }
+
+ @NotNull
+ private static SystemUser createSystemUser(@NotNull String
systemUsersName, @NotNull String nodeName) {
RepoPath repoPath = new
RepoPath("/home/users/system/services/"+nodeName);
- return parseAndSetRepoinit(new SystemUser(systemUsersName, repoPath,
new RepoPath("/home/users/system/services")));
+ return new SystemUser(systemUsersName, repoPath, new
RepoPath("/home/users/system/services"));
+ }
+
+ @NotNull
+ private static String getPolicyPath(@NotNull SystemUser systemUser) {
+ return "/jcr_root"+systemUser.getPath().toString() +
"/_rep_principalPolicy.xml";
+ }
+
+ private ParseResult parseAndSetRepoinit(@NotNull String systemUsersName,
@NotNull String nodeName) throws Exception {
+ SystemUser systemUser = createSystemUser(systemUsersName, nodeName);
+
+ return parseAndSetRepoinit(getPolicyPath(systemUser), systemUser);
}
- private ParseResult parseAndSetRepoinit(SystemUser systemUser) throws
Exception {
- String path = "/jcr_root"+systemUser.getPath().toString() +
"/_rep_principalPolicy.xml";
+ private ParseResult parseAndSetRepoinit(@NotNull String path, @NotNull
SystemUser... systemUsers) throws Exception {
AclManager aclManager = new DefaultAclManager();
- aclManager.addSystemUser(systemUser);
+ for (SystemUser systemUser : systemUsers) {
+ aclManager.addSystemUser(systemUser);
+ }
InputStream is = getClass().getResourceAsStream(path.substring(1));
ByteArrayOutputStream baos = new ByteArrayOutputStream();