Skip to content

Commit 1869a60

Browse files
SOLR-18357: Remove SolrTestCaseJ4 URL-allowlist system-property helpers (#4790)
1 parent c3064b9 commit 1869a60

15 files changed

Lines changed: 25 additions & 62 deletions

‎solr/core/src/test/org/apache/solr/TestTolerantSearch.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.solr.request.SolrQueryRequest;
3434
import org.apache.solr.response.JavaBinResponseWriter;
3535
import org.apache.solr.response.SolrQueryResponse;
36+
import org.apache.solr.security.AllowListUrlChecker;
3637
import org.apache.solr.util.ErrorLogMuter;
3738
import org.apache.solr.util.SolrJettyTestRule;
3839
import org.junit.AfterClass;
@@ -70,7 +71,7 @@ private static Path createSolrHome() throws Exception {
7071

7172
@BeforeClass
7273
public static void createThings() throws Exception {
73-
systemSetPropertyEnableUrlAllowList(false);
74+
System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");
7475
solrTestRule.startSolr(createSolrHome());
7576

7677
collection1 = solrTestRule.getSolrClient("collection1");
@@ -114,7 +115,6 @@ public static void createThings() throws Exception {
114115
public static void destroyThings() throws Exception {
115116
collection1 = null;
116117
collection2 = null;
117-
systemClearPropertySolrEnableUrlAllowList();
118118
}
119119

120120
@SuppressWarnings({"unchecked", "try"})

‎solr/core/src/test/org/apache/solr/handler/TestHealthCheckHandlerLegacyMode.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.solr.common.params.ModifiableSolrParams;
3434
import org.apache.solr.common.util.NamedList;
3535
import org.apache.solr.embedded.JettySolrRunner;
36+
import org.apache.solr.security.AllowListUrlChecker;
3637
import org.apache.solr.util.TestInjection;
3738
import org.junit.After;
3839
import org.junit.Before;
@@ -51,7 +52,7 @@ public class TestHealthCheckHandlerLegacyMode extends SolrTestCaseJ4 {
5152
public void setUp() throws Exception {
5253
super.setUp();
5354

54-
systemSetPropertyEnableUrlAllowList(false);
55+
System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");
5556

5657
leader = new ReplicationTestHelper.SolrInstance(createTempDir("solr-instance"), "leader", null);
5758
leader.setUp();

‎solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
106106
@Before
107107
public void setUp() throws Exception {
108108
super.setUp();
109-
systemSetPropertyEnableUrlAllowList(false);
109+
System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");
110110
System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
111111
// For manual testing only
112112
// useFactory(null); // force an FS factory.
@@ -139,7 +139,6 @@ public void clearIndexWithReplication() throws Exception {
139139
@After
140140
public void tearDown() throws Exception {
141141
super.tearDown();
142-
systemClearPropertySolrEnableUrlAllowList();
143142
if (null != leaderJetty) {
144143
leaderJetty.stop();
145144
leaderJetty = null;
@@ -254,7 +253,7 @@ public void doTestHandlerPathUnchanged() {
254253
public void testUrlAllowList() throws Exception {
255254
// Run another test with URL allow-list enabled and allow-list is empty.
256255
// Expect an exception because the leader URL is not allowed.
257-
systemSetPropertyEnableUrlAllowList(true);
256+
System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "true");
258257
SolrException e = expectThrows(SolrException.class, this::doTestDetails);
259258
assertTrue(
260259
e.getMessage()

‎solr/core/src/test/org/apache/solr/handler/TestUserManagedReplicationWithAuth.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.apache.solr.common.params.CommonParams;
4343
import org.apache.solr.common.params.ModifiableSolrParams;
4444
import org.apache.solr.embedded.JettySolrRunner;
45+
import org.apache.solr.security.AllowListUrlChecker;
4546
import org.junit.After;
4647
import org.junit.Before;
4748
import org.junit.Test;
@@ -74,7 +75,7 @@ public class TestUserManagedReplicationWithAuth extends SolrTestCaseJ4 {
7475
@Before
7576
public void setUp() throws Exception {
7677
super.setUp();
77-
systemSetPropertyEnableUrlAllowList(false);
78+
System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");
7879
// leader with Basic auth enabled via security.json
7980
leader = new ReplicationTestHelper.SolrInstance(createTempDir("solr-instance"), "leader", null);
8081
leader.setUp();

‎solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.solr.common.util.EnvUtils;
3939
import org.apache.solr.common.util.NamedList;
4040
import org.apache.solr.response.SolrQueryResponse;
41+
import org.apache.solr.security.AllowListUrlChecker;
4142
import org.apache.solr.util.ErrorLogMuter;
4243
import org.apache.solr.util.ExternalPaths;
4344
import org.apache.solr.util.SolrJettyTestRule;
@@ -57,7 +58,7 @@ public class DistributedDebugComponentTest extends SolrTestCaseJ4 {
5758

5859
@BeforeClass
5960
public static void createThings() throws Exception {
60-
systemSetPropertyEnableUrlAllowList(false);
61+
System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");
6162
EnvUtils.setProperty(
6263
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
6364
solrTestRule.startSolr();
@@ -94,7 +95,6 @@ public static void createThings() throws Exception {
9495
public static void destroyThings() {
9596
collection1 = null;
9697
collection2 = null;
97-
systemClearPropertySolrEnableUrlAllowList();
9898
}
9999

100100
@Test

‎solr/core/src/test/org/apache/solr/search/TestSmileRequest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.solr.common.util.Utils;
3232
import org.apache.solr.response.SmileWriterTest;
3333
import org.apache.solr.search.json.TestJsonRequest;
34+
import org.apache.solr.security.AllowListUrlChecker;
3435
import org.junit.AfterClass;
3536
import org.junit.BeforeClass;
3637
import org.junit.Test;
@@ -41,7 +42,7 @@ public class TestSmileRequest extends SolrTestCaseJ4 {
4142

4243
@BeforeClass
4344
public static void beforeTests() throws Exception {
44-
systemSetPropertyEnableUrlAllowList(false);
45+
System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");
4546
System.setProperty("solr.requests.streaming.body.enabled", "true");
4647
JSONTestUtil.failRepeatedKeys = true;
4748
initCore("solrconfig-tlog.xml", "schema_latest.xml");
@@ -60,7 +61,6 @@ public static void afterTests() throws Exception {
6061
servers.stop();
6162
servers = null;
6263
}
63-
systemClearPropertySolrEnableUrlAllowList();
6464
}
6565

6666
@Test

‎solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetErrors.java‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@
3030

3131
public class TestJsonFacetErrors extends SolrTestCaseHS {
3232

33-
private static SolrInstances servers; // for distributed testing
34-
35-
@SuppressWarnings("deprecation")
3633
@BeforeClass
3734
public static void beforeTests() throws Exception {
38-
systemSetPropertyEnableUrlAllowList(false);
3935
JSONTestUtil.failRepeatedKeys = true;
4036

4137
// we need DVs on point fields to compute stats & facets
@@ -45,22 +41,9 @@ public static void beforeTests() throws Exception {
4541
initCore("solrconfig-tlog.xml", "schema_latest.xml");
4642
}
4743

48-
/** Start all servers for cluster if they don't already exist */
49-
public static void initServers() throws Exception {
50-
if (servers == null) {
51-
servers = new SolrInstances(3, "solrconfig-tlog.xml", "schema_latest.xml");
52-
}
53-
}
54-
55-
@SuppressWarnings("deprecation")
5644
@AfterClass
5745
public static void afterTests() throws Exception {
58-
systemClearPropertySolrEnableUrlAllowList();
5946
JSONTestUtil.failRepeatedKeys = false;
60-
if (servers != null) {
61-
servers.stop();
62-
servers = null;
63-
}
6447
}
6548

6649
public void indexSimple(Client client) throws Exception {

‎solr/core/src/test/org/apache/solr/search/facet/TestJsonFacetRefinement.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.solr.common.util.SimpleOrderedMap;
3030
import org.apache.solr.common.util.Utils;
3131
import org.apache.solr.request.SolrQueryRequest;
32+
import org.apache.solr.security.AllowListUrlChecker;
3233
import org.junit.AfterClass;
3334
import org.junit.BeforeClass;
3435
import org.junit.Test;
@@ -41,7 +42,7 @@ public class TestJsonFacetRefinement extends SolrTestCaseHS {
4142

4243
@BeforeClass
4344
public static void beforeTests() throws Exception {
44-
systemSetPropertyEnableUrlAllowList(false);
45+
System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");
4546
// we need DVs on point fields to compute stats & facets
4647
if (Boolean.getBoolean(NUMERIC_POINTS_SYSPROP))
4748
System.setProperty(NUMERIC_DOCVALUES_SYSPROP, "true");
@@ -63,7 +64,6 @@ public static void afterTests() throws Exception {
6364
servers.stop();
6465
servers = null;
6566
}
66-
systemClearPropertySolrEnableUrlAllowList();
6767
}
6868

6969
// todo - pull up to test base class?

‎solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.solr.common.params.SolrParams;
4040
import org.apache.solr.request.SolrQueryRequest;
4141
import org.apache.solr.request.macro.MacroExpander;
42+
import org.apache.solr.security.AllowListUrlChecker;
4243
import org.apache.solr.util.ErrorLogMuter;
4344
import org.apache.solr.util.hll.HLL;
4445
import org.junit.AfterClass;
@@ -65,10 +66,9 @@ public class TestJsonFacets extends SolrTestCaseHS {
6566
private static int origTableSize;
6667
private static FacetField.FacetMethod origDefaultFacetMethod;
6768

68-
@SuppressWarnings("deprecation")
6969
@BeforeClass
7070
public static void beforeTests() throws Exception {
71-
systemSetPropertyEnableUrlAllowList(false);
71+
System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");
7272
JSONTestUtil.failRepeatedKeys = true;
7373

7474
origTableSize = FacetFieldProcessorByHashDV.MAXIMUM_STARTING_TABLE_SIZE;
@@ -92,10 +92,8 @@ public static void initServers() throws Exception {
9292
}
9393
}
9494

95-
@SuppressWarnings("deprecation")
9695
@AfterClass
9796
public static void afterTests() throws Exception {
98-
systemClearPropertySolrEnableUrlAllowList();
9997
JSONTestUtil.failRepeatedKeys = false;
10098
FacetFieldProcessorByHashDV.MAXIMUM_STARTING_TABLE_SIZE = origTableSize;
10199
FacetField.FacetMethod.DEFAULT_METHOD = origDefaultFacetMethod;

‎solr/core/src/test/org/apache/solr/search/facet/TestJsonRangeFacets.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.solr.JSONTestUtil;
2222
import org.apache.solr.SolrTestCaseHS;
2323
import org.apache.solr.common.params.SolrParams;
24+
import org.apache.solr.security.AllowListUrlChecker;
2425
import org.junit.AfterClass;
2526
import org.junit.BeforeClass;
2627
import org.junit.Test;
@@ -30,10 +31,9 @@ public class TestJsonRangeFacets extends SolrTestCaseHS {
3031
private static SolrInstances servers; // for distributed testing
3132
private static String cache;
3233

33-
@SuppressWarnings("deprecation")
3434
@BeforeClass
3535
public static void beforeTests() throws Exception {
36-
systemSetPropertyEnableUrlAllowList(false);
36+
System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "false");
3737
JSONTestUtil.failRepeatedKeys = true;
3838

3939
// we need DVs on point fields to compute stats & facets
@@ -51,10 +51,8 @@ public static void initServers() throws Exception {
5151
}
5252
}
5353

54-
@SuppressWarnings("deprecation")
5554
@AfterClass
5655
public static void afterTests() throws Exception {
57-
systemClearPropertySolrEnableUrlAllowList();
5856
JSONTestUtil.failRepeatedKeys = false;
5957
if (servers != null) {
6058
servers.stop();

0 commit comments

Comments
 (0)