From 0445f8200e0630e1bb8b7117f200529ed1259747 Mon Sep 17 00:00:00 2001 From: markrmiller Date: Fri, 31 Mar 2017 10:53:20 -0400 Subject: [PATCH] SOLR-10338: Configure SecureRandom non blocking for tests. --- dev-tools/idea/.idea/workspace.xml | 2 +- dev-tools/maven/pom.xml.template | 1 + lucene/common-build.xml | 3 ++ solr/CHANGES.txt | 2 + .../test/SecureRandomAlgorithmTesterApp.java | 41 +++++++++++++++++++ .../java/org/apache/solr/SolrTestCaseJ4.java | 9 ++++ 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 solr/core/src/test/SecureRandomAlgorithmTesterApp.java diff --git a/dev-tools/idea/.idea/workspace.xml b/dev-tools/idea/.idea/workspace.xml index 0ca7f0c2b70..e22108f04b4 100644 --- a/dev-tools/idea/.idea/workspace.xml +++ b/dev-tools/idea/.idea/workspace.xml @@ -2,7 +2,7 @@ - diff --git a/dev-tools/maven/pom.xml.template b/dev-tools/maven/pom.xml.template index cd8d6b8db77..6b7f915e22d 100644 --- a/dev-tools/maven/pom.xml.template +++ b/dev-tools/maven/pom.xml.template @@ -277,6 +277,7 @@ ${tests.postingsformat} ${tests.timezone} ${tests.verbose} + file:/dev/./urandom diff --git a/lucene/common-build.xml b/lucene/common-build.xml index 327a01d8486..aee7899d1f6 100644 --- a/lucene/common-build.xml +++ b/lucene/common-build.xml @@ -1062,6 +1062,9 @@ + + + diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 840de480058..097ee2b0690 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -176,6 +176,8 @@ Other Changes * SOLR-10147: Admin UI -> Cloud -> Graph: Impossible to see shard state (Amrit Sarkar, janhoy) +* SOLR-10338: Configure SecureRandom non blocking for tests. (Mihaly Toth, hossman, Ishan Chattopadhyaya, via Mark Miller) + ================== 6.5.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. diff --git a/solr/core/src/test/SecureRandomAlgorithmTesterApp.java b/solr/core/src/test/SecureRandomAlgorithmTesterApp.java new file mode 100644 index 00000000000..44f79e903c8 --- /dev/null +++ b/solr/core/src/test/SecureRandomAlgorithmTesterApp.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +public class SecureRandomAlgorithmTesterApp { + public static void main(String[] args) throws NoSuchAlgorithmException { + String algorithm = args[0]; + String method = args[1]; + int amount = Integer.valueOf(args[2]); + SecureRandom secureRandom; + if(algorithm.equals("default")) + secureRandom = new SecureRandom(); + else + secureRandom = SecureRandom.getInstance(algorithm); + System.out.println("Algorithm:" + secureRandom.getAlgorithm()); + switch(method) { + case "seed": secureRandom.generateSeed(amount); break; + case "bytes": secureRandom.nextBytes(new byte[amount]); break; + case "long": secureRandom.nextLong(); break; + case "int": secureRandom.nextInt(); break; + default: throw new IllegalArgumentException("Not supported random function: " + method); + } + System.out.println("SecureRandom function invoked"); + } +} 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 f82ccc6e975..be8e96db41e 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -39,6 +39,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.security.SecureRandom; import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; @@ -2431,6 +2432,14 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase { } } + @BeforeClass + public static void assertNonBlockingRandomGeneratorAvailable() { + if(Boolean.parseBoolean(System.getProperty("test.solr.allow.any.securerandom","false"))) + return; + // Use -Djava.security.egd=file:/dev/./urandom VM option if you hit this + assertEquals("SHA1PRNG", new SecureRandom().getAlgorithm()); + } + @AfterClass public static void unchooseMPForMP() { System.clearProperty(SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICYFACTORY);