From 939b3364e604a4a16b3c4c5f278c4d7f30f1354b Mon Sep 17 00:00:00 2001 From: Chris Hostetter Date: Tue, 15 Oct 2019 15:37:33 -0700 Subject: [PATCH] SOLR-13846: workaround - elliminate use of problematic PreemptiveBasicAuthClientBuilderFactory in tests that don't need it --- .../solr/cloud/TestQueryingOnDownCollection.java | 8 -------- .../solr/security/BasicAuthOnSingleNodeTest.java | 12 +++--------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java b/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java index 763cdd47390..1cd70f4fc37 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java @@ -18,14 +18,12 @@ package org.apache.solr.cloud; import java.lang.invoke.MethodHandles; import java.util.List; -import java.util.Locale; import java.util.Map; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.impl.Http2SolrClient; -import org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -45,10 +43,6 @@ public class TestQueryingOnDownCollection extends SolrCloudTestCase { private static final String USERNAME = "solr"; private static final String PASSWORD = "solr"; - static { - System.setProperty("basicauth", String.format(Locale.ROOT,"{}:{}", USERNAME, PASSWORD)); - } - @BeforeClass public static void setupCluster() throws Exception { configureCluster(3) @@ -107,8 +101,6 @@ public class TestQueryingOnDownCollection extends SolrCloudTestCase { // run same set of tests on v2 client which uses V2HttpCall Http2SolrClient v2Client = new Http2SolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) .build(); - PreemptiveBasicAuthClientBuilderFactory factory = new PreemptiveBasicAuthClientBuilderFactory(); - factory.setup(v2Client); error = expectThrows(SolrException.class, "Request should fail after trying all replica nodes once", diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthOnSingleNodeTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthOnSingleNodeTest.java index 974e940a10c..bcfe60862b5 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthOnSingleNodeTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthOnSingleNodeTest.java @@ -19,11 +19,10 @@ package org.apache.solr.security; import java.lang.invoke.MethodHandles; -import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.solr.client.solrj.impl.Http2SolrClient; -import org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory; import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.cloud.SolrCloudAuthTestCase; import org.junit.Before; import org.junit.Test; @@ -35,10 +34,6 @@ public class BasicAuthOnSingleNodeTest extends SolrCloudAuthTestCase { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final String COLLECTION = "authCollection"; - static { - System.setProperty("basicauth", "solr:solr"); - } - @Before public void setupCluster() throws Exception { configureCluster(1) @@ -63,13 +58,12 @@ public class BasicAuthOnSingleNodeTest extends SolrCloudAuthTestCase { public void basicTest() throws Exception { try (Http2SolrClient client = new Http2SolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) .build()){ - PreemptiveBasicAuthClientBuilderFactory factory = new PreemptiveBasicAuthClientBuilderFactory(); - factory.setup(client); // SOLR-13510, this will be failed if the listener (handling inject credential in header) is called in another // thread since SolrRequestInfo will return null in that case. for (int i = 0; i < 30; i++) { - client.query(COLLECTION, new SolrQuery("*:*")); + assertNotNull(new QueryRequest(params("q", "*:*")) + .setBasicAuthCredentials("solr", "solr").process(client, COLLECTION)); } } }