Apache Solr open-source search software
SOLR-18357: Remove SolrTestCaseJ4 URL-allowlist system-property helpers (#4790)
Serhiy Bzhezytskyy1869a60e2e3f
diff --git a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java b/solr/core/src/test/org/apache/solr/TestTolerantSearch.javaindex 208f61e09cd..e872fcd7086 100644--- a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java+++ b/solr/core/src/test/org/apache/solr/TestTolerantSearch.java@@ -33,6 +33,7 @@ import org.apache.solr.common.util.NamedList;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.response.JavaBinResponseWriter;import org.apache.solr.response.SolrQueryResponse;+import org.apache.solr.security.AllowListUrlChecker;import org.apache.solr.util.ErrorLogMuter;import org.apache.solr.util.SolrJettyTestRule;import org.junit.AfterClass;@@ -70,7 +71,7 @@ public class TestTolerantSearch extends SolrTestCaseJ4 {@BeforeClasspublic static void createThings() throws Exception {- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");solrTestRule.startSolr(createSolrHome());collection1 = solrTestRule.getSolrClient("collection1");@@ -114,7 +115,6 @@ public class TestTolerantSearch extends SolrTestCaseJ4 {public static void destroyThings() throws Exception {collection1 = null;collection2 = null;- systemClearPropertySolrEnableUrlAllowList();}@SuppressWarnings({"unchecked", "try"})diff --git a/solr/core/src/test/org/apache/solr/handler/TestHealthCheckHandlerLegacyMode.java b/solr/core/src/test/org/apache/solr/handler/TestHealthCheckHandlerLegacyMode.javaindex 9b0f0112cdc..d9fdd3aa804 100644--- a/solr/core/src/test/org/apache/solr/handler/TestHealthCheckHandlerLegacyMode.java+++ b/solr/core/src/test/org/apache/solr/handler/TestHealthCheckHandlerLegacyMode.java@@ -33,6 +33,7 @@ import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.embedded.JettySolrRunner;+import org.apache.solr.security.AllowListUrlChecker;import org.apache.solr.util.TestInjection;import org.junit.After;import org.junit.Before;@@ -51,7 +52,7 @@ public class TestHealthCheckHandlerLegacyMode extends SolrTestCaseJ4 {public void setUp() throws Exception {super.setUp();- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");leader = new ReplicationTestHelper.SolrInstance(createTempDir("solr-instance"), "leader", null);leader.setUp();diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.javaindex 055d6ba5720..326e0ac5059 100644--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java@@ -106,7 +106,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {@Beforepublic void setUp() throws Exception {super.setUp();- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");// For manual testing only// useFactory(null); // force an FS factory.@@ -139,7 +139,6 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {@Afterpublic void tearDown() throws Exception {super.tearDown();- systemClearPropertySolrEnableUrlAllowList();if (null != leaderJetty) {leaderJetty.stop();leaderJetty = null;@@ -254,7 +253,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {public void testUrlAllowList() throws Exception {// Run another test with URL allow-list enabled and allow-list is empty.// Expect an exception because the leader URL is not allowed.- systemSetPropertyEnableUrlAllowList(true);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "true");SolrException e = expectThrows(SolrException.class, this::doTestDetails);assertTrue(e.getMessage()diff --git a/solr/core/src/test/org/apache/solr/handler/TestUserManagedReplicationWithAuth.java b/solr/core/src/test/org/apache/solr/handler/TestUserManagedReplicationWithAuth.javaindex df378434896..53e07c2bbd7 100644--- a/solr/core/src/test/org/apache/solr/handler/TestUserManagedReplicationWithAuth.java+++ b/solr/core/src/test/org/apache/solr/handler/TestUserManagedReplicationWithAuth.java@@ -42,6 +42,7 @@ import org.apache.solr.common.SolrInputDocument;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.embedded.JettySolrRunner;+import org.apache.solr.security.AllowListUrlChecker;import org.junit.After;import org.junit.Before;import org.junit.Test;@@ -74,7 +75,7 @@ public class TestUserManagedReplicationWithAuth extends SolrTestCaseJ4 {@Beforepublic void setUp() throws Exception {super.setUp();- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");// leader with Basic auth enabled via security.jsonleader = new ReplicationTestHelper.SolrInstance(createTempDir("solr-instance"), "leader", null);leader.setUp();diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.javaindex 4eefff1ee97..814f66b5fd4 100644--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java@@ -38,6 +38,7 @@ import org.apache.solr.common.params.ShardParams;import org.apache.solr.common.util.EnvUtils;import org.apache.solr.common.util.NamedList;import org.apache.solr.response.SolrQueryResponse;+import org.apache.solr.security.AllowListUrlChecker;import org.apache.solr.util.ErrorLogMuter;import org.apache.solr.util.ExternalPaths;import org.apache.solr.util.SolrJettyTestRule;@@ -57,7 +58,7 @@ public class DistributedDebugComponentTest extends SolrTestCaseJ4 {@BeforeClasspublic static void createThings() throws Exception {- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");EnvUtils.setProperty(ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());solrTestRule.startSolr();@@ -94,7 +95,6 @@ public class DistributedDebugComponentTest extends SolrTestCaseJ4 {public static void destroyThings() {collection1 = null;collection2 = null;- systemClearPropertySolrEnableUrlAllowList();}@Testdiff --git a/solr/core/src/test/org/apache/solr/search/TestSmileRequest.java b/solr/core/src/test/org/apache/solr/search/TestSmileRequest.javaindex d121c46dd5e..e8947e8234b 100644--- a/solr/core/src/test/org/apache/solr/search/TestSmileRequest.java+++ b/solr/core/src/test/org/apache/solr/search/TestSmileRequest.java@@ -31,6 +31,7 @@ import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.Utils;import org.apache.solr.response.SmileWriterTest;import org.apache.solr.search.json.TestJsonRequest;+import org.apache.solr.security.AllowListUrlChecker;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;@@ -41,7 +42,7 @@ public class TestSmileRequest extends SolrTestCaseJ4 {@BeforeClasspublic static void beforeTests() throws Exception {- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");System.setProperty("solr.requests.streaming.body.enabled", "true");JSONTestUtil.failRepeatedKeys = true;initCore("solrconfig-tlog.xml", "schema_latest.xml");@@ -60,7 +61,6 @@ public class TestSmileRequest extends SolrTestCaseJ4 {servers.stop();servers = null;}- systemClearPropertySolrEnableUrlAllowList();}@Testdiff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetErrors.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetErrors.javaindex 891ddd21d21..27f190e1376 100644--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetErrors.java+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetErrors.java@@ -30,12 +30,8 @@ import org.junit.Test;public class TestJsonFacetErrors extends SolrTestCaseHS {- private static SolrInstances servers; // for distributed testing-- @SuppressWarnings("deprecation")@BeforeClasspublic static void beforeTests() throws Exception {- systemSetPropertyEnableUrlAllowList(false);JSONTestUtil.failRepeatedKeys = true;// we need DVs on point fields to compute stats & facets@@ -45,22 +41,9 @@ public class TestJsonFacetErrors extends SolrTestCaseHS {initCore("solrconfig-tlog.xml", "schema_latest.xml");}- /** Start all servers for cluster if they don't already exist */- public static void initServers() throws Exception {- if (servers == null) {- servers = new SolrInstances(3, "solrconfig-tlog.xml", "schema_latest.xml");- }- }-- @SuppressWarnings("deprecation")@AfterClasspublic static void afterTests() throws Exception {- systemClearPropertySolrEnableUrlAllowList();JSONTestUtil.failRepeatedKeys = false;- if (servers != null) {- servers.stop();- servers = null;- }}public void indexSimple(Client client) throws Exception {diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetRefinement.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetRefinement.javaindex e0e6947f4a4..cb79ed8fbc4 100644--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetRefinement.java+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetRefinement.java@@ -29,6 +29,7 @@ import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.util.SimpleOrderedMap;import org.apache.solr.common.util.Utils;import org.apache.solr.request.SolrQueryRequest;+import org.apache.solr.security.AllowListUrlChecker;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;@@ -41,7 +42,7 @@ public class TestJsonFacetRefinement extends SolrTestCaseHS {@BeforeClasspublic static void beforeTests() throws Exception {- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");// we need DVs on point fields to compute stats & facetsif (Boolean.getBoolean(NUMERIC_POINTS_SYSPROP))System.setProperty(NUMERIC_DOCVALUES_SYSPROP, "true");@@ -63,7 +64,6 @@ public class TestJsonFacetRefinement extends SolrTestCaseHS {servers.stop();servers = null;}- systemClearPropertySolrEnableUrlAllowList();}// todo - pull up to test base class?diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.javaindex 7a6d7954c07..a061d6ea7b2 100644--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java@@ -39,6 +39,7 @@ import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.request.macro.MacroExpander;+import org.apache.solr.security.AllowListUrlChecker;import org.apache.solr.util.ErrorLogMuter;import org.apache.solr.util.hll.HLL;import org.junit.AfterClass;@@ -65,10 +66,9 @@ public class TestJsonFacets extends SolrTestCaseHS {private static int origTableSize;private static FacetField.FacetMethod origDefaultFacetMethod;- @SuppressWarnings("deprecation")@BeforeClasspublic static void beforeTests() throws Exception {- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");JSONTestUtil.failRepeatedKeys = true;origTableSize = FacetFieldProcessorByHashDV.MAXIMUM_STARTING_TABLE_SIZE;@@ -92,10 +92,8 @@ public class TestJsonFacets extends SolrTestCaseHS {}}- @SuppressWarnings("deprecation")@AfterClasspublic static void afterTests() throws Exception {- systemClearPropertySolrEnableUrlAllowList();JSONTestUtil.failRepeatedKeys = false;FacetFieldProcessorByHashDV.MAXIMUM_STARTING_TABLE_SIZE = origTableSize;FacetField.FacetMethod.DEFAULT_METHOD = origDefaultFacetMethod;diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonRangeFacets.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonRangeFacets.javaindex 47954b50973..ccade73e35e 100644--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonRangeFacets.java+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonRangeFacets.java@@ -21,6 +21,7 @@ import java.util.Arrays;import org.apache.solr.JSONTestUtil;import org.apache.solr.SolrTestCaseHS;import org.apache.solr.common.params.SolrParams;+import org.apache.solr.security.AllowListUrlChecker;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;@@ -30,10 +31,9 @@ public class TestJsonRangeFacets extends SolrTestCaseHS {private static SolrInstances servers; // for distributed testingprivate static String cache;- @SuppressWarnings("deprecation")@BeforeClasspublic static void beforeTests() throws Exception {- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");JSONTestUtil.failRepeatedKeys = true;// we need DVs on point fields to compute stats & facets@@ -51,10 +51,8 @@ public class TestJsonRangeFacets extends SolrTestCaseHS {}}- @SuppressWarnings("deprecation")@AfterClasspublic static void afterTests() throws Exception {- systemClearPropertySolrEnableUrlAllowList();JSONTestUtil.failRepeatedKeys = false;if (servers != null) {servers.stop();diff --git a/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java b/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.javaindex 2264752251a..cfc7627aac1 100644--- a/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java+++ b/solr/core/src/test/org/apache/solr/search/json/TestJsonRequest.java@@ -30,6 +30,7 @@ import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.search.CaffeineCache;import org.apache.solr.search.DocSet;+import org.apache.solr.security.AllowListUrlChecker;import org.apache.solr.util.ErrorLogMuter;import org.junit.AfterClass;import org.junit.BeforeClass;@@ -47,10 +48,9 @@ public class TestJsonRequest extends SolrTestCaseHS {private static SolrInstances servers; // for distributed testing- @SuppressWarnings("deprecation")@BeforeClasspublic static void beforeTests() throws Exception {- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");JSONTestUtil.failRepeatedKeys = true;initCore("solrconfig-tlog.xml", "schema_latest.xml");}@@ -61,7 +61,6 @@ public class TestJsonRequest extends SolrTestCaseHS {}}- @SuppressWarnings("deprecation")@AfterClasspublic static void afterTests() throws Exception {JSONTestUtil.failRepeatedKeys = false;@@ -69,7 +68,6 @@ public class TestJsonRequest extends SolrTestCaseHS {servers.stop();servers = null;}- systemClearPropertySolrEnableUrlAllowList();}@Testdiff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.javaindex 895ce0e529c..11aa4fb83a0 100644--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java@@ -68,8 +68,8 @@ import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.SolrNamedThreadFactory;import org.apache.solr.embedded.JettyConfig;import org.apache.solr.embedded.JettySolrRunner;+import org.apache.solr.security.AllowListUrlChecker;import org.eclipse.jetty.ee10.servlet.ServletHolder;-import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Rule;import org.junit.rules.TestRule;@@ -131,17 +131,10 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {r = new Random(random().nextLong());}- @SuppressWarnings("deprecation")@BeforeClass// Sets the solr.security.allow.urls.enable=false, disabling the need to provide an allow list.public static void setSolrEnableUrlUrlAllowList() {- systemSetPropertyEnableUrlAllowList(false);- }-- @SuppressWarnings("deprecation")- @AfterClass- public static void clearSolrEnableUrlUrlAllowList() {- systemClearPropertySolrEnableUrlAllowList();+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");}protected BaseDistributedSearchTestCase() {diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.javaindex 160da2b1a85..fa5dd6e6d83 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java@@ -453,7 +453,7 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {// If we want to run with allowlist, this must be explicitly set to true for the test// otherwise we disable the checkif (EnvUtils.getPropertyAsBool(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, null)) {- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");}jetty.start();diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex 0a381196312..a280f1d8a6b 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -118,7 +118,6 @@ import org.apache.solr.schema.IndexSchema;import org.apache.solr.schema.PointField;import org.apache.solr.schema.SchemaField;import org.apache.solr.search.SolrIndexSearcher;-import org.apache.solr.security.AllowListUrlChecker;import org.apache.solr.update.processor.DistributedUpdateProcessor;import org.apache.solr.update.processor.DistributedUpdateProcessor.DistribPhase;import org.apache.solr.update.processor.DistributedZkUpdateProcessor;@@ -2686,14 +2685,6 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {System.setProperty(SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICYFACTORY, value);}- @Deprecated // For backwards compatibility only. Please do not use in new tests.- protected static void systemSetPropertyEnableUrlAllowList(boolean value) {- System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, String.valueOf(value));- }-- @Deprecated // For backwards compatibility only. Please do not use in new tests.- protected static void systemClearPropertySolrEnableUrlAllowList() {}-@SafeVarargsprotected static <T> T pickRandom(T... options) {return options[random().nextInt(options.length)];diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.javaindex 3d0f636f75d..d7e78d7f0d0 100644--- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java+++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java@@ -26,6 +26,7 @@ import org.apache.solr.common.SolrInputDocument;import org.apache.solr.common.util.NamedList;import org.apache.solr.embedded.JettyConfig;import org.apache.solr.embedded.JettySolrRunner;+import org.apache.solr.security.AllowListUrlChecker;import org.apache.solr.util.ExternalPaths;import org.junit.AfterClass;import org.junit.BeforeClass;@@ -49,7 +50,7 @@ public class AdminUiReplicationStandaloneTest extends AdminUiStandaloneTestBase// sets the solr.tests.* index-config properties the test solrconfigs requirenewRandomConfig();// the follower's leaderUrl is not covered by the URL allow-list- systemSetPropertyEnableUrlAllowList(false);+ System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");Path leaderHome = buildReplicationHome("solrconfig-leader.xml", 0);leaderJetty = new JettySolrRunner(leaderHome.toString(), JettyConfig.builder().build());