ACS-7921: Add a default property value for solr.shardsWhitelist to the test - this should apply the setting to all HandlerFactories

This commit is contained in:
mstrankowski
2024-06-11 20:52:44 +02:00
parent 2b0373ba02
commit a2424a784a

View File

@@ -100,6 +100,8 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4
protected static final int DEFAULT_CONNECTION_TIMEOUT1 = DEFAULT_CONNECTION_TIMEOUT; protected static final int DEFAULT_CONNECTION_TIMEOUT1 = DEFAULT_CONNECTION_TIMEOUT;
protected static final int CLIENT_SO_TIMEOUT = 90000; protected static final int CLIENT_SO_TIMEOUT = 90000;
protected final static int INDEX_TIMEOUT = 100000; protected final static int INDEX_TIMEOUT = 100000;
protected static final String JETTY_CONTEXT = "/solr";
protected static final String SHARD_NAME_PREFIX = "shard";
private static AtomicInteger nodeCnt; private static AtomicInteger nodeCnt;
protected static boolean useExplicitNodeNames; protected static boolean useExplicitNodeNames;
@@ -107,6 +109,7 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4
public static Properties DEFAULT_CORE_PROPS = new Properties(); public static Properties DEFAULT_CORE_PROPS = new Properties();
protected static Map<String, JettySolrRunner> jettyContainers; protected static Map<String, JettySolrRunner> jettyContainers;
protected static int jettyPort;
protected static Map<String, SolrClient> solrCollectionNameToStandaloneClient; protected static Map<String, SolrClient> solrCollectionNameToStandaloneClient;
protected static List<JettySolrRunner> solrShards; protected static List<JettySolrRunner> solrShards;
protected static List<SolrClient> clientShards; protected static List<SolrClient> clientShards;
@@ -150,6 +153,9 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4
{ {
testClassName = testClassName + "_" + System.currentTimeMillis(); testClassName = testClassName + "_" + System.currentTimeMillis();
if (numShards > 0) {
jettyPort = getNextAvailablePort();
}
solrcoreProperties = addExplicitShardingProperty(solrcoreProperties); solrcoreProperties = addExplicitShardingProperty(solrcoreProperties);
clientShards = new ArrayList<>(); clientShards = new ArrayList<>();
@@ -164,6 +170,7 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4
String[] coreNames = new String[]{DEFAULT_TEST_CORENAME}; String[] coreNames = new String[]{DEFAULT_TEST_CORENAME};
distribSetUp(testClassName); distribSetUp(testClassName);
distribShardsSetUp(numShards);
RandomSupplier.RandVal.uniqueValues = new HashSet<>(); // reset random values RandomSupplier.RandVal.uniqueValues = new HashSet<>(); // reset random values
@@ -242,11 +249,30 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4
public static void distribSetUp(String serverName) public static void distribSetUp(String serverName)
{ {
SolrTestCaseJ4.resetExceptionIgnores(); // ignore anything with SolrTestCaseJ4.resetExceptionIgnores(); // ignore anything with
// ignore_exception in it // ignore_exception in it
System.setProperty("solr.test.sys.prop1", "propone"); System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo"); System.setProperty("solr.test.sys.prop2", "proptwo");
System.setProperty("solr.directoryFactory", "org.apache.solr.core.MockDirectoryFactory"); System.setProperty("solr.directoryFactory", "org.apache.solr.core.MockDirectoryFactory");
System.setProperty("solr.log.dir", testDir.toPath().resolve(serverName).toString()); System.setProperty("solr.log.dir", testDir.toPath().resolve(serverName).toString());
}
/**
* Needed to test fix for CVE-2017-3164
* @param numShards
*/
private static void distribShardsSetUp(int numShards){
if (numShards <= 0) {
return;
}
StringBuilder shardWhitelistBuilder = new StringBuilder();
for (int i = 0; i < numShards; i++)
{
shardWhitelistBuilder.append("127.0.0.1:").append(jettyPort).append(JETTY_CONTEXT).append("/" + SHARD_NAME_PREFIX + i).append(',');
}
shardWhitelistBuilder.deleteCharAt(shardWhitelistBuilder.length() - 1);
System.setProperty("solr.shardsWhitelist", shardWhitelistBuilder.toString());
} }
public static void distribTearDown() public static void distribTearDown()
@@ -276,7 +302,7 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4
{ {
Path jettySolrHome = testDir.toPath().resolve(jettyKey); Path jettySolrHome = testDir.toPath().resolve(jettyKey);
seedSolrHome(jettySolrHome); seedSolrHome(jettySolrHome);
return createJetty(jettySolrHome.toFile(), null, null, false, 0, getSchemaFile(), basicAuth); return createJetty(jettySolrHome.toFile(), null, null, false, jettyPort, getSchemaFile(), basicAuth);
} }
} }
@@ -365,7 +391,7 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4
Properties props = new Properties(); Properties props = new Properties();
props.putAll(additionalProperties); props.putAll(additionalProperties);
final String shardname = "shard" + i; final String shardname = SHARD_NAME_PREFIX + i;
props.put("shard.instance", Integer.toString(i)); props.put("shard.instance", Integer.toString(i));
props.put("shard.count", Integer.toString(numShards)); props.put("shard.count", Integer.toString(numShards));
@@ -469,10 +495,10 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4
if(basicAuth) if(basicAuth)
{ {
LOGGER.info("###### adding basic auth ######"); LOGGER.info("###### adding basic auth ######");
config = JettyConfig.builder().setContext("/solr").setPort(port).withFilter(BasicAuthFilter.class, "/sql/*").stopAtShutdown(true).withSSLConfig(sslConfig).build(); config = JettyConfig.builder().setContext(JETTY_CONTEXT).setPort(port).withFilter(BasicAuthFilter.class, "/sql/*").stopAtShutdown(true).withSSLConfig(sslConfig).build();
} else { } else {
LOGGER.info("###### no basic auth ######"); LOGGER.info("###### no basic auth ######");
config = JettyConfig.builder().setContext("/solr").setPort(port).stopAtShutdown(true).withSSLConfig(sslConfig).build(); config = JettyConfig.builder().setContext(JETTY_CONTEXT).setPort(port).stopAtShutdown(true).withSSLConfig(sslConfig).build();
} }
return new JettySolrRunner(solrHome.getAbsolutePath(), props, config); return new JettySolrRunner(solrHome.getAbsolutePath(), props, config);
@@ -514,7 +540,7 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4
protected static String buildUrl(int port) protected static String buildUrl(int port)
{ {
return buildUrl(port, "/solr"); return buildUrl(port, JETTY_CONTEXT);
} }
protected static String getSolrXml() protected static String getSolrXml()
@@ -577,7 +603,7 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4
} }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws IOException, ServletException throws IOException, ServletException
{ {
//Parse the basic auth filter //Parse the basic auth filter
String auth = ((HttpServletRequest)request).getHeader("Authorization"); String auth = ((HttpServletRequest)request).getHeader("Authorization");