Skip to content

Commit 57ff174

Browse files
author
schallee@darkmist.net
committed
Switch from SecureRandom to Random seeded by SecureRandom.
Remove one unused variable.
1 parent 846ad44 commit 57ff174

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

src/test/java/org/owasp/esapi/util/FileTestUtils.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,30 @@ public class FileTestUtils
1414
private static final String CLASS_NAME = CLASS.getName();
1515
private static final String DEFAULT_PREFIX = CLASS_NAME + '.';
1616
private static final String DEFAULT_SUFFIX = ".tmp";
17-
private static final Random rand = new SecureRandom();
17+
private static final Random rand;
18+
19+
/*
20+
Rational for switching from SecureRandom to Random:
21+
22+
This is used for generating filenames for temporary
23+
directories. Origionally this was using SecureRandom for
24+
this to make /tmp races harder. This is not necessary as
25+
mkdir always returns false if if the directory already
26+
exists.
27+
28+
Additionally, SecureRandom for some reason on linux
29+
is appears to be reading from /dev/random instead of
30+
/dev/urandom. As such, the many calls for temporary
31+
directories in the unit tests quickly depleates the
32+
entropy pool causing unit test runs to block until more
33+
entropy is collected (this is why moving the mouse speeds
34+
up unit tests).
35+
*/
36+
static
37+
{
38+
SecureRandom secRand = new SecureRandom();
39+
rand = new Random(secRand.nextLong());
40+
}
1841

1942
/** Private constructor as all methods are static. */
2043
private FileTestUtils()
@@ -171,7 +194,6 @@ public static void deleteRecursively(File file) throws IOException
171194
{
172195
File[] children;
173196
File child;
174-
File childsParent;
175197

176198
if(file == null || !file.exists())
177199
return; // already deleted?

0 commit comments

Comments
 (0)