You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2019/12/11 18:27:11 UTC

[lucene-solr] branch branch_8x updated: SOLR-14050: clean up tests use of network addresses

This is an automated email from the ASF dual-hosted git repository.

rmuir pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new 715b215  SOLR-14050: clean up tests use of network addresses
715b215 is described below

commit 715b2151ac990d37df10393d59d24d5af66284e9
Author: Robert Muir <rm...@apache.org>
AuthorDate: Wed Dec 11 12:51:45 2019 -0500

    SOLR-14050: clean up tests use of network addresses
    
    Solr tests now have a similar policy to Lucene, loopback use only. If a
    test tries to resolve or connect to the internet, it will get SecurityException.
    
    Some solr tests explicitly try to talk to dead nodes with real
    networking. This is not good and asking for trouble, but use low loopback port numbers instead of
    multicast addresses. The idea is that it fails faster. Move these to
    constants so that stuff isn't copy-pasted everywhere, in case we have to
    do something different later.
---
 lucene/tools/junit4/solr-tests.policy                    | 15 ++++++++-------
 .../dataimport/TestSolrEntityProcessorEndToEnd.java      |  2 +-
 .../solr/cloud/TestSolrCloudWithSecureImpersonation.java |  4 ++--
 .../solr/handler/component/CustomTermsComponentTest.java |  2 +-
 .../handler/component/DistributedDebugComponentTest.java |  2 +-
 .../org/apache/solr/search/facet/TestJsonFacets.java     |  2 +-
 .../security/hadoop/TestImpersonationWithHadoopAuth.java |  2 +-
 .../org/apache/solr/update/SolrCmdDistributorTest.java   |  2 +-
 .../test/org/apache/solr/util/SimplePostToolTest.java    |  7 +++----
 .../org/apache/solr/client/solrj/SolrExceptionTest.java  |  3 ++-
 .../solr/client/solrj/impl/CloudHttp2SolrClientTest.java |  2 +-
 .../solr/client/solrj/impl/CloudSolrClientTest.java      |  2 +-
 .../org/apache/solr/BaseDistributedSearchTestCase.java   |  6 +++---
 .../src/java/org/apache/solr/SolrTestCaseJ4.java         | 16 ++++++++++++++++
 14 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/lucene/tools/junit4/solr-tests.policy b/lucene/tools/junit4/solr-tests.policy
index 00dae24..816c7c3 100644
--- a/lucene/tools/junit4/solr-tests.policy
+++ b/lucene/tools/junit4/solr-tests.policy
@@ -51,13 +51,14 @@ grant {
 
   permission java.nio.file.LinkPermission "hard";
   
-  // all possibilities of accepting/binding connections on localhost with ports >=1024:
-  permission java.net.SocketPermission "localhost:1024-", "accept,listen";
-  permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
-  permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
-  
-  // Allow connecting to the internet anywhere
-  permission java.net.SocketPermission "*", "connect,resolve";
+  // all possibilities of accepting/binding/connections on localhost with ports >=1024:
+  permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect,resolve";
+  permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
+  permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
+  // "dead hosts", we try to keep it fast
+  permission java.net.SocketPermission "[::1]:4", "connect,resolve";
+  permission java.net.SocketPermission "[::1]:6", "connect,resolve";
+  permission java.net.SocketPermission "[::1]:8", "connect,resolve";
   
   // Basic permissions needed for Lucene to work:
   permission java.util.PropertyPermission "*", "read,write";
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
index 0bf9cc2..9c4e957 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
@@ -54,7 +54,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
   private static final String SOURCE_CONF_DIR = "dih" + File.separator + "solr" + File.separator + "collection1" + File.separator + "conf" + File.separator;
   private static final String ROOT_DIR = "dih" + File.separator + "solr" + File.separator;
 
-  private static final String DEAD_SOLR_SERVER = "http://[ff01::114]:33332/solr";
+  private static final String DEAD_SOLR_SERVER = "http://" + DEAD_HOST_1 + "/solr";
   
   private static final List<Map<String,Object>> DB_DOCS = new ArrayList<>();
   private static final List<Map<String,Object>> SOLR_DOCS = new ArrayList<>();
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java b/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java
index a149b33..c8e4457 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java
@@ -77,7 +77,7 @@ public class TestSolrCloudWithSecureImpersonation extends SolrTestCaseJ4 {
     filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "noGroups.hosts", "*");
     filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "anyHostAnyUser.groups", "*");
     filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "anyHostAnyUser.hosts", "*");
-    filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "wrongHost.hosts", "1.1.1.1.1.1");
+    filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "wrongHost.hosts", DEAD_HOST_1);
     filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "wrongHost.groups", "*");
     filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "noHosts.groups", "*");
     filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "localHostAnyGroup.groups", "*");
@@ -290,7 +290,7 @@ public class TestSolrCloudWithSecureImpersonation extends SolrTestCaseJ4 {
   public void testProxyInvalidRemote() throws Exception {
     HttpSolrClient.RemoteSolrException e = expectThrows(HttpSolrClient.RemoteSolrException.class,
         () -> {
-          String invalidIpAddress = "-127.-128";
+          String invalidIpAddress = DEAD_HOST_2;
           solrClient.request(getProxyRequest("localHostAnyGroup","bar", "[ff01::114]", invalidIpAddress));
     });
     assertTrue(e.getMessage().contains(getExpectedHostExMsg("localHostAnyGroup")));
diff --git a/solr/core/src/test/org/apache/solr/handler/component/CustomTermsComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/CustomTermsComponentTest.java
index b0836f1..f648535 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/CustomTermsComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/CustomTermsComponentTest.java
@@ -155,7 +155,7 @@ public class CustomTermsComponentTest extends ShardsWhitelistTest {
     // this case should fail
     findAndCheckTerms(cluster, collection,
         defaultHandlerName,
-        shards + ",http://[ff01::114]:33332", // ... with specified shards with one invalid
+        shards + ",http://" + DEAD_HOST_1, // ... with specified shards with one invalid
         (random().nextBoolean() ? null : f1), v1,
         (random().nextBoolean() ? null : f2), v2,
         "No live SolrServers available to handle this request");
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 49b7ece..e395825 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
@@ -388,7 +388,7 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
   }
   
   public void testTolerantSearch() throws SolrServerException, IOException {
-    String badShard = "[ff01::0083]:3334";
+    String badShard = DEAD_HOST_1;
     SolrQuery query = new SolrQuery();
     query.setQuery("*:*");
     query.set("debug",  "true");
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 e85a295..a0fb090 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
@@ -2972,7 +2972,7 @@ public class TestJsonFacets extends SolrTestCaseHS {
   public void testTolerant() throws Exception {
     initServers();
     Client client = servers.getClient(random().nextInt());
-    client.queryDefaults().set("shards", servers.getShards() + ",[ff01::114]:33332/ignore_exception");
+    client.queryDefaults().set("shards", servers.getShards() + "," + DEAD_HOST_1 + "/ignore_exception");
     indexSimple(client);
 
     try {
diff --git a/solr/core/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java b/solr/core/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java
index 5ce7527..d603fd2 100644
--- a/solr/core/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java
+++ b/solr/core/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java
@@ -63,7 +63,7 @@ public class TestImpersonationWithHadoopAuth  extends SolrCloudTestCase {
     proxyUserConfigs.put("proxyuser.noGroups.hosts", "*");
     proxyUserConfigs.put("proxyuser.anyHostAnyUser.hosts", "*");
     proxyUserConfigs.put("proxyuser.anyHostAnyUser.groups", "*");
-    proxyUserConfigs.put("proxyuser.wrongHost.hosts", "1.1.1.1.1.1");
+    proxyUserConfigs.put("proxyuser.wrongHost.hosts", DEAD_HOST_1);
     proxyUserConfigs.put("proxyuser.wrongHost.groups", "*");
     proxyUserConfigs.put("proxyuser.noHosts.groups", "*");
     proxyUserConfigs.put("proxyuser.localHostAnyGroup.hosts",
diff --git a/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java b/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java
index f6d7087..36c511f 100644
--- a/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java
+++ b/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java
@@ -795,7 +795,7 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
 
       ArrayList<Node> nodes = new ArrayList<>();
 
-      ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, "[ff01::114]:33332" + context, ZkStateReader.CORE_NAME_PROP, "");
+      ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, DEAD_HOST_1 + context, ZkStateReader.CORE_NAME_PROP, "");
       ForwardNode retryNode = new ForwardNode(new ZkCoreNodeProps(nodeProps), null, "collection1", "shard1", 5) {
         @Override
         public boolean checkRetry(Error err) {
diff --git a/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java b/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java
index b9eaa63..39036ef 100644
--- a/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java
+++ b/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java
@@ -24,6 +24,7 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
@@ -37,9 +38,7 @@ import org.junit.Test;
 /**
  * NOTE: do *not* use real hostnames, not even "example.com", in this test.
  *
- * Even though a MockPageFetcher is used to prevent real HTTP requests from being 
- * executed, the use of the URL class in SimplePostTool causes attempted resolution of 
- * the hostnames.
+ * A MockPageFetcher is used to prevent real HTTP requests from being executed.
  */ 
 public class SimplePostToolTest extends SolrTestCaseJ4 {
 
@@ -173,7 +172,7 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
     assertEquals(3, num);
     
     // Without respecting robots.txt
-    t_web.pageFetcher.robotsCache.clear();
+    t_web.pageFetcher.robotsCache.put("[ff01::114]", Collections.emptyList());
     t_web.recursive = 5;
     num = t_web.postWebPages(new String[] {"http://[ff01::114]/#removeme"}, 0, null);
     assertEquals(6, num);
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java
index c894a6a..9dbb03c 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java
@@ -20,6 +20,7 @@ import static org.apache.solr.SolrTestCaseJ4.getHttpSolrClient;
 
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.solr.SolrTestCase;
+import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.client.solrj.impl.HttpClientUtil;
 import org.apache.solr.client.solrj.impl.HttpSolrClient;
 import org.junit.Test;
@@ -43,7 +44,7 @@ public class SolrExceptionTest extends SolrTestCase {
       // switched to a local address to avoid going out on the net, ns lookup issues, etc.
       // set a 1ms timeout to let the connection fail faster.
       httpClient = HttpClientUtil.createClient(null);
-      try (HttpSolrClient client = getHttpSolrClient("http://[ff01::114]:11235/solr/", httpClient, 1)) {
+      try (HttpSolrClient client = getHttpSolrClient("http://" + SolrTestCaseJ4.DEAD_HOST_1 + "/solr/", httpClient, 1)) {
         SolrQuery query = new SolrQuery("test123");
         client.query(query);
       }
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
index 74b02cb..c398227 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
@@ -752,7 +752,7 @@ public class CloudHttp2SolrClientTest extends SolrCloudTestCase {
 
   @Test
   public void testShutdown() throws IOException {
-    try (CloudSolrClient client = getCloudSolrClient("[ff01::114]:33332")) {
+    try (CloudSolrClient client = getCloudSolrClient(DEAD_HOST_1)) {
       client.setZkConnectTimeout(100);
       client.connect();
       fail("Expected exception");
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
index 57050ce..943b26c 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
@@ -738,7 +738,7 @@ public class CloudSolrClientTest extends SolrCloudTestCase {
 
   @Test
   public void testShutdown() throws IOException {
-    try (CloudSolrClient client = getCloudSolrClient("[ff01::114]:33332")) {
+    try (CloudSolrClient client = getCloudSolrClient(DEAD_HOST_1)) {
       client.setZkConnectTimeout(100);
       SolrException ex = expectThrows(SolrException.class, client::connect);
       assertTrue(ex.getCause() instanceof TimeoutException);
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 a881084..f0ab629 100644
--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
@@ -223,9 +223,9 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
    */
   protected BaseDistributedSearchTestCase(final String context) {
     this.context = context;
-    this.deadServers = new String[] {"[ff01::114]:33332" + context, 
-                                     "[ff01::083]:33332" + context, 
-                                     "[ff01::213]:33332" + context};
+    this.deadServers = new String[] {DEAD_HOST_1 + context,
+                                     DEAD_HOST_2 + context,
+                                     DEAD_HOST_3 + context};
   }
 
   private final static int DEFAULT_MAX_SHARD_COUNT = 3;
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 2d17249..cfeb89d 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -378,6 +378,22 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
     }
   }
   
+  /**
+   * a "dead" host, if you try to connect to it, it will likely fail fast
+   * please consider using mocks and not real networking to simulate failure
+   */
+  public static final String DEAD_HOST_1 = "[::1]:4";
+  /**
+   * a "dead" host, if you try to connect to it, it will likely fail fast
+   * please consider using mocks and not real networking to simulate failure
+   */
+  public static final String DEAD_HOST_2 = "[::1]:6";
+  /**
+   * a "dead" host, if you try to connect to it, it will likely fail fast
+   * please consider using mocks and not real networking to simulate failure
+   */
+  public static final String DEAD_HOST_3 = "[::1]:8";
+
   /** Assumes that Mockito/Bytebuddy is available and can be used to mock classes (e.g., fails if Java version is too new). */
   public static void assumeWorkingMockito() {
     // we use reflection here, because we do not have ByteBuddy/Mockito in all modules and the test framework!