-
Notifications
You must be signed in to change notification settings - Fork 3
Closed
Description
If JSDOMNodeJSEnv is used, crypt
npm module is not loaded (require("crypto")
), so using UUID.randomUUID() in Scala.js will throw java.lang.UnsupportedOperationException.
build.sbt:
Test / jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv()
An example exception:
java.security.SecureRandom is not supported on this platform because it provides neither `crypto.getRandomValues` nor Node.js' "crypto" module.
java.lang.UnsupportedOperationException: java.security.SecureRandom is not supported on this platform because it provides neither `crypto.getRandomValues` nor Node.js' "crypto" module.
at java.security.SecureRandom$.notSupported(file:///Users/leo/work/git/airframe/airframe-http/.js/target/scala-2.13/airframe-http-test-fastopt/main.js:25407:51)
at java.security.SecureRandom$.getRandomValuesFun$lzycompute(file:///Users/leo/work/git/airframe/airframe-http/.js/target/scala-2.13/airframe-http-test-fastopt/main.js:25401:128)
at java.security.SecureRandom$.java$security$SecureRandom$$getRandomValuesFun(file:///Users/leo/work/git/airframe/airframe-http/.js/target/scala-2.13/airframe-http-test-fastopt/main.js:25437:62)
at java.security.SecureRandom.<init>(file:///Users/leo/work/git/airframe/airframe-http/.js/target/scala-2.13/airframe-http-test-fastopt/main.js:37078:94)
at java.util.UUID$.csprng$lzycompute(file:///Users/leo/work/git/airframe/airframe-http/.js/target/scala-2.13/airframe-http-test-fastopt/main.js:26996:32)
at java.util.UUID$.csprng(file:///Users/leo/work/git/airframe/airframe-http/.js/target/scala-2.13/airframe-http-test-fastopt/main.js:27002:70)
at java.util.UUID$.randomUUID(file:///Users/leo/work/git/airframe/airframe-http/.js/target/scala-2.13/airframe-http-test-fastopt/main.js:27032:3)
Related:
- Provide Node.js interface through
global
object inJSDOMNodeJSEnv
scalacenter/scalajs-bundler#197 (Something like this is needed for calling require("crypto") at Node.js) - scala.js 1.10.0 UUID.newUUID() depends on java.security.SecureRandom: [CVE-2022-28355] Scala.js should not provide a cryptographically insecure
UUID.randomUUID()
implementation scala-js#4657 - Found this issue when using scala-js-java-securerandom Add scala-js-java-securerandom for Scala.js 1.10.0 wvlet/airframe#2117
A workaround is trying to avoid using UUID.newUUID() in Scala.js during testing with NodeJS and DOM
Metadata
Metadata
Assignees
Labels
No labels