You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2013/02/19 23:55:30 UTC
svn commit: r1447956 - in /lucene/dev/branches/branch_4x: ./ dev-tools/
lucene/ lucene/analysis/
lucene/analysis/icu/src/java/org/apache/lucene/collation/ lucene/backwards/
lucene/benchmark/ lucene/codecs/ lucene/core/
lucene/core/src/test/org/apache/l...
Author: hossman
Date: Tue Feb 19 22:55:27 2013
New Revision: 1447956
URL: http://svn.apache.org/r1447956
Log:
SOLR-4394: Tests and example configs demonstrating SSL with both server and client certs (merge r1445971 + r1447885 + r1447952)
Added:
lucene/dev/branches/branch_4x/solr/example/etc/create-solrtest.keystore.sh
- copied unchanged from r1445971, lucene/dev/trunk/solr/example/etc/create-solrtest.keystore.sh
lucene/dev/branches/branch_4x/solr/example/etc/solrtest.keystore
- copied unchanged from r1445971, lucene/dev/trunk/solr/example/etc/solrtest.keystore
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/dev-tools/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/BUILD.txt (props changed)
lucene/dev/branches/branch_4x/lucene/CHANGES.txt (props changed)
lucene/dev/branches/branch_4x/lucene/JRE_VERSION_MIGRATION.txt (props changed)
lucene/dev/branches/branch_4x/lucene/LICENSE.txt (props changed)
lucene/dev/branches/branch_4x/lucene/MIGRATE.txt (props changed)
lucene/dev/branches/branch_4x/lucene/NOTICE.txt (props changed)
lucene/dev/branches/branch_4x/lucene/README.txt (props changed)
lucene/dev/branches/branch_4x/lucene/SYSTEM_REQUIREMENTS.txt (props changed)
lucene/dev/branches/branch_4x/lucene/analysis/ (props changed)
lucene/dev/branches/branch_4x/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationKeyFilterFactory.java (props changed)
lucene/dev/branches/branch_4x/lucene/backwards/ (props changed)
lucene/dev/branches/branch_4x/lucene/benchmark/ (props changed)
lucene/dev/branches/branch_4x/lucene/build.xml (props changed)
lucene/dev/branches/branch_4x/lucene/codecs/ (props changed)
lucene/dev/branches/branch_4x/lucene/common-build.xml (props changed)
lucene/dev/branches/branch_4x/lucene/core/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.cfs.zip (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.nocfs.zip (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.optimized.cfs.zip (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.optimized.nocfs.zip (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSort.java (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSortDocValues.java (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestTotalHitCountCollector.java (props changed)
lucene/dev/branches/branch_4x/lucene/demo/ (props changed)
lucene/dev/branches/branch_4x/lucene/facet/ (props changed)
lucene/dev/branches/branch_4x/lucene/grouping/ (props changed)
lucene/dev/branches/branch_4x/lucene/highlighter/ (props changed)
lucene/dev/branches/branch_4x/lucene/ivy-settings.xml (props changed)
lucene/dev/branches/branch_4x/lucene/join/ (props changed)
lucene/dev/branches/branch_4x/lucene/licenses/ (props changed)
lucene/dev/branches/branch_4x/lucene/memory/ (props changed)
lucene/dev/branches/branch_4x/lucene/misc/ (props changed)
lucene/dev/branches/branch_4x/lucene/module-build.xml (props changed)
lucene/dev/branches/branch_4x/lucene/queries/ (props changed)
lucene/dev/branches/branch_4x/lucene/queryparser/ (props changed)
lucene/dev/branches/branch_4x/lucene/sandbox/ (props changed)
lucene/dev/branches/branch_4x/lucene/site/ (props changed)
lucene/dev/branches/branch_4x/lucene/spatial/ (props changed)
lucene/dev/branches/branch_4x/lucene/suggest/ (props changed)
lucene/dev/branches/branch_4x/lucene/test-framework/ (props changed)
lucene/dev/branches/branch_4x/lucene/tools/ (props changed)
lucene/dev/branches/branch_4x/lucene/tools/junit4/tests.policy
lucene/dev/branches/branch_4x/solr/ (props changed)
lucene/dev/branches/branch_4x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/solr/LICENSE.txt (props changed)
lucene/dev/branches/branch_4x/solr/NOTICE.txt (props changed)
lucene/dev/branches/branch_4x/solr/README.txt (props changed)
lucene/dev/branches/branch_4x/solr/SYSTEM_REQUIREMENTS.txt (props changed)
lucene/dev/branches/branch_4x/solr/build.xml (props changed)
lucene/dev/branches/branch_4x/solr/cloud-dev/ (props changed)
lucene/dev/branches/branch_4x/solr/common-build.xml (props changed)
lucene/dev/branches/branch_4x/solr/contrib/ (props changed)
lucene/dev/branches/branch_4x/solr/core/ (props changed)
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java
lucene/dev/branches/branch_4x/solr/example/ (props changed)
lucene/dev/branches/branch_4x/solr/example/etc/jetty.xml
lucene/dev/branches/branch_4x/solr/licenses/ (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpclient-LICENSE-ASL.txt (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpclient-NOTICE.txt (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpcore-LICENSE-ASL.txt (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpcore-NOTICE.txt (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpmime-LICENSE-ASL.txt (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpmime-NOTICE.txt (props changed)
lucene/dev/branches/branch_4x/solr/scripts/ (props changed)
lucene/dev/branches/branch_4x/solr/site/ (props changed)
lucene/dev/branches/branch_4x/solr/solrj/ (props changed)
lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java
lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java
lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java
lucene/dev/branches/branch_4x/solr/test-framework/ (props changed)
lucene/dev/branches/branch_4x/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
lucene/dev/branches/branch_4x/solr/testlogging.properties (props changed)
lucene/dev/branches/branch_4x/solr/webapp/ (props changed)
Modified: lucene/dev/branches/branch_4x/lucene/tools/junit4/tests.policy
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/tools/junit4/tests.policy?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/tools/junit4/tests.policy (original)
+++ lucene/dev/branches/branch_4x/lucene/tools/junit4/tests.policy Tue Feb 19 22:55:27 2013
@@ -67,4 +67,7 @@ grant {
permission java.security.SecurityPermission "getProperty.networkaddress.cache.ttl";
permission java.security.SecurityPermission "getProperty.networkaddress.cache.negative.ttl";
+ // SSL related properties for Solr tests
+ permission java.security.SecurityPermission "getProperty.ssl.*";
+
};
Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Tue Feb 19 22:55:27 2013
@@ -157,6 +157,10 @@ Other Changes
* SOLR-4415: Add 'state' to shards (default to 'active') and read/write them to
ZooKeeper (Anshum Gupta via shalin)
+* SOLR-4394: Tests and example configs demonstrating SSL with both server
+ and client certs (hossman)
+
+
================== 4.1.0 ==================
Versions of Major Components
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java Tue Feb 19 22:55:27 2013
@@ -23,6 +23,9 @@ import java.util.LinkedList;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
+import java.net.URL;
+import java.net.MalformedURLException;
+
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -38,8 +41,11 @@ import org.apache.solr.servlet.SolrDispa
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
-import org.eclipse.jetty.server.handler.GzipHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.server.ssl.SslConnector;
+import org.eclipse.jetty.server.ssl.SslSocketConnector;
+import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
+import org.eclipse.jetty.server.handler.GzipHandler;
import org.eclipse.jetty.server.session.HashSessionIdManager;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
@@ -47,6 +53,7 @@ import org.eclipse.jetty.util.component.
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ThreadPool;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
/**
* Run solr using jetty
@@ -155,22 +162,59 @@ public class JettySolrRunner {
System.setProperty("solr.solr.home", solrHome);
if (System.getProperty("jetty.testMode") != null) {
final String connectorName = System.getProperty("tests.jettyConnector", "SelectChannel");
+
+ // if this property is true, then jetty will be configured to use SSL
+ // leveraging the same system properties as java to specify
+ // the keystore/truststore if they are set
+ //
+ // This means we will use the same truststore, keystore (and keys) for
+ // the server as well as any client actions taken by this JVM in
+ // talking to that server, but for the purposes of testing that should
+ // be good enough
+ final boolean useSsl = Boolean.getBoolean("tests.jettySsl");
+ final SslContextFactory sslcontext = new SslContextFactory(false);
+
+ if (useSsl) {
+ if (null != System.getProperty("javax.net.ssl.keyStore")) {
+ sslcontext.setKeyStorePath
+ (System.getProperty("javax.net.ssl.keyStore"));
+ }
+ if (null != System.getProperty("javax.net.ssl.keyStorePassword")) {
+ sslcontext.setKeyStorePassword
+ (System.getProperty("javax.net.ssl.keyStorePassword"));
+ }
+ if (null != System.getProperty("javax.net.ssl.trustStore")) {
+ sslcontext.setTrustStore
+ (System.getProperty("javax.net.ssl.trustStore"));
+ }
+ if (null != System.getProperty("javax.net.ssl.trustStorePassword")) {
+ sslcontext.setTrustStorePassword
+ (System.getProperty("javax.net.ssl.trustStorePassword"));
+ }
+ sslcontext.setNeedClientAuth(Boolean.getBoolean("tests.jettySsl.clientAuth"));
+ }
+
final Connector connector;
final QueuedThreadPool threadPool;
if ("SelectChannel".equals(connectorName)) {
- final SelectChannelConnector c = new SelectChannelConnector();
+ final SelectChannelConnector c = useSsl
+ ? new SslSelectChannelConnector(sslcontext)
+ : new SelectChannelConnector();
c.setReuseAddress(true);
c.setLowResourcesMaxIdleTime(1500);
connector = c;
threadPool = (QueuedThreadPool) c.getThreadPool();
} else if ("Socket".equals(connectorName)) {
- final SocketConnector c = new SocketConnector();
+ final SocketConnector c = useSsl
+ ? new SslSocketConnector(sslcontext)
+ : new SocketConnector();
c.setReuseAddress(true);
connector = c;
threadPool = (QueuedThreadPool) c.getThreadPool();
} else {
throw new IllegalArgumentException("Illegal value for system property 'tests.jettyConnector': " + connectorName);
}
+
connector.setPort(port);
connector.setHost("127.0.0.1");
if (threadPool != null) {
@@ -346,6 +390,31 @@ public class JettySolrRunner {
return lastPort;
}
+ /**
+ * Returns a base URL consisting of the protocal, host, and port for a
+ * Connector in use by the Jetty Server contained in this runner.
+ */
+ public URL getBaseUrl() {
+ String protocol = null;
+ try {
+ Connector[] conns = server.getConnectors();
+ if (0 == conns.length) {
+ throw new IllegalStateException("Jetty Server has no Connectors");
+ }
+ Connector c = conns[0];
+ if (c.getLocalPort() < 0) {
+ throw new IllegalStateException("Jetty Connector is not open: " +
+ c.getLocalPort());
+ }
+ protocol = (c instanceof SslConnector) ? "https" : "http";
+ return new URL(protocol, c.getHost(), c.getLocalPort(), context);
+
+ } catch (MalformedURLException e) {
+ throw new IllegalStateException
+ ("Java could not make sense of protocol: " + protocol, e);
+ }
+ }
+
public DebugFilter getDebugFilter() {
return (DebugFilter)debugFilter.getFilter();
}
Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java Tue Feb 19 22:55:27 2013
@@ -26,7 +26,6 @@ import org.apache.http.client.methods.Ht
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.client.utils.URIUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
@@ -49,10 +48,8 @@ public abstract class CacheHeaderTestBas
qparams.add(new BasicNameValuePair(params[i * 2], params[i * 2 + 1]));
}
- java.net.URI uri = URIUtils.createURI("http",
- new URI(httpserver.getBaseURL()).getHost(),
- new URI(httpserver.getBaseURL()).getPort(), "/solr/select",
- URLEncodedUtils.format(qparams, "UTF-8"), null);
+ URI uri = URI.create(httpserver.getBaseURL() + "/select?" +
+ URLEncodedUtils.format(qparams, "UTF-8"));
if ("GET".equals(method)) {
m = new HttpGet(uri);
@@ -73,10 +70,9 @@ public abstract class CacheHeaderTestBas
for(int i=0;i<params.length/2;i++) {
qparams.add(new BasicNameValuePair(params[i*2], params[i*2+1]));
}
- java.net.URI uri = URIUtils.createURI("http",
- new URI(httpserver.getBaseURL()).getHost(),
- new URI(httpserver.getBaseURL()).getPort(), "/solr/update",
- URLEncodedUtils.format(qparams, "UTF-8"), null);
+
+ URI uri = URI.create(httpserver.getBaseURL() + "/update?" +
+ URLEncodedUtils.format(qparams, "UTF-8"));
if ("GET".equals(method)) {
m=new HttpGet(uri);
Modified: lucene/dev/branches/branch_4x/solr/example/etc/jetty.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/example/etc/jetty.xml?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/example/etc/jetty.xml (original)
+++ lucene/dev/branches/branch_4x/solr/example/etc/jetty.xml Tue Feb 19 22:55:27 2013
@@ -60,6 +60,43 @@
</Arg>
</Call>
+ <!-- if the connector below is uncommented, then jetty will also accept SSL
+ connections on port 8984, using a self signed certificate and can
+ optionally require the client to authenticate with a certificate.
+ (which can be the same as the server certificate_
+
+ # Run solr example with SSL on port 8984
+ java -jar start.jar
+ #
+ # Run post.jar so that it trusts the server cert...
+ java -Djavax.net.ssl.trustStore=../etc/solrtest.keystore -Durl=https://localhost:8984/solr/update -jar post.jar *.xml
+
+ # Run solr example with SSL requiring client certs on port 8984
+ java -Djetty.ssl.clientAuth=true -jar start.jar
+ #
+ # Run post.jar so that it trusts the server cert,
+ # and authenticates with a client cert
+ java -Djavax.net.ssl.keyStorePassword=secret -Djavax.net.ssl.keyStore=../etc/solrtest.keystore -Djavax.net.ssl.trustStore=../etc/solrtest.keystore -Durl=https://localhost:8984/solr/update -jar post.jar *.xml
+
+ -->
+ <!--
+ <Call name="addConnector">
+ <Arg>
+ <New class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
+ <Arg>
+ <New class="org.eclipse.jetty.http.ssl.SslContextFactory">
+ <Set name="keyStore"><SystemProperty name="jetty.home" default="."/>/etc/solrtest.keystore</Set>
+ <Set name="keyStorePassword">secret</Set>
+ <Set name="needClientAuth"><SystemProperty name="jetty.ssl.clientAuth" default="false"/></Set>
+ </New>
+ </Arg>
+ <Set name="port"><SystemProperty name="jetty.ssl.port" default="8984"/></Set>
+ <Set name="maxIdleTime">30000</Set>
+ </New>
+ </Arg>
+ </Call>
+ -->
+
<!-- =========================================================== -->
<!-- Set handler Collection Structure -->
<!-- =========================================================== -->
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java Tue Feb 19 22:55:27 2013
@@ -25,6 +25,8 @@ import org.apache.solr.client.solrj.resp
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
@@ -32,6 +34,7 @@ import org.junit.Test;
*/
public abstract class LargeVolumeTestBase extends SolrJettyTestBase
{
+ private static Logger log = LoggerFactory.getLogger(LargeVolumeTestBase.class);
// for real load testing, make these numbers bigger
static final int numdocs = 100; //1000 * 1000;
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java Tue Feb 19 22:55:27 2013
@@ -41,7 +41,7 @@ public class SolrExampleBinaryTest exten
{
try {
// setup the server...
- String url = "http://127.0.0.1:"+port+context;
+ String url = jetty.getBaseUrl().toString();
HttpSolrServer s = new HttpSolrServer( url );
s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
s.setDefaultMaxConnectionsPerHost(100);
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java Tue Feb 19 22:55:27 2013
@@ -61,6 +61,8 @@ import org.apache.solr.common.params.Ana
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.FacetParams;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This should include tests against the example solr config
@@ -72,6 +74,8 @@ import org.junit.Test;
*/
abstract public class SolrExampleTests extends SolrJettyTestBase
{
+ private static Logger log = LoggerFactory.getLogger(SolrExampleTests.class);
+
static {
ignoreException("uniqueKey");
}
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java Tue Feb 19 22:55:27 2013
@@ -36,7 +36,7 @@ public class SolrExampleXMLTest extends
@Override
public SolrServer createNewSolrServer() {
try {
- String url = "http://127.0.0.1:" + port + context;
+ String url = jetty.getBaseUrl().toString();
HttpSolrServer s = new HttpSolrServer(url);
s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
s.setDefaultMaxConnectionsPerHost(100);
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java Tue Feb 19 22:55:27 2013
@@ -20,6 +20,7 @@ package org.apache.solr.client.solrj.emb
import org.apache.solr.client.solrj.SolrExampleTests;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.util.ExternalPaths;
+
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java Tue Feb 19 22:55:27 2013
@@ -55,7 +55,8 @@ public class SolrExampleStreamingTest ex
{
try {
// setup the server...
- String url = "http://127.0.0.1:"+port+context; // smaller queue size hits locks more often
+ String url = jetty.getBaseUrl().toString();
+ // smaller queue size hits locks more often
ConcurrentUpdateSolrServer s = new ConcurrentUpdateSolrServer( url, 2, 5 ) {
public Throwable lastError = null;
@@ -79,7 +80,7 @@ public class SolrExampleStreamingTest ex
// SOLR-3903
final List<Throwable> failures = new ArrayList<Throwable>();
ConcurrentUpdateSolrServer s = new ConcurrentUpdateSolrServer
- ("http://127.0.0.1:"+port+context, 2, 2) {
+ (jetty.getBaseUrl().toString(), 2, 2) {
@Override
public void handleError(Throwable ex) {
failures.add(ex);
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java Tue Feb 19 22:55:27 2013
@@ -147,8 +147,8 @@ public class BasicHttpSolrServerTest ext
@Test
public void testTimeout() throws Exception {
- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"
- + jetty.getLocalPort() + "/solr/slow/foo");
+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() +
+ "/slow/foo");
SolrQuery q = new SolrQuery("*:*");
server.setSoTimeout(2000);
try {
@@ -163,8 +163,8 @@ public class BasicHttpSolrServerTest ext
@Test
public void testQuery(){
DebugServlet.clear();
- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"
- + jetty.getLocalPort() + "/solr/debug/foo");
+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() +
+ "/debug/foo");
SolrQuery q = new SolrQuery("foo");
q.setParam("a", "\u1234");
try {
@@ -250,8 +250,8 @@ public class BasicHttpSolrServerTest ext
@Test
public void testDelete(){
DebugServlet.clear();
- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"
- + jetty.getLocalPort() + "/solr/debug/foo");
+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() +
+ "/debug/foo");
try {
server.deleteById("id");
} catch (Throwable t) {}
@@ -291,8 +291,8 @@ public class BasicHttpSolrServerTest ext
@Test
public void testUpdate(){
DebugServlet.clear();
- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"
- + jetty.getLocalPort() + "/solr/debug/foo");
+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() +
+ "/debug/foo");
UpdateRequest req = new UpdateRequest();
req.add(new SolrInputDocument());
req.setParam("a", "\u1234");
@@ -352,8 +352,8 @@ public class BasicHttpSolrServerTest ext
@Test
public void testRedirect() throws Exception {
- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"
- + jetty.getLocalPort() + "/solr/redirect/foo");
+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() +
+ "/redirect/foo");
SolrQuery q = new SolrQuery("*:*");
// default = false
try {
@@ -373,8 +373,8 @@ public class BasicHttpSolrServerTest ext
@Test
public void testCompression() throws Exception {
- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:"
- + jetty.getLocalPort() + "/solr/debug/foo");
+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() +
+ "/debug/foo");
SolrQuery q = new SolrQuery("*:*");
// verify request header gets set
@@ -395,8 +395,8 @@ public class BasicHttpSolrServerTest ext
assertNull(DebugServlet.headers.get("Accept-Encoding"));
// verify server compresses output
- HttpGet get = new HttpGet("http://127.0.0.1:" + jetty.getLocalPort()
- + "/solr/select?q=foo&wt=xml");
+ HttpGet get = new HttpGet(jetty.getBaseUrl().toString() +
+ "/select?q=foo&wt=xml");
get.setHeader("Accept-Encoding", "gzip");
HttpClient client = HttpClientUtil.createClient(null);
HttpEntity entity = null;
@@ -414,8 +414,7 @@ public class BasicHttpSolrServerTest ext
}
// verify compressed response can be handled
- server = new HttpSolrServer("http://127.0.0.1:" + jetty.getLocalPort()
- + "/solr");
+ server = new HttpSolrServer(jetty.getBaseUrl().toString());
server.setAllowCompression(true);
q = new SolrQuery("foo");
QueryResponse response = server.query(q);
@@ -426,7 +425,8 @@ public class BasicHttpSolrServerTest ext
@Test
public void testSetParametersExternalClient(){
HttpClient client = HttpClientUtil.createClient(null);
- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1/", client);
+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString(),
+ client);
try {
server.setMaxTotalConnections(1);
fail("Operation should not succeed.");
@@ -441,7 +441,8 @@ public class BasicHttpSolrServerTest ext
@Test
public void testGetRawStream() throws SolrServerException, IOException{
HttpClient client = HttpClientUtil.createClient(null);
- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:" + jetty.getLocalPort() + "/solr", client, null);
+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString(),
+ client, null);
QueryRequest req = new QueryRequest();
NamedList response = server.request(req);
InputStream stream = (InputStream)response.get("stream");
Modified: lucene/dev/branches/branch_4x/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java?rev=1447956&r1=1447955&r2=1447956&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java (original)
+++ lucene/dev/branches/branch_4x/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java Tue Feb 19 22:55:27 2013
@@ -22,16 +22,71 @@ import org.apache.solr.client.solrj.embe
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.util.ExternalPaths;
+
+import java.io.File;
+import java.util.Map;
+import java.util.HashMap;
+
import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
abstract public class SolrJettyTestBase extends SolrTestCaseJ4
{
+ private static Logger log = LoggerFactory.getLogger(SolrJettyTestBase.class);
+
// Try not introduce a dependency on the example schema or config unless you need to.
// using configs in the test directory allows more flexibility to change "example"
// without breaking configs.
-
public String getSolrHome() { return ExternalPaths.EXAMPLE_HOME; }
+ private static boolean manageSslProps = true;
+ private static final File TEST_KEYSTORE = new File(ExternalPaths.SOURCE_HOME,
+ "example/etc/solrtest.keystore");
+ private static final Map<String,String> SSL_PROPS = new HashMap<String,String>();
+ static {
+ SSL_PROPS.put("tests.jettySsl","false");
+ SSL_PROPS.put("tests.jettySsl.clientAuth","false");
+ SSL_PROPS.put("javax.net.ssl.keyStore", TEST_KEYSTORE.getAbsolutePath());
+ SSL_PROPS.put("javax.net.ssl.keyStorePassword","secret");
+ SSL_PROPS.put("javax.net.ssl.trustStore", TEST_KEYSTORE.getAbsolutePath());
+ SSL_PROPS.put("javax.net.ssl.trustStorePassword","secret");
+ }
+
+ @BeforeClass
+ public static void beforeSolrJettyTestBase() throws Exception {
+
+ // consume the same amount of random no matter what
+ final boolean trySsl = random().nextBoolean();
+ final boolean trySslClientAuth = random().nextBoolean();
+
+ // only randomize SSL if none of the SSL_PROPS are already set
+ final Map<Object,Object> sysprops = System.getProperties();
+ for (String prop : SSL_PROPS.keySet()) {
+ if (sysprops.containsKey(prop)) {
+ log.info("System property explicitly set, so skipping randomized ssl properties: " + prop);
+ manageSslProps = false;
+ break;
+ }
+ }
+
+ assertTrue("test keystore does not exist, can't be used for randomized " +
+ "ssl testing: " + TEST_KEYSTORE.getAbsolutePath(),
+ TEST_KEYSTORE.exists() );
+
+ if (manageSslProps) {
+ log.info("Randomized ssl ({}) and clientAuth ({})", trySsl, trySslClientAuth);
+ for (String prop : SSL_PROPS.keySet()) {
+ System.setProperty(prop, SSL_PROPS.get(prop));
+ }
+ // now explicitly re-set the two random values
+ System.setProperty("tests.jettySsl", String.valueOf(trySsl));
+ System.setProperty("tests.jettySsl.clientAuth", String.valueOf(trySslClientAuth));
+ }
+ }
+
public static JettySolrRunner jetty;
public static int port;
public static SolrServer server = null;
@@ -64,6 +119,11 @@ abstract public class SolrJettyTestBase
jetty = null;
}
server = null;
+ if (manageSslProps) {
+ for (String prop : SSL_PROPS.keySet()) {
+ System.clearProperty(prop);
+ }
+ }
}
@@ -86,7 +146,7 @@ abstract public class SolrJettyTestBase
if (jetty != null) {
try {
// setup the server...
- String url = "http://127.0.0.1:"+port+context;
+ String url = jetty.getBaseUrl().toString();
HttpSolrServer s = new HttpSolrServer( url );
s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
s.setDefaultMaxConnectionsPerHost(100);