Skip to content

Commit b28000d

Browse files
committed
[GR-74734] Expand subprocess entropy tests
1 parent 8197665 commit b28000d

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

graalpython/com.oracle.graal.python.test/src/tests/test_entropy_subprocess.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,35 @@ def test_multiprocessing_process_import_does_not_use_initrandom(self):
140140
self.assert_subprocess_ok(result)
141141
self.assertEqual("ok", result.stdout.strip())
142142

143+
def test_tempfile_candidate_names_use_initrandom(self):
144+
result = self._run_with_init_device(
145+
b"\x00" * self.HASH_AND_RANDOM_IMPORT_BYTES,
146+
"import tempfile; next(tempfile._get_candidate_names()); print('ok')",
147+
)
148+
self.assert_initrandom_exhausted(result)
149+
150+
def test_tempfile_does_not_mutate_random_state(self):
151+
result = self._run_with_init_source(
152+
"fixed:0x1234ABCD",
153+
"import random; before = random.getstate(); "
154+
"import tempfile; next(tempfile._get_candidate_names()); "
155+
"after = random.getstate(); "
156+
"print(before == after)",
157+
)
158+
self.assert_subprocess_ok(result)
159+
self.assertEqual("True", result.stdout.strip())
160+
161+
def test_email_generator_boundary_mutates_random_state(self):
162+
result = self._run_with_init_source(
163+
"fixed:0x1234ABCD",
164+
"import random; before = random.getstate(); "
165+
"from email.generator import Generator; Generator._make_boundary(); "
166+
"after = random.getstate(); "
167+
"print(before == after)",
168+
)
169+
self.assert_subprocess_ok(result)
170+
self.assertEqual("False", result.stdout.strip())
171+
143172
def test_pyexpat_import_does_not_use_additional_initrandom(self):
144173
result = self._run_with_init_device(
145174
b"\x00" * self.HASH_SECRET_BYTES,
@@ -156,6 +185,17 @@ def test_sqlite3_import_does_not_use_additional_initrandom(self):
156185
self.assert_subprocess_ok(result)
157186
self.assertEqual("_sqlite3", result.stdout.strip())
158187

188+
def test_uuid1_mutates_random_state(self):
189+
result = self._run_with_init_source(
190+
"fixed:0x1234ABCD",
191+
"import random; before = random.getstate(); "
192+
"import uuid; uuid.uuid1(node=1); "
193+
"after = random.getstate(); "
194+
"print(before == after)",
195+
)
196+
self.assert_subprocess_ok(result)
197+
self.assertEqual("False", result.stdout.strip())
198+
159199
def test_uuid4_does_not_use_initrandom(self):
160200
result = self._run_with_init_device(
161201
b"\x00" * self.HASH_SECRET_BYTES,

0 commit comments

Comments
 (0)