This is an automated email from the ASF dual-hosted git repository. dsmiley pushed a commit to branch branch_10x in repository https://gitbox.apache.org/repos/asf/solr.git
commit 9276a90e195f4da7799fe076ba07ab0e7798218d Author: Serhiy Bzhezytskyy <[email protected]> AuthorDate: Thu Aug 27 04:25:27 2026 +0300 SOLR-18357: Remove SolrTestCaseJ4 URL-allowlist system-property helpers (#4790) (cherry picked from commit 1869a60e2e3fa6361822a471bbc0fa7dbb7bf5cb) --- .../src/test/org/apache/solr/TestTolerantSearch.java | 4 ++-- .../solr/handler/TestHealthCheckHandlerLegacyMode.java | 3 ++- .../org/apache/solr/handler/TestReplicationHandler.java | 5 ++--- .../handler/TestUserManagedReplicationWithAuth.java | 3 ++- .../component/DistributedDebugComponentTest.java | 4 ++-- .../test/org/apache/solr/search/TestSmileRequest.java | 4 ++-- .../apache/solr/search/facet/TestJsonFacetErrors.java | 17 ----------------- .../solr/search/facet/TestJsonFacetRefinement.java | 4 ++-- .../org/apache/solr/search/facet/TestJsonFacets.java | 6 ++---- .../apache/solr/search/facet/TestJsonRangeFacets.java | 6 ++---- .../org/apache/solr/search/json/TestJsonRequest.java | 6 ++---- .../org/apache/solr/BaseDistributedSearchTestCase.java | 11 ++--------- .../src/java/org/apache/solr/SolrTestCaseHS.java | 2 +- .../src/java/org/apache/solr/SolrTestCaseJ4.java | 9 --------- .../solr/webapp/AdminUiReplicationStandaloneTest.java | 3 ++- 15 files changed, 25 insertions(+), 62 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java b/solr/core/src/test/org/apache/solr/TestTolerantSearch.java index 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 { @BeforeClass public 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.java index 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.java index 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 { @Before public 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 { @After public 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.java index 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 { @Before public void setUp() throws Exception { super.setUp(); - systemSetPropertyEnableUrlAllowList(false); + System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false"); // leader with Basic auth enabled via security.json leader = 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.java index 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 { @BeforeClass public 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(); } @Test diff --git a/solr/core/src/test/org/apache/solr/search/TestSmileRequest.java b/solr/core/src/test/org/apache/solr/search/TestSmileRequest.java index 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 { @BeforeClass public 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(); } @Test diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetErrors.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetErrors.java index 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") @BeforeClass public 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") @AfterClass public 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.java index 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 { @BeforeClass public static void beforeTests() throws Exception { - systemSetPropertyEnableUrlAllowList(false); + System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false"); // we need DVs on point fields to compute stats & facets if (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.java index 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") @BeforeClass public 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") @AfterClass public 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.java index 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 testing private static String cache; - @SuppressWarnings("deprecation") @BeforeClass public 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") @AfterClass public 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.java index 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") @BeforeClass public 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") @AfterClass public static void afterTests() throws Exception { JSONTestUtil.failRepeatedKeys = false; @@ -69,7 +68,6 @@ public class TestJsonRequest extends SolrTestCaseHS { servers.stop(); servers = null; } - systemClearPropertySolrEnableUrlAllowList(); } @Test diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java index 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.java index 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 check if (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.java index 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() {} - @SafeVarargs protected 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.java index 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 require newRandomConfig(); // 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());
