You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2021/04/07 11:06:39 UTC
[sling-org-apache-sling-feature-cpconverter] 01/01: SLING-10274:
use the repoinit parser to normalize line separators
This is an automated email from the ASF dual-hosted git repository.
pauls pushed a commit to branch SLING-10274
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git
commit c5b9e8514cb9e210dad41f8c9863e0ab990e9f0a
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Wed Apr 7 13:06:17 2021 +0200
SLING-10274: use the repoinit parser to normalize line separators
---
.../cpconverter/accesscontrol/AclManager.java | 3 +-
.../accesscontrol/DefaultAclManager.java | 2 +-
.../features/DefaultFeaturesManager.java | 17 +++++++-
.../cpconverter/features/FeaturesManager.java | 3 +-
.../ContentPackage2FeatureModelConverterTest.java | 5 ++-
.../org/apache/sling/feature/cpconverter/Util.java | 46 ++++++++++++++++++++++
.../cpconverter/accesscontrol/AclManagerTest.java | 39 +++++++++---------
.../accesscontrol/EnforcePrincipalBasedTest.java | 45 ++++++++++-----------
.../handlers/ConfigurationEntryHandlerTest.java | 5 ++-
.../handlers/PrivilegesHandlerTest.java | 6 +--
.../handlers/RepPolicyEntryHandlerTest.java | 21 +++++-----
.../RepPrincipalPolicyEntryHandlerTest.java | 17 ++++----
.../handlers/RepRepoPolicyEntryHandlerTest.java | 5 ++-
.../feature/cpconverter/handlers/RepoInitTest.java | 27 +++++++------
.../handlers/UsersEntryHandlerTest.java | 3 +-
.../handlers/META-INF/vault/privileges.xml | 2 +-
16 files changed, 158 insertions(+), 88 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManager.java b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManager.java
index 8d5ceeb..3f4a56d 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManager.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManager.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.apache.jackrabbit.vault.fs.spi.PrivilegeDefinitions;
import org.apache.sling.feature.cpconverter.features.FeaturesManager;
import org.apache.sling.feature.cpconverter.vltpkg.VaultPackageAssembler;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -39,7 +40,7 @@ public interface AclManager {
boolean addAcl(@NotNull String systemUser, @NotNull AccessControlEntry acl);
- void addRepoinitExtension(@NotNull List<VaultPackageAssembler> packageAssemblers, @NotNull FeaturesManager featureManager);
+ void addRepoinitExtension(@NotNull List<VaultPackageAssembler> packageAssemblers, @NotNull FeaturesManager featureManager) throws RepoInitParsingException;
void addRepoinitExtention(@Nullable String repoInitText, @Nullable String runMode, @NotNull FeaturesManager featuresManager);
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
index f681e6e..9cd6bae 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
@@ -145,7 +145,7 @@ public class DefaultAclManager implements AclManager, EnforceInfo {
}
@Override
- public void addRepoinitExtension(@NotNull List<VaultPackageAssembler> packageAssemblers, @NotNull FeaturesManager featureManager) {
+ public void addRepoinitExtension(@NotNull List<VaultPackageAssembler> packageAssemblers, @NotNull FeaturesManager featureManager) throws RepoInitParsingException {
try (Formatter formatter = new Formatter()) {
if (privilegeDefinitions != null) {
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java b/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java
index 35090d5..3c4a97b 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java
@@ -22,6 +22,7 @@ import static org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelCo
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.StringReader;
import java.security.acl.Acl;
import java.util.*;
import java.util.Map.Entry;
@@ -43,6 +44,10 @@ import org.apache.sling.feature.extension.apiregions.api.ApiExport;
import org.apache.sling.feature.extension.apiregions.api.ApiRegion;
import org.apache.sling.feature.extension.apiregions.api.ApiRegions;
import org.apache.sling.feature.io.json.FeatureJSONWriter;
+import org.apache.sling.repoinit.parser.RepoInitParser;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
+import org.apache.sling.repoinit.parser.impl.RepoInitParserService;
+import org.apache.sling.repoinit.parser.operations.Operation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.framework.Constants;
@@ -437,17 +442,25 @@ public class DefaultFeaturesManager implements FeaturesManager {
}
@Override
- public void addOrAppendRepoInitExtension(@NotNull String text, @Nullable String runMode) {
+ public void addOrAppendRepoInitExtension(@NotNull String text, @Nullable String runMode) throws RepoInitParsingException {
logger.info("Adding/Appending RepoInitExtension for runMode: {}", runMode );
Extension repoInitExtension = getRunMode(runMode).getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT);
+ try (Formatter formatter = new Formatter()) {
+ RepoInitParser parser = new RepoInitParserService();
+ List<Operation> operations = parser.parse(new StringReader(text));
+ for (Operation op : operations) {
+ formatter.format("%s", op.asRepoInitString());
+ }
+ text = formatter.out().toString();
+ }
if (repoInitExtension == null) {
repoInitExtension = new Extension(ExtensionType.TEXT, Extension.EXTENSION_NAME_REPOINIT, ExtensionState.REQUIRED);
getRunMode(runMode).getExtensions().add(repoInitExtension);
repoInitExtension.setText(text);
} else {
- repoInitExtension.setText(repoInitExtension.getText() + "\n ".concat(text));
+ repoInitExtension.setText(repoInitExtension.getText().concat(text));
}
}
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/features/FeaturesManager.java b/src/main/java/org/apache/sling/feature/cpconverter/features/FeaturesManager.java
index 8392599..88fd528 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/features/FeaturesManager.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/features/FeaturesManager.java
@@ -20,6 +20,7 @@ import java.util.Dictionary;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Feature;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -44,6 +45,6 @@ public interface FeaturesManager {
void serialize() throws Exception;
- void addOrAppendRepoInitExtension(@NotNull String text, @Nullable String runMode);
+ void addOrAppendRepoInitExtension(@NotNull String text, @Nullable String runMode) throws RepoInitParsingException;
}
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java b/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
index 0357138..5cc4f2d 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.sling.feature.cpconverter;
+import static org.apache.sling.feature.cpconverter.Util.normalize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -759,7 +760,7 @@ public class ContentPackage2FeatureModelConverterTest {
Extension repoinitExtension = feature.getExtensions().getByName("repoinit");
assertNotNull(repoinitExtension);
- String expected = "register nodetypes\n" +
+ String expected = normalize("register nodetypes\n" +
"<<===\n" +
"<< <'sling'='http://sling.apache.org/jcr/sling/1.0'>\n" +
"<< <'nt'='http://www.jcp.org/jcr/nt/1.0'>\n" +
@@ -773,7 +774,7 @@ public class ContentPackage2FeatureModelConverterTest {
"<< [rep:RepoAccessControllable]\n" +
"<< mixin\n" +
"<< + rep:repoPolicy (rep:Policy) protected ignore\n" +
- "===>>\n";
+ "===>>\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
}
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/Util.java b/src/test/java/org/apache/sling/feature/cpconverter/Util.java
new file mode 100644
index 0000000..43db798
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/cpconverter/Util.java
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+import org.apache.sling.repoinit.parser.RepoInitParser;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
+import org.apache.sling.repoinit.parser.impl.RepoInitParserService;
+import org.apache.sling.repoinit.parser.operations.Operation;
+
+import java.io.StringReader;
+import java.util.Formatter;
+import java.util.List;
+
+public class Util {
+ public static String normalize(String repoinit) throws RepoInitParsingException {
+ RepoInitParser parser = new RepoInitParserService();
+ List<Operation> operations = parser.parse(new StringReader(repoinit));
+ Formatter formatter = new Formatter();
+ for (Operation op : operations) {
+ formatter.format("%s", op.asRepoInitString());
+ }
+ return formatter.out().toString();
+ }
+
+ public static String normalizeUnchecked(String repoinit) {
+ try {
+ return normalize(repoinit);
+ } catch (RepoInitParsingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java b/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
index 91f4169..fa9cb0b 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
@@ -20,6 +20,7 @@ import org.apache.jackrabbit.vault.util.PlatformNameFormat;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Extension;
import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.cpconverter.Util;
import org.apache.sling.feature.cpconverter.features.DefaultFeaturesManager;
import org.apache.sling.feature.cpconverter.features.FeaturesManager;
import org.apache.sling.feature.cpconverter.shared.RepoPath;
@@ -96,13 +97,13 @@ public class AclManagerTest {
assertNotNull(repoinitExtension);
// acs-commons-on-deploy-scripts-service will be missed
- String expected =
+ String expected = Util.normalize(
"create service user acs-commons-package-replication-status-event-service with path system\n" +
"create path /sling:tests/not(nt:unstructured mixin rep:AccessControllable,mix:created)/system/user/path\n" +
"set ACL for acs-commons-package-replication-status-event-service\n" +
" allow jcr:read,rep:write,rep:indexDefinitionManagement on /sling:tests/not/system/user/path\n" +
" allow jcr:read,crx:replicate,jcr:removeNode on /home/users/system\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -138,12 +139,12 @@ public class AclManagerTest {
assertNotNull(repoinitExtension);
// aacs-commons-ensure-oak-index-service will be missed
- String expected =
+ String expected = Util.normalize(
"create service user acs-commons-package-replication-status-event-service with path system\n" +
"create path /sling:tests/not(nt:unstructured mixin rep:AccessControllable,mix:created)/system/user/path\n" +
"set ACL for acs-commons-package-replication-status-event-service\n" +
" allow jcr:read,rep:write,rep:indexDefinitionManagement on /sling:tests/not/system/user/path\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -153,7 +154,7 @@ public class AclManagerTest {
}
@Test
- public void testAddACLforUnknownUser() {
+ public void testAddACLforUnknownUser() throws RepoInitParsingException {
// we expect this acl to not show up because the user is unknown
aclManager.addAcl("acs-commons-on-deploy-scripts-service", newAcl(true, "jcr:read,crx:replicate,jcr:removeNode", "/home/users/system"));
@@ -188,12 +189,12 @@ public class AclManagerTest {
Extension repoinitExtension = feature.getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT);
assertNotNull(repoinitExtension);
- String expected =
+ String expected = Util.normalize(
"create service user sys-usr with path system\n" +
"set ACL for sys-usr\n" +
" allow jcr:read on /content/cq:tags\n" +
" allow jcr:write on /content/cq:tags\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -204,7 +205,7 @@ public class AclManagerTest {
}
@Test(expected = IllegalStateException.class)
- public void testGroupHandlingWithGroupUsed() {
+ public void testGroupHandlingWithGroupUsed() throws RepoInitParsingException {
aclManager.addSystemUser(new SystemUser("sys-usr", new RepoPath("/home/users/system/foo"), new RepoPath("/home/users/system")));
aclManager.addGroup(new Group("test", new RepoPath("/home/groups/test"), new RepoPath("/home/groups/test")));
@@ -222,7 +223,7 @@ public class AclManagerTest {
}
@Test
- public void testGroupHandlingWithGroupNotUsed() {
+ public void testGroupHandlingWithGroupNotUsed() throws RepoInitParsingException {
aclManager.addSystemUser(new SystemUser("sys-usr", new RepoPath("/home/users/system/foo"), new RepoPath("/home/users/system")));
aclManager.addGroup(new Group("test", new RepoPath("/home/groups/test"), new RepoPath("/home/groups/test")));
@@ -239,11 +240,11 @@ public class AclManagerTest {
Extension repoinitExtension = feature.getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT);
assertNotNull(repoinitExtension);
- String expected =
+ String expected = Util.normalize(
"create service user sys-usr with path system\n" +
"set ACL for sys-usr\n" +
" allow jcr:read on /content/test\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -251,7 +252,7 @@ public class AclManagerTest {
}
@Test(expected = IllegalStateException.class)
- public void testGroupHandlingWithGroupMatchingSubPath() {
+ public void testGroupHandlingWithGroupMatchingSubPath() throws RepoInitParsingException {
aclManager.addSystemUser(new SystemUser("sys-usr", new RepoPath("/home/users/system/foo"), new RepoPath("/home/users/system")));
aclManager.addGroup(new Group("test", new RepoPath("/home/groups/test"), new RepoPath("/home/groups/test")));
@@ -266,7 +267,7 @@ public class AclManagerTest {
}
@Test(expected = IllegalStateException.class)
- public void testUserHandlingWithMatchingUser() {
+ public void testUserHandlingWithMatchingUser() throws RepoInitParsingException {
aclManager.addSystemUser(new SystemUser("sys-usr", new RepoPath("/home/users/system/foo"), new RepoPath("/home/users/system")));
aclManager.addUser(new User("test", new RepoPath("/home/users/test"), new RepoPath("/home/users/test")));
@@ -281,7 +282,7 @@ public class AclManagerTest {
}
@Test
- public void testUserHandlingWithNonMatchingUser() {
+ public void testUserHandlingWithNonMatchingUser() throws RepoInitParsingException {
aclManager.addSystemUser(new SystemUser("sys-usr", new RepoPath("/home/users/system/foo"), new RepoPath("/home/users/system")));
aclManager.addUser(new User("test", new RepoPath("/home/users/test"), new RepoPath("/home/users/test")));
@@ -298,18 +299,18 @@ public class AclManagerTest {
Extension repoinitExtension = feature.getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT);
assertNotNull(repoinitExtension);
- String expected =
+ String expected = Util.normalize(
"create service user sys-usr with path system\n" +
"set ACL for sys-usr\n" +
" allow jcr:read on /content/test\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
}
@Test
- public void testPathHandlingWithUser() {
+ public void testPathHandlingWithUser() throws RepoInitParsingException {
aclManager.addSystemUser(new SystemUser("sys-usr", new RepoPath("/home/users/system/foo"), new RepoPath("/home/users/system")));
aclManager.addUser(new User("test", new RepoPath("/home/users/test"), new RepoPath("/home/users/test")));
@@ -326,11 +327,11 @@ public class AclManagerTest {
Extension repoinitExtension = feature.getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT);
assertNotNull(repoinitExtension);
- String expected =
+ String expected = Util.normalize(
"create service user sys-usr with path system\n" +
"set ACL for sys-usr\n" +
" allow jcr:read on /home/users/test2\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/EnforcePrincipalBasedTest.java b/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/EnforcePrincipalBasedTest.java
index 951604f..89353ae 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/EnforcePrincipalBasedTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/EnforcePrincipalBasedTest.java
@@ -43,6 +43,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
+import static org.apache.sling.feature.cpconverter.Util.normalize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -89,7 +90,7 @@ public class EnforcePrincipalBasedTest {
}
@Test(expected = IllegalStateException.class)
- public void testInvalidSupportedPath() {
+ public void testInvalidSupportedPath() throws RepoInitParsingException {
AclManager acMgr = new DefaultAclManager("/an/invalid/supported/path", "invalid");
RepoPath accessControlledPath = new RepoPath("/content/feature");
getRepoInitExtension(acMgr, accessControlledPath, systemUser, false);
@@ -115,12 +116,12 @@ public class EnforcePrincipalBasedTest {
RepoPath accessControlledPath = new RepoPath("/content/feature");
Extension repoinitExtension = getRepoInitExtension(acMgr, accessControlledPath, systemUser, false);
- String expected =
+ String expected = normalize(
"create service user user1 with path " + relativeIntermediatePath + "\n" +
"create path /content/feature(sling:Folder)\n" +
"set ACL for user1\n" +
" allow jcr:read on /content/feature\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -135,11 +136,11 @@ public class EnforcePrincipalBasedTest {
RepoPath accessControlledPath = new RepoPath("/content/feature");
Extension repoinitExtension = getRepoInitExtension(aclManager, accessControlledPath, systemUser, false);
- String expected =
+ String expected = normalize(
"create service user user1 with forced path " + remappedIntermediatePath + "\n" +
"set principal ACL for user1\n" +
" allow jcr:read on /content/feature\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -154,11 +155,11 @@ public class EnforcePrincipalBasedTest {
RepoPath accessControlledPath = new RepoPath("/content/feature");
Extension repoinitExtension = getRepoInitExtension(aclManager, accessControlledPath, systemUser, true);
- String expected =
+ String expected = normalize(
"create service user user1 with forced path " + remappedIntermediatePath + "\n" +
"set principal ACL for user1\n" +
" allow jcr:read on /content/feature\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -173,11 +174,11 @@ public class EnforcePrincipalBasedTest {
RepoPath accessControlledPath = systemUser.getPath();
Extension repoinitExtension = getRepoInitExtension(aclManager, accessControlledPath, systemUser, true);
- String expected =
+ String expected = normalize(
"create service user user1 with forced path " + remappedIntermediatePath + "\n" +
"set principal ACL for user1\n" +
" allow jcr:read on home(user1)\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -188,41 +189,41 @@ public class EnforcePrincipalBasedTest {
}
@Test
- public void testSingleUserMapping() {
+ public void testSingleUserMapping() throws RepoInitParsingException {
aclManager.addMapping(new Mapping("org.apache.sling.testbundle:subservice="+systemUser.getId()));
RepoPath accessControlledPath = new RepoPath("/content/feature");
Extension repoinitExtension = getRepoInitExtension(aclManager, accessControlledPath, systemUser, false);
- String expected =
+ String expected = normalize(
"create service user user1 with path " +relativeIntermediatePath+ "\n" +
"set ACL for user1\n" +
" allow jcr:read on /content/feature\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
}
@Test
- public void testPrincipalMapping() {
+ public void testPrincipalMapping() throws RepoInitParsingException {
aclManager.addMapping(new Mapping("org.apache.sling.testbundle:subservice=["+systemUser.getId()+"]"));
RepoPath accessControlledPath = new RepoPath("/content/feature");
Extension repoinitExtension = getRepoInitExtension(aclManager, accessControlledPath, systemUser, false);
- String expected =
+ String expected = normalize(
"create service user user1 with forced path " + remappedIntermediatePath + "\n" +
"set principal ACL for user1\n" +
" allow jcr:read on /content/feature\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
}
@Test
- public void testSingleUserMappingInSeed() throws IOException {
+ public void testSingleUserMappingInSeed() throws IOException, RepoInitParsingException {
DefaultFeaturesManager fm = new DefaultFeaturesManager(true, 1, File.createTempFile("foo", "bar"), "*", "*", new HashMap<>(), aclManager);
Feature seed = new Feature(ArtifactId.fromMvnId("org:foo:2"));
Configuration foo = new Configuration("org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl~foo");
@@ -236,18 +237,18 @@ public class EnforcePrincipalBasedTest {
RepoPath accessControlledPath = new RepoPath("/content/feature");
Extension repoinitExtension = getRepoInitExtension(aclManager, accessControlledPath, systemUser, false);
- String expected =
+ String expected = normalize(
"create service user user1 with path " + relativeIntermediatePath + "\n" +
"set ACL for user1\n" +
" allow jcr:read on /content/feature\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
}
@Test
- public void testPrincipalMappingInSeed() throws IOException {
+ public void testPrincipalMappingInSeed() throws IOException, RepoInitParsingException {
DefaultFeaturesManager fm = new DefaultFeaturesManager(true, 1, File.createTempFile("foo", "bar"), "*", "*", new HashMap<>(), aclManager);
Feature seed = new Feature(ArtifactId.fromMvnId("org:foo:2"));
Configuration foo = new Configuration("org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl~foo");
@@ -261,18 +262,18 @@ public class EnforcePrincipalBasedTest {
RepoPath accessControlledPath = new RepoPath("/content/feature");
Extension repoinitExtension = getRepoInitExtension(aclManager, accessControlledPath, systemUser, false);
- String expected =
+ String expected = normalize(
"create service user user1 with forced path " + remappedIntermediatePath + "\n" +
"set principal ACL for user1\n" +
" allow jcr:read on /content/feature\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
}
@NotNull
- private Extension getRepoInitExtension(@NotNull AclManager aclManager, @NotNull RepoPath accessControlledPath, @NotNull SystemUser systemUser, boolean isPrincipalBased) {
+ private Extension getRepoInitExtension(@NotNull AclManager aclManager, @NotNull RepoPath accessControlledPath, @NotNull SystemUser systemUser, boolean isPrincipalBased) throws RepoInitParsingException {
aclManager.addSystemUser(systemUser);
AccessControlEntry acl = new AccessControlEntry(true, Collections.singletonList("jcr:read"), accessControlledPath, isPrincipalBased);
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigurationEntryHandlerTest.java b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigurationEntryHandlerTest.java
index 21ca0cc..3a7425f 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigurationEntryHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigurationEntryHandlerTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.sling.feature.cpconverter.handlers;
+import static org.apache.sling.feature.cpconverter.Util.normalizeUnchecked;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -60,7 +61,7 @@ public class ConfigurationEntryHandlerTest {
private static final String REPOINIT_PID = "org.apache.sling.jcr.repoinit.RepositoryInitializer";
private static final String REPOINIT_TESTCONFIG_PATH = "/jcr_root/apps/asd/config.author/" + REPOINIT_PID + "-test.config";
private static final String TYPED_TESTCONFIG_PATH = "/jcr_root/apps/asd/config/" + EXPECTED_PID + ".typed.xml";
- private static final String EXPECTED_REPOINIT = "create service user test-user\n" +
+ private static final String EXPECTED_REPOINIT = normalizeUnchecked("create service user test-user\n" +
" set ACL for test-user\n" +
" allow jcr:read on /conf\n" +
" end\n" +
@@ -71,7 +72,7 @@ public class ConfigurationEntryHandlerTest {
" create path /test\n" +
" set properties on /test\n" +
" set testprop to \"one=two\"\n" +
- " end"
+ " end")
;
private static final String EXPECTED_TYPED_CONFIG = "{\n" +
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/PrivilegesHandlerTest.java b/src/test/java/org/apache/sling/feature/cpconverter/handlers/PrivilegesHandlerTest.java
index 9a20b78..66813b5 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/PrivilegesHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/PrivilegesHandlerTest.java
@@ -91,12 +91,12 @@ public class PrivilegesHandlerTest {
Extension repoinitExtension = feature.getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT);
assertNotNull(repoinitExtension);
- String str = "register privilege sling:replicate\n" +
+ String str = "register privilege sling:replicate" + System.lineSeparator() +
"register abstract privilege sling:test with ";
String txt = repoinitExtension.getText();
assertTrue("Expect '"+txt+"' contains '"+str+"'", txt.contains(str));
- String aggregation1 = "with sling:replicate,jcr:read\n";
- String aggregation2 = "with jcr:read,sling:replicate\n";
+ String aggregation1 = "with sling.replicate,jcr.read" + System.lineSeparator();
+ String aggregation2 = "with jcr.read,sling.replicate" + System.lineSeparator();
assertTrue(txt.contains(aggregation1) || txt.contains(aggregation2));
}
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
index 49a3cb5..3352fa4 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
@@ -35,6 +35,7 @@ import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.util.List;
+import static org.apache.sling.feature.cpconverter.Util.normalize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -83,7 +84,7 @@ public final class RepPolicyEntryHandlerTest {
"acs-commons-on-deploy-scripts-service").getRepoinitExtension();
// commented ACLs are due SLING-8561
- String expected =
+ String expected = normalize(
"create service user acs-commons-ensure-oak-index-service with path system\n" +
"create service user acs-commons-dispatcher-flush-service with path system\n" +
"create service user acs-commons-package-replication-status-event-service with path system\n" +
@@ -109,7 +110,7 @@ public final class RepPolicyEntryHandlerTest {
"end\n" +
"set ACL for acs-commons-ensure-service-user-service\n" +
" allow jcr:read,rep:write,jcr:readAccessControl,jcr:modifyAccessControl on home(acs-commons-ensure-service-user-service)\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -127,7 +128,7 @@ public final class RepPolicyEntryHandlerTest {
"acs-commons-on-deploy-scripts-service");
Extension repoinitExtension = result.getRepoinitExtension();
- String expected =
+ String expected = normalize(
"create service user acs-commons-package-replication-status-event-service with path system\n" +
"create service user acs-commons-ensure-service-user-service with path system\n" +
"create service user acs-commons-automatic-package-replicator-service with path system\n" +
@@ -144,7 +145,7 @@ public final class RepPolicyEntryHandlerTest {
"end\n" +
"set ACL for acs-commons-ensure-service-user-service\n" +
" allow jcr:read,rep:write,jcr:readAccessControl,jcr:modifyAccessControl on home(acs-commons-ensure-service-user-service)\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -170,12 +171,12 @@ public final class RepPolicyEntryHandlerTest {
ParseResult result = parseAndSetRepoinit(new SystemUser("acs-commons-package-replication-status-event-service",
new RepoPath("/home/users/system/some/other/node"), new RepoPath("/home/users/system/some/other")));
Extension repoinitExtension = result.getRepoinitExtension();
- String expected =
+ String expected = normalize(
"create service user acs-commons-package-replication-status-event-service with path system/some/other\n" +
"set ACL for acs-commons-package-replication-status-event-service\n" +
" allow jcr:read,rep:write,jcr:readAccessControl,jcr:modifyAccessControl on /home/users/system/asd\n" +
" deny jcr:write on /home/users/system/asd\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -213,11 +214,11 @@ public final class RepPolicyEntryHandlerTest {
ParseResult result = parseAndSetRepoinit("/jcr_root/home/groups/g/_rep_policy.xml", aclManager);
Extension repoinitExtension = result.getRepoinitExtension();
- String expected =
+ String expected = normalize(
"create service user service1 with path system/services\n" +
"set ACL for service1\n" +
" allow jcr:read,rep:userManagement on /home/groups/g\n" +
- "end\n";
+ "end\n");
assertEquals(expected, repoinitExtension.getText());
assertTrue(result.getExcludedAcls().isEmpty());
}
@@ -262,11 +263,11 @@ public final class RepPolicyEntryHandlerTest {
String path = "/jcr_root/asd/jr2restrictions/_rep_policy.xml";
Extension repoinitExtension = parseAndSetRepoinit(path, aclManager).getRepoinitExtension();
- String expected =
+ String expected = normalize(
"create service user service1 with path system/services\n" +
"set ACL for service1\n" +
" allow jcr:read on /asd/jr2restrictions restriction(rep:glob,*/subtree/*) restriction(sling:customRestriction,sling:value1,sling:value2)\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
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 31b1642..2700c36 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
@@ -34,6 +34,7 @@ import java.io.InputStream;
import java.io.StringReader;
import java.util.List;
+import static org.apache.sling.feature.cpconverter.Util.normalize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -67,11 +68,11 @@ public final class RepPrincipalPolicyEntryHandlerTest {
@Test
public void parseSimplePolicy() throws Exception {
Extension repoinitExtension = parseAndSetRepoinit("service1", "random1").getRepoinitExtension();
- String expected =
+ String expected = normalize(
"create service user service1 with path system/services\n" +
"set principal ACL for service1\n" +
" allow jcr:read,jcr:readAccessControl on /asd/public\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -84,11 +85,11 @@ public final class RepPrincipalPolicyEntryHandlerTest {
@Test
public void parseMvRestrictions() throws Exception {
Extension repoinitExtension = parseAndSetRepoinit("service2", "random2").getRepoinitExtension();
- String expected =
+ String expected = normalize(
"create service user service2 with path system/services\n" +
"set principal ACL for service2\n" +
" allow jcr:read on /asd/public restriction(rep:ntNames,nt:folder,sling:Folder) restriction(sling:customRestriction,customRestrictionValue)\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -108,12 +109,12 @@ public final class RepPrincipalPolicyEntryHandlerTest {
SystemUser systemUser4 = createSystemUser("service4", "random4");
Extension repoinitExtension = parseAndSetRepoinit(getPolicyPath(systemUser4), systemUser4).getRepoinitExtension();
- String expected =
+ String expected = normalize(
"create service user service4 with path system/services\n" +
"set principal ACL for service4\n" +
// 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\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
@@ -129,12 +130,12 @@ public final class RepPrincipalPolicyEntryHandlerTest {
SystemUser systemUser4 = createSystemUser("service4", "random4");
Extension repoinitExtension = parseAndSetRepoinit(getPolicyPath(systemUser4), systemUser4, systemUser3).getRepoinitExtension();
- String expected =
+ String expected = normalize(
"create service user service4 with path system/services\n" +
"create service user service3 with path system/services\n" +
"set principal ACL for service4\n" +
" allow jcr:read,rep:userManagement on home(service3)\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepRepoPolicyEntryHandlerTest.java b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepRepoPolicyEntryHandlerTest.java
index 652d871..c9e6c0f 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepRepoPolicyEntryHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepRepoPolicyEntryHandlerTest.java
@@ -33,6 +33,7 @@ import java.io.OutputStream;
import java.io.StringReader;
import java.util.List;
+import static org.apache.sling.feature.cpconverter.Util.normalize;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -69,10 +70,10 @@ public class RepRepoPolicyEntryHandlerTest {
OutputStream out = new ByteArrayOutputStream();
Extension repoinitExtension = new ParseResult(TestUtils.createRepoInitExtension(handler, aclManager, path, getClass().getResourceAsStream(path.substring(1)), out), out.toString()).getRepoinitExtension();
- String expectedEnd =
+ String expectedEnd = normalize(
"set ACL for repolevel-service\n" +
" allow jcr:namespaceManagement on :repository\n" +
- "end\n";
+ "end\n");
String actual = repoinitExtension.getText();
assertTrue(actual.endsWith(expectedEnd));
// no path must be create for repository level entries
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepoInitTest.java b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepoInitTest.java
index 6b8a724..9da5a7d 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepoInitTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepoInitTest.java
@@ -36,6 +36,7 @@ import org.junit.runners.Parameterized;
import java.io.StringReader;
import java.util.Collection;
+import static org.apache.sling.feature.cpconverter.Util.normalize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -81,11 +82,11 @@ public class RepoInitTest {
Extension expectedExtension;
if (enforcePrincipalBasedAcSetup) {
- expectedExtension = extractExtentions(result, false, false);
+ expectedExtension = extractExtensions(result, false, false);
} else {
- expectedExtension = extractExtentions(path, false, false);
+ expectedExtension = extractExtensions(path, false, false);
}
- Extension extension = extractExtentions(path, enforcePrincipalBasedAcSetup, false);
+ Extension extension = extractExtensions(path, enforcePrincipalBasedAcSetup, false);
assertNotNull(expectedExtension);
assertNotNull(extension);
String txt = extension.getText();
@@ -99,8 +100,8 @@ public class RepoInitTest {
public void parseConversionOmittedForServiceUserRepoInit() throws Exception {
String path = PATH_PREFIX + "-conversion-test.config";
- Extension expectedExtension = extractExtentions(path, false, true);
- Extension extension = extractExtentions(path, enforcePrincipalBasedAcSetup, true);
+ Extension expectedExtension = extractExtensions(path, false, true);
+ Extension extension = extractExtensions(path, enforcePrincipalBasedAcSetup, true);
assertNotNull(expectedExtension);
assertNotNull(extension);
String txt = extension.getText();
@@ -114,8 +115,8 @@ public class RepoInitTest {
public void parseNoConversionRepoInit() throws Exception {
String expectedPath = (enforcePrincipalBasedAcSetup) ? PATH_PREFIX + "-no-conversion-result.config" : PATH_PREFIX + "-no-conversion-test.config";
- Extension expectedExtension = extractExtentions(expectedPath, false, false);
- Extension extension = extractExtentions(PATH_PREFIX + "-no-conversion-test.config", enforcePrincipalBasedAcSetup, false);
+ Extension expectedExtension = extractExtensions(expectedPath, false, false);
+ Extension extension = extractExtensions(PATH_PREFIX + "-no-conversion-test.config", enforcePrincipalBasedAcSetup, false);
assertNotNull(expectedExtension);
assertNotNull(extension);
String txt = extension.getText();
@@ -131,7 +132,7 @@ public class RepoInitTest {
// See SLING-10231, SLING-10238 and FIXMEs in DefaultVisitor
String path = PATH_PREFIX + "-no-conv-with-diff.config";
- String resultTxt = "set properties on /test\n"+
+ String resultTxt = normalize("set properties on /test\n"+
"set testprop{String} to \"one=two\"\n"+
"set testprop{String} to \"\\\"one=two\\\"\"\n"+
"set sling:ResourceType{String} to \"/x/y/z\"\n"+
@@ -143,18 +144,18 @@ public class RepoInitTest {
"set aLongMultiValue{Long} to 1,2,3\n"+
"set curlyBracketsAndDoubleQuotes{String} to \"{\\\"one, two\\\":\\\"three, four\\\"}\"\n"+
"set curlyBracketsAndSingleQuotes{String} to \"{'five, six':'seven,eight'}\"\n"+
- "end";
- Extension extension = extractExtentions(path, enforcePrincipalBasedAcSetup, false);
+ "end");
+ Extension extension = extractExtensions(path, enforcePrincipalBasedAcSetup, false);
assertNotNull(extension);
- String expectedTxt = (enforcePrincipalBasedAcSetup) ? resultTxt : extractExtentions(path, false, false).getText();
+ String expectedTxt = (enforcePrincipalBasedAcSetup) ? resultTxt : extractExtensions(path, false, false).getText();
String txt = extension.getText();
- assertEquals(name, expectedTxt, txt.trim());
+ assertEquals(name, expectedTxt, txt);
// verify that the generated repo-init is valid
assertFalse(name, new RepoInitParserService().parse(new StringReader(txt)).isEmpty());
}
- private Extension extractExtentions(@NotNull String path, boolean enforcePrincipalBasedAcSetup, boolean addMappingById) throws Exception {
+ private Extension extractExtensions(@NotNull String path, boolean enforcePrincipalBasedAcSetup, boolean addMappingById) throws Exception {
Archive archive = mock(Archive.class);
Archive.Entry entry = mock(Archive.Entry.class);
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandlerTest.java b/src/test/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandlerTest.java
index 8851ccc..40c54dc 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandlerTest.java
@@ -32,6 +32,7 @@ import org.junit.Test;
import java.io.StringReader;
import java.util.List;
+import static org.apache.sling.feature.cpconverter.Util.normalize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -77,7 +78,7 @@ public class UsersEntryHandlerTest {
assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
assertTrue(repoinitExtension.isRequired());
- String expected = "create service user asd-share-commons-asd-index-definition-reader-service with path system/asd-share-commons\n";
+ String expected = normalize("create service user asd-share-commons-asd-index-definition-reader-service with path system/asd-share-commons\n");
String actual = repoinitExtension.getText();
assertEquals(expected, actual);
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/META-INF/vault/privileges.xml b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/META-INF/vault/privileges.xml
index 625a79b..1e083bd 100644
--- a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/META-INF/vault/privileges.xml
+++ b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/META-INF/vault/privileges.xml
@@ -17,5 +17,5 @@
-->
<privileges xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
<privilege name="sling:replicate"/>
- <privilege name="sling:test" abstract="true"><contains name="sling:replicate"/><contains name="jcr:read"/></privilege>
+ <privilege name="sling:test" abstract="true"><contains name="sling.replicate"/><contains name="jcr.read"/></privilege>
</privileges>