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.
This commit is contained in:
Jack Conradson 2019-08-02 11:52:23 -07:00
parent 00235bbecd
commit 54552edaf6
2 changed files with 18 additions and 0 deletions

View File

@ -1031,6 +1031,7 @@ class java.util.UUID {
UUID fromString(String)
long getLeastSignificantBits()
long getMostSignificantBits()
UUID randomUUID()
UUID nameUUIDFromBytes(byte[])
long node()
long timestamp()

View File

@ -21,6 +21,7 @@ package org.elasticsearch.painless;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
public class BasicAPITests extends ScriptTestCase {
@ -149,4 +150,20 @@ public class BasicAPITests extends ScriptTestCase {
"return ChronoUnit.MILLIS.between(d, t);"
));
}
public void testRandomUUID() {
assertTrue(
Pattern.compile("\\p{XDigit}{8}(-\\p{XDigit}{4}){3}-\\p{XDigit}{12}").matcher(
(String)exec(
"UUID a = UUID.randomUUID();" +
"String s = a.toString(); " +
"UUID b = UUID.fromString(s);" +
"if (a.equals(b) == false) {" +
" throw new RuntimeException('uuids did not match');" +
"}" +
"return s;"
)
).matches()
);
}
}