Skip to content

Commit c95e74e

Browse files
committed
Avoid blocking non-reproducible randomness in test (#36561)
The security documentation test uses SecureRandom#getStrongInstance. This defaults to securerandom.strongAlgorithms=NativePRNGBlocking:SUN,DRBG:SUN which means a blocking implementation that reads from /dev/random. This means that this test can stall if the entropy on the machine is exhausted. Anyway, it also means that the randomness is non-reproducible, a thing that we try to avoid in tests. This commit switches to a boring randomness source to avoid the blocking, and to keep the test reproducible.
1 parent 4c6c8c0 commit c95e74e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SecurityDocumentationIT.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,21 @@
7171
import org.elasticsearch.client.security.support.expressiondsl.expressions.AnyRoleMapperExpression;
7272
import org.elasticsearch.client.security.support.expressiondsl.fields.FieldRoleMapperExpression;
7373
import org.elasticsearch.client.security.user.User;
74-
import org.elasticsearch.client.security.user.privileges.Role;
7574
import org.elasticsearch.client.security.user.privileges.ApplicationPrivilege;
75+
import org.elasticsearch.client.security.user.privileges.ApplicationResourcePrivileges;
7676
import org.elasticsearch.client.security.user.privileges.IndicesPrivileges;
77+
import org.elasticsearch.client.security.user.privileges.Role;
78+
import org.elasticsearch.client.security.user.privileges.UserIndicesPrivileges;
7779
import org.elasticsearch.common.util.set.Sets;
7880
import org.hamcrest.Matchers;
7981

8082
import javax.crypto.SecretKeyFactory;
8183
import javax.crypto.spec.PBEKeySpec;
84+
8285
import java.io.IOException;
83-
import java.security.SecureRandom;
84-
import java.util.Base64;
8586
import java.util.ArrayList;
8687
import java.util.Arrays;
88+
import java.util.Base64;
8789
import java.util.Collections;
8890
import java.util.HashMap;
8991
import java.util.Iterator;
@@ -94,8 +96,8 @@
9496
import java.util.concurrent.TimeUnit;
9597

9698
import static org.hamcrest.Matchers.contains;
97-
import static org.hamcrest.Matchers.containsString;
9899
import static org.hamcrest.Matchers.containsInAnyOrder;
100+
import static org.hamcrest.Matchers.containsString;
99101
import static org.hamcrest.Matchers.empty;
100102
import static org.hamcrest.Matchers.emptyIterable;
101103
import static org.hamcrest.Matchers.equalTo;
@@ -128,7 +130,8 @@ public void testPutUser() throws Exception {
128130
}
129131
{
130132
byte[] salt = new byte[32];
131-
SecureRandom.getInstanceStrong().nextBytes(salt);
133+
// no need for secure random in a test; it could block and would not be reproducible anyway
134+
random().nextBytes(salt);
132135
char[] password = new char[]{'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
133136
User user = new User("example2", Collections.singletonList("superuser"));
134137

0 commit comments

Comments
 (0)