You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2020/10/23 16:40:09 UTC

[geode] branch develop updated: GEODE-8648: Use SecureRandom in RandomRule (#5657)

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

klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 3bb3b19  GEODE-8648: Use SecureRandom in RandomRule (#5657)
3bb3b19 is described below

commit 3bb3b194b2571e91da4623df7f4d22a5627eb9b2
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri Oct 23 09:39:17 2020 -0700

    GEODE-8648: Use SecureRandom in RandomRule (#5657)
---
 .../apache/geode/test/junit/rules/RandomRule.java  | 26 +++++++++++-----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/RandomRule.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/RandomRule.java
index 36e8f67..6f07cd3 100644
--- a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/RandomRule.java
+++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/RandomRule.java
@@ -19,8 +19,8 @@ import static java.util.Objects.requireNonNull;
 import static java.util.stream.Collectors.toList;
 import static java.util.stream.StreamSupport.stream;
 
+import java.security.SecureRandom;
 import java.util.List;
-import java.util.Random;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.junit.runner.Description;
@@ -30,24 +30,24 @@ import org.apache.geode.test.junit.rules.serializable.SerializableStatement;
 import org.apache.geode.test.junit.rules.serializable.SerializableTestRule;
 
 @SuppressWarnings({"serial", "unused", "WeakerAccess", "NumericCastThatLosesPrecision"})
-public class RandomRule extends Random implements GsRandom, SerializableTestRule {
+public class RandomRule extends SecureRandom implements GsRandom, SerializableTestRule {
 
-  private final AtomicReference<Random> random = new AtomicReference<>();
-  private final long seed;
+  private final AtomicReference<SecureRandom> random = new AtomicReference<>();
+  private final byte[] seed;
 
   public RandomRule() {
-    this(0);
+    this(null, null);
   }
 
-  public RandomRule(long seed) {
+  public RandomRule(byte[] seed) {
     this(null, seed);
   }
 
-  public RandomRule(Random random) {
-    this(random, 0);
+  public RandomRule(SecureRandom random) {
+    this(random, null);
   }
 
-  private RandomRule(Random random, long seed) {
+  private RandomRule(SecureRandom random, byte[] seed) {
     this.random.set(random);
     this.seed = seed;
   }
@@ -258,11 +258,11 @@ public class RandomRule extends Random implements GsRandom, SerializableTestRule
     return requireNonEmpty(list).get(nextInt(0, list.size() - 1));
   }
 
-  private Random newRandom() {
-    if (seed == 0) {
-      return new Random();
+  private SecureRandom newRandom() {
+    if (seed == null) {
+      return new SecureRandom();
     }
-    return new Random(seed);
+    return new SecureRandom(seed);
   }
 
   private <T> List<T> requireNonEmpty(List<T> list) {