anchela commented on a change in pull request #91:
URL: 
https://github.com/apache/sling-org-apache-sling-feature-cpconverter/pull/91#discussion_r648970034



##########
File path: 
src/main/java/org/apache/sling/feature/cpconverter/vltpkg/RecollectorVaultPackageScanner.java
##########
@@ -42,6 +43,7 @@ public RecollectorVaultPackageScanner(@NotNull 
ContentPackage2FeatureModelConver
         this.converter = converter;
         handlers = new EntryHandler[] {
                 new UsersEntryHandler(),
+                new GroupEntryHandler(),

Review comment:
       that looks reasonable!

##########
File path: 
src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
##########
@@ -1041,9 +1041,125 @@ public void 
testConvertPackageWithUsersGroupsAndServiceUsers() throws Exception
                     
"jcr_root/home/groups/demo-cp/EsYrXeBdSRkna2kqbxjl/_rep_policy.xml"
                     );
 
+            assertPolicy(converted, "jcr_root/demo-cp/_rep_policy.xml", 
"cp-serviceuser-1", "cp-user1", "cp-group1");
+            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");
+        } finally {
+            deleteDirTree(outputDirectory);
+        }
+    }
+    @Test
+    public void 
testConvertPackageWithUsersGroupsAndServiceUsersRepPolicyFirst() throws 
Exception {
+        URL packageUrl = getClass().getResource("demo-cp3.zip");
+        File packageFile = FileUtils.toFile(packageUrl);
+        File outputDirectory = new File(System.getProperty("java.io.tmpdir"), 
getClass().getName() + '_' + System.currentTimeMillis());
+        try {
+            converter.setFeaturesManager(new DefaultFeaturesManager(true, 5, 
outputDirectory, null, null, null, new DefaultAclManager()))
+                    .setBundlesDeployer(new 
LocalMavenRepositoryArtifactsDeployer(outputDirectory))
+                    
.setEmitter(DefaultPackagesEventsEmitter.open(outputDirectory))
+                    .convert(packageFile);
+
+            File converted = new File(outputDirectory, 
"my_packages/demo-cp/0.0.0/demo-cp-0.0.0-cp2fm-converted.zip");
+            Set<String> notExpected = new HashSet<>();
+            notExpected.add("jcr_root/apps/demo-cp/.content.xml");
+            notExpected.add("jcr_root/home/users/demo-cp/_rep_policy.xml");
+            notExpected.add("jcr_root/home/groups/demo-cp/_rep_policy.xml");
+            notExpected.add("jcr_root/home/users/system/.content.xml");
+            
notExpected.add("jcr_root/home/users/system/_cq_services/.content.xml");
+            
notExpected.add("jcr_root/home/users/system/_cq_services/demo-cp/.content.xml");
+            
notExpected.add("jcr_root/home/users/system/_cq_services/demo-cp/qStDu7IQBLa95gURmer1/.content.xml");
+            
notExpected.add("jcr_root/home/users/system/_cq_services/demo-cp/qStDu7IQBLa95gURmer1/_rep_principalPolicy.xml");
+            verifyContentPackage(converted,
+                    notExpected,
+                    "META-INF/vault/properties.xml",
+                    "META-INF/vault/config.xml",
+                    "META-INF/vault/filter.xml",
+                    "jcr_root/.content.xml",
+                    "jcr_root/demo-cp/.content.xml",
+                    "jcr_root/demo-cp/_rep_policy.xml",
+                    "jcr_root/apps/.content.xml",
+                    "jcr_root/home/.content.xml",
+                    "jcr_root/home/users/demo-cp/.content.xml",
+                    
"jcr_root/home/users/demo-cp/XPXhA_RKMFRKNO8ViIhn/.content.xml",
+                    
"jcr_root/home/users/demo-cp/XPXhA_RKMFRKNO8ViIhn/_rep_policy.xml",
+                    "jcr_root/home/groups/.content.xml",
+                    "jcr_root/home/groups/demo-cp/.content.xml",
+                    
"jcr_root/home/groups/demo-cp/EsYrXeBdSRkna2kqbxjl/.content.xml",
+                    
"jcr_root/home/groups/demo-cp/EsYrXeBdSRkna2kqbxjl/_rep_policy.xml"
+            );
+
+            assertPolicy(converted, "jcr_root/demo-cp/_rep_policy.xml", 
"cp-serviceuser-1", "cp-user1", "cp-group1");
+            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");
         } finally {
             deleteDirTree(outputDirectory);
         }
     }
+    @Test
+    public void testConvertCONTENTPackageWithUsersGroupsAndServiceUsers() 
throws Exception {
+        URL packageUrl = getClass().getResource("demo-cp2.zip");
+        File packageFile = FileUtils.toFile(packageUrl);
+        File outputDirectory = new File(System.getProperty("java.io.tmpdir"), 
getClass().getName() + '_' + System.currentTimeMillis());
+        File unrefOutputDir = new File(outputDirectory, "unref");
+        try {
+            converter.setFeaturesManager(new DefaultFeaturesManager(true, 5, 
outputDirectory, null, null, null, new DefaultAclManager()))
+                    .setBundlesDeployer(new 
LocalMavenRepositoryArtifactsDeployer(outputDirectory))
+                    .setUnreferencedArtifactsDeployer(new 
LocalMavenRepositoryArtifactsDeployer(unrefOutputDir))
+                    
.setContentTypePackagePolicy(PackagePolicy.PUT_IN_DEDICATED_FOLDER)
+                    
.setEmitter(DefaultPackagesEventsEmitter.open(outputDirectory))
+                    .convert(packageFile);
+
+            File converted = new File(unrefOutputDir, 
"my_packages/demo-cp/0.0.0/demo-cp-0.0.0-cp2fm-converted.zip");
+            Set<String> notExpected = new HashSet<>();
+            notExpected.add("jcr_root/home/users/demo-cp/_rep_policy.xml");
+            notExpected.add("jcr_root/home/groups/demo-cp/_rep_policy.xml");
+            notExpected.add("jcr_root/home/users/system/.content.xml");
+            
notExpected.add("jcr_root/home/users/system/_cq_services/.content.xml");
+            
notExpected.add("jcr_root/home/users/system/_cq_services/demo-cp/.content.xml");
+            
notExpected.add("jcr_root/home/users/system/_cq_services/demo-cp/qStDu7IQBLa95gURmer1/.content.xml");
+            
notExpected.add("jcr_root/home/users/system/_cq_services/demo-cp/qStDu7IQBLa95gURmer1/_rep_principalPolicy.xml");
+            verifyContentPackage(converted,
+                    notExpected,
+                    "META-INF/vault/properties.xml",
+                    "META-INF/vault/config.xml",
+                    "META-INF/vault/filter.xml",
+                    "jcr_root/.content.xml",
+                    "jcr_root/demo-cp/.content.xml",
+                    "jcr_root/demo-cp/_rep_policy.xml",
+                    "jcr_root/home/.content.xml",
+                    "jcr_root/home/users/demo-cp/.content.xml",
+                    
"jcr_root/home/users/demo-cp/XPXhA_RKMFRKNO8ViIhn/.content.xml",
+                    
"jcr_root/home/users/demo-cp/XPXhA_RKMFRKNO8ViIhn/_rep_policy.xml",
+                    "jcr_root/home/groups/.content.xml",
+                    "jcr_root/home/groups/demo-cp/.content.xml",
+                    
"jcr_root/home/groups/demo-cp/EsYrXeBdSRkna2kqbxjl/.content.xml",
+                    
"jcr_root/home/groups/demo-cp/EsYrXeBdSRkna2kqbxjl/_rep_policy.xml"
+            );
+
+            assertPolicy(converted, "jcr_root/demo-cp/_rep_policy.xml", 
"cp-serviceuser-1", "cp-user1", "cp-group1");
+            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");
+        } finally {
+            deleteDirTree(outputDirectory);
+        }
+    }
+    
+    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);
+            assertNotNull(entry);
+            assertFalse(entry.isDirectory());
+            
+            try (InputStream in = zipFile.getInputStream(entry)) {
+                String policy = IOUtils.toString(in, StandardCharsets.UTF_8);
+                for (String principalName : expectedPrincipalNames) {
+                    
assertTrue(policy.contains("rep:principalName=\""+principalName+"\""));
+                }
+                if (unExpectedPrincipalName != null) {
+                    
assertFalse(policy.contains("rep:principalName=\""+unExpectedPrincipalName+"\""));
+                }
+            }
+        } 
+    }

Review comment:
       now we have the same test assertions copied 3 times, right?
   i will move that to a separate ticket and add the zip-file as a separate 
param.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to