From 866c3434b627e66aeffe353c1e4a0163a211db7e Mon Sep 17 00:00:00 2001 From: Angel Borroy Date: Thu, 29 Jul 2021 12:54:45 +0200 Subject: [PATCH] SEARCH-3022 Cherry pick from https://github.com/Alfresco/SearchServices/pull/382 --- .../solr/core/CoreDescriptorDecorator.java | 10 +++-- .../alfresco/solr/config/ConfigUtilTest.java | 42 +++++++++++++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/search-services/alfresco-search/src/main/java/org/apache/solr/core/CoreDescriptorDecorator.java b/search-services/alfresco-search/src/main/java/org/apache/solr/core/CoreDescriptorDecorator.java index 0e1b5eeee..7faf33cdb 100644 --- a/search-services/alfresco-search/src/main/java/org/apache/solr/core/CoreDescriptorDecorator.java +++ b/search-services/alfresco-search/src/main/java/org/apache/solr/core/CoreDescriptorDecorator.java @@ -91,9 +91,13 @@ public class CoreDescriptorDecorator try { - coreProperties.forEach(prop -> - properties.put(prop, ConfigUtil.locateProperty(prop,properties.getProperty(prop))) - ); + coreProperties.forEach(prop -> { + String value = ConfigUtil.locateProperty(prop, null); + if (value != null) + { + properties.put(prop, value); + } + }); } catch(Exception e) { diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/config/ConfigUtilTest.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/config/ConfigUtilTest.java index 3d55b634d..3c29ca52c 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/config/ConfigUtilTest.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/config/ConfigUtilTest.java @@ -26,14 +26,17 @@ package org.alfresco.solr.config; +import java.io.File; +import java.util.HashMap; +import java.util.Properties; + import org.alfresco.solr.AlfrescoCoreAdminHandler; import org.alfresco.solr.SolrInformationServer; +import org.apache.solr.core.CoreDescriptor; +import org.apache.solr.core.CoreDescriptorDecorator; import org.junit.Test; -import java.util.Map; - import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; /** * Tests configuring and setup of Alfresco and Solr properties @@ -74,5 +77,38 @@ public class ConfigUtilTest { assertEquals("SOLR_SOLR_PORT",ConfigUtil.convertPropertyNameToEnvironmentParam(SolrInformationServer.SOLR_PORT)); assertEquals("SOLR_SOLR_BASEURL",ConfigUtil.convertPropertyNameToEnvironmentParam(SolrInformationServer.SOLR_BASEURL)); } + + /** + * See https://github.com/Alfresco/SearchServices/pull/382 + */ + @Test + public void testMissingCoreProperty() + { + HashMap coreProps = new HashMap(); + Properties saved = (Properties)System.getProperties().clone(); + System.setProperty("alfresco.secureComms", "https"); + for (String key : CoreDescriptorDecorator.SUBSTITUTABLE_PROPERTIES_SECURE) { + // Intentionally omit store provider settings + if (!key.endsWith("store.provider")) { + // Set store type as system property + if (key.endsWith("store.type")) { + System.setProperty(key, "JKS"); + } + coreProps.put(key, "irrelevant"); + } + } + Properties contProps = new Properties(); + File tmp = new File("/tmp"); + CoreDescriptor coreDesc = new CoreDescriptor("test", tmp.toPath(), coreProps, contProps, false); + CoreDescriptorDecorator decorator = new CoreDescriptorDecorator(coreDesc); + Properties decProps = decorator.getProperties(); + // Verify store types are in system property + assertEquals("JKS", ConfigUtil.locateProperty("alfresco.encryption.ssl.keystore.type", null)); + assertEquals("JKS", ConfigUtil.locateProperty("alfresco.encryption.ssl.truststore.type", null)); + // Verify store types in CoreDescriptor came from system property + assertEquals("JKS", decProps.get("alfresco.encryption.ssl.keystore.type")); + assertEquals("JKS", decProps.get("alfresco.encryption.ssl.truststore.type")); + System.setProperties(saved); + } } \ No newline at end of file