You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2021/06/10 14:09:37 UTC

[sling-org-apache-sling-feature-cpconverter] branch SLING-10467 created (now bac191a)

This is an automated email from the ASF dual-hosted git repository.

angela pushed a change to branch SLING-10467
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git.


      at bac191a  SLING-10467 : Converted content package referres to paths moved to repo-init

This branch includes the following new commits:

     new bac191a  SLING-10467 : Converted content package referres to paths moved to repo-init

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-feature-cpconverter] 01/01: SLING-10467 : Converted content package referres to paths moved to repo-init

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

angela pushed a commit to branch SLING-10467
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git

commit bac191a6039c2f1e5a3ea18636cd3e93bb96da6d
Author: angela <an...@adobe.com>
AuthorDate: Thu Jun 10 16:09:19 2021 +0200

    SLING-10467 : Converted content package referres to paths moved to repo-init
---
 .../ConverterUserAndPermissionTest.java            | 51 ++++++++++++++++++++--
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/src/test/java/org/apache/sling/feature/cpconverter/ConverterUserAndPermissionTest.java b/src/test/java/org/apache/sling/feature/cpconverter/ConverterUserAndPermissionTest.java
index 8355e13..e5c76c5 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/ConverterUserAndPermissionTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/ConverterUserAndPermissionTest.java
@@ -39,10 +39,12 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
@@ -127,9 +129,10 @@ public class ConverterUserAndPermissionTest  extends AbstractConverterTest {
 
             Set<String> expected = new HashSet<>(COMMON_EXPECTED_PATHS);
             expected.add("jcr_root/apps/.content.xml");
-            
+
             verifyContentPackage(converted, notExpected, expected);
             assertExpectedPolicies(converted);
+            assertFilterXml(converted);
         } finally {
             deleteDirTree(outputDirectory);
         }
@@ -138,10 +141,10 @@ public class ConverterUserAndPermissionTest  extends AbstractConverterTest {
     /**
      * "demo-cp3.zip" contains the same content as "demo-cp.zip" but with altered order leading to ACE being read before 
      * the corresponding system-user, whose principal is referenced in the ACE.
-     * 
+     *
      * This test would fail if user/group information was not collected during the first pass (i.e. corresponding 
      * handlers listed in {@link org.apache.sling.feature.cpconverter.vltpkg.RecollectorVaultPackageScanner}.
-     * 
+     *
      * @throws Exception
      */
     @Test
@@ -164,6 +167,7 @@ public class ConverterUserAndPermissionTest  extends AbstractConverterTest {
 
             verifyContentPackage(converted, notExpected, expected);
             assertExpectedPolicies(converted);
+            assertFilterXml(converted);
         } finally {
             deleteDirTree(outputDirectory);
         }
@@ -192,6 +196,7 @@ public class ConverterUserAndPermissionTest  extends AbstractConverterTest {
             File converted = new File(unrefOutputDir, "my_packages/demo-cp/0.0.0/demo-cp-0.0.0-cp2fm-converted.zip");
             verifyContentPackage(converted, COMMON_NOT_EXPECTED_PATHS, COMMON_EXPECTED_PATHS);
             assertExpectedPolicies(converted);
+            assertFilterXml(converted);
         } finally {
             deleteDirTree(outputDirectory);
         }
@@ -202,7 +207,7 @@ public class ConverterUserAndPermissionTest  extends AbstractConverterTest {
         assertPolicy(converted, "jcr_root/home/groups/demo-cp/EsYrXeBdSRkna2kqbxjl/_rep_policy.xml", null, "cp-group1");
         assertPolicy(converted,  "jcr_root/home/users/demo-cp/XPXhA_RKMFRKNO8ViIhn/_rep_policy.xml", null, "cp-user1");
     }
-    
+
     private static void assertPolicy(@NotNull File contentPackage, @NotNull String path, @Nullable String unExpectedPrincipalName, @NotNull String... expectedPrincipalNames) throws IOException {
         try (ZipFile zipFile = new ZipFile(contentPackage)) {
             ZipEntry entry = zipFile.getEntry(path);
@@ -220,4 +225,42 @@ public class ConverterUserAndPermissionTest  extends AbstractConverterTest {
             }
         }
     }
+
+    private static void assertFilterXml(@NotNull File contentPackage) throws IOException {
+        try (ZipFile zipFile = new ZipFile(contentPackage)) {
+            ZipEntry entry = zipFile.getEntry("META-INF/vault/filter.xml");
+            assertNotNull(entry);
+            assertFalse(entry.isDirectory());
+
+            try (InputStream in = zipFile.getInputStream(entry)) {
+                String filterXml = IOUtils.toString(in, StandardCharsets.UTF_8);
+
+                List<String> expected = new ArrayList<>();
+                expected.add("/home/users/demo-cp");
+                expected.add("/home/groups/demo-cp");
+                expected.add("/demo-cp");
+
+                for (String expectedPath : expected) {
+                    String p = getFilterPath(expectedPath);
+                    assertTrue(p, filterXml.contains(p));
+                }
+
+                List<String> notExpected = new ArrayList<>();
+                notExpected.add("/apps/demo-cp");
+                notExpected.add("/home/users/system/demo-cp");
+                notExpected.add("/home/users/system/cq:services/demo-cp");
+
+                for (String unexpectedPath : notExpected) {
+                    String p = getFilterPath(unexpectedPath);
+                    assertFalse(p, filterXml.contains(p));
+                }
+            }
+        }
+    }
+
+    @NotNull
+    private static String getFilterPath(@NotNull String path) {
+        String p = (path.startsWith("jcr_root")) ? path.substring("jcr_root".length()) : path;
+        return "<filter root=\""+p+"\"/>";
+    }
 }