From 0972d8060262d661b80751551d19e6717e15a166 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 18 Mar 2019 04:41:21 +0100
Subject: [PATCH] patches/Restricted: allow random.SystemRandom

---
 product/ERP5Type/patches/Restricted.py                 | 3 +++
 product/ERP5Type/tests/testRestrictedPythonSecurity.py | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/product/ERP5Type/patches/Restricted.py b/product/ERP5Type/patches/Restricted.py
index 2350f61a84..e73046385e 100644
--- a/product/ERP5Type/patches/Restricted.py
+++ b/product/ERP5Type/patches/Restricted.py
@@ -344,3 +344,6 @@ for member_id in dir(decimal):
   if isinstance(member, type) and issubclass(member, decimal.DecimalException):
     ContainerAssertions[member] = 1
 del member_id, member
+
+from random import SystemRandom
+allow_type(SystemRandom)
diff --git a/product/ERP5Type/tests/testRestrictedPythonSecurity.py b/product/ERP5Type/tests/testRestrictedPythonSecurity.py
index ff29c15958..80170c5049 100644
--- a/product/ERP5Type/tests/testRestrictedPythonSecurity.py
+++ b/product/ERP5Type/tests/testRestrictedPythonSecurity.py
@@ -25,8 +25,6 @@
 #
 ##############################################################################
 
-import unittest
-
 from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
 from Products.ERP5Type.tests.utils import createZODBPythonScript
 from Products.ERP5Type.tests.utils import removeZODBPythonScript
@@ -123,3 +121,7 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase):
         'return urlparse.parse_qsl("q=s")',
         expected=[('q', 's')]
     )
+
+  def testSystemRandom(self):
+    self.createAndRunScript('import random',
+                            'return random.SystemRandom().getrandbits(10)')
-- 
2.30.9