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 13:04:36 UTC
[sling-org-apache-sling-feature-cpconverter] branch master updated:
SLING-10358: Enforcing configuration below config folders is not taking
into account the xml config handler (#77)
This is an automated email from the ASF dual-hosted git repository.
pauls pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git
The following commit(s) were added to refs/heads/master by this push:
new 182d05f SLING-10358: Enforcing configuration below config folders is not taking into account the xml config handler (#77)
182d05f is described below
commit 182d05f5c302bbe550ec5719bb2072ad935afef2
Author: Karl Pauls <pa...@apache.org>
AuthorDate: Fri May 7 15:04:31 2021 +0200
SLING-10358: Enforcing configuration below config folders is not taking into account the xml config handler (#77)
---
.../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);
}
}