Skip to content

Commit 54552ed

Browse files
committed
Whitelist randomUUID in Painless (#45148)
This whitelists randomUUID with the understanding that it's possible for /dev/random to cause blocking on *nix systems. Users that need randomUUID should switch their random generator source to /dev/urandom if this is a concern for them.
1 parent 00235bb commit 54552ed

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/java.util.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ class java.util.UUID {
10311031
UUID fromString(String)
10321032
long getLeastSignificantBits()
10331033
long getMostSignificantBits()
1034+
UUID randomUUID()
10341035
UUID nameUUIDFromBytes(byte[])
10351036
long node()
10361037
long timestamp()

modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.util.HashMap;
2323
import java.util.Map;
24+
import java.util.regex.Pattern;
2425

2526
public class BasicAPITests extends ScriptTestCase {
2627

@@ -149,4 +150,20 @@ public void testJCZDTToZonedDateTime() {
149150
"return ChronoUnit.MILLIS.between(d, t);"
150151
));
151152
}
153+
154+
public void testRandomUUID() {
155+
assertTrue(
156+
Pattern.compile("\\p{XDigit}{8}(-\\p{XDigit}{4}){3}-\\p{XDigit}{12}").matcher(
157+
(String)exec(
158+
"UUID a = UUID.randomUUID();" +
159+
"String s = a.toString(); " +
160+
"UUID b = UUID.fromString(s);" +
161+
"if (a.equals(b) == false) {" +
162+
" throw new RuntimeException('uuids did not match');" +
163+
"}" +
164+
"return s;"
165+
)
166+
).matches()
167+
);
168+
}
152169
}

0 commit comments

Comments
 (0)