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/05/07 12:27:11 UTC

[sling-org-apache-sling-feature-cpconverter] branch issues/SLING-10358 created (now 2acc9e6)

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

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


      at 2acc9e6  SLING-10358: Enforcing configuration below config folders is not taking into account the xml config handler

This branch includes the following new commits:

     new 2acc9e6  SLING-10358: Enforcing configuration below config folders is not taking into account the xml config handler

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-10358: Enforcing configuration below config folders is not taking into account the xml config handler

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

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

commit 2acc9e6becf8991d5862c2b7b975268268965a73
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Fri May 7 14:26:36 2021 +0200

    SLING-10358: Enforcing configuration below config folders is not taking into account the xml config handler
---
 .../AbstractConfigurationEntryHandler.java         |  9 +++++----
 .../handlers/ConfigEntryHandlerTest.java           | 23 ++++++++++++++++++++--
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java b/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java
index bb84b81..fa0b514 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java
@@ -48,10 +48,6 @@ abstract class AbstractConfigurationEntryHandler extends AbstractRegexEntryHandl
         String runMode;
         // we are pretty sure it matches, here
         if (matcher.matches()) {
-            if (enforceConfigurationBelowConfigFolder && !"config".equals(matcher.group("foldername"))) {
-                throw new IllegalStateException("OSGi configuration are only considered if placed below a folder called 'config', but the configuration at '"+ path + "' is placed outside!");
-            }
-            
             String pid = matcher.group("pid");
 
             int idx = pid.lastIndexOf('/');
@@ -83,6 +79,11 @@ abstract class AbstractConfigurationEntryHandler extends AbstractRegexEntryHandl
                 Objects.requireNonNull(converter.getMainPackageAssembler()).addEntry(path, archive, entry);
                 return;
             }
+
+            if (enforceConfigurationBelowConfigFolder && !"config".equals(matcher.group("foldername"))) {
+                throw new IllegalStateException("OSGi configuration are only considered if placed below a folder called 'config', but the configuration at '"+ path + "' is placed outside!");
+            }
+
             // there is a specified RunMode
             runMode = matcher.group("runmode");
 
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.java b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.java
index bc817a1..f323adf 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.java
@@ -44,6 +44,7 @@ import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter;
 import org.apache.sling.feature.cpconverter.features.DefaultFeaturesManager;
 import org.apache.sling.feature.cpconverter.features.FeaturesManager;
+import org.apache.sling.feature.cpconverter.vltpkg.VaultPackageAssembler;
 import org.apache.sling.feature.io.json.FeatureJSONReader;
 import org.apache.sling.feature.io.json.FeatureJSONWriter;
 import org.jetbrains.annotations.NotNull;
@@ -122,9 +123,27 @@ public class ConfigEntryHandlerTest {
     }
 
     @Test
-    public void testConfigPathBelowInstallFolder() {
+    public void testConfigPathBelowInstallFolder() throws Exception {
         ConfigurationEntryHandler handler = new ConfigurationEntryHandler();
         handler.setEnforceConfgurationBelowConfigFolder(true);
-        assertThrows(IllegalStateException.class, () -> { handler.handle("/jcr_root/apps/myapp/install/myconfig.config", null, null, null); });
+        Archive archive = Mockito.mock(Archive.class);
+        Entry entry = Mockito.mock(Entry.class);
+        Mockito.when(archive.openInputStream(entry)).thenReturn(new ByteArrayInputStream(new byte[0]));
+        assertThrows(IllegalStateException.class, () -> {
+            handler.handle("/jcr_root/apps/myapp/install/myconfig.config", archive, entry, Mockito.mock(ContentPackage2FeatureModelConverter.class));
+        });
+    }
+
+    @Test
+    public void testConfigPathNoneConfigBelowInstallFolder() throws Exception {
+        XmlConfigurationEntryHandler handler = new XmlConfigurationEntryHandler();
+        handler.setEnforceConfgurationBelowConfigFolder(true);
+        Archive archive = Mockito.mock(Archive.class);
+        Entry entry = Mockito.mock(Entry.class);
+        Mockito.when(archive.openInputStream(entry)).thenReturn(new ByteArrayInputStream(new byte[0]));
+        ContentPackage2FeatureModelConverter converter = Mockito.mock(ContentPackage2FeatureModelConverter.class);
+        Mockito.when(converter.getMainPackageAssembler()).thenReturn(Mockito.mock(VaultPackageAssembler.class));
+
+        handler.handle("/jcr_root/apps/asd/config/.empty.xml", archive, entry, converter);
     }
 }