Refs #32061 -- Fixed test_crash_password_does_not_leak() crash on Windows.

When env is passed to subprocess.run() we should pass all existing
environment variables. This fixes crash on Windows:

Fatal Python error: failed to get random numbers to initialize Python

Fatal Python error: _Py_HashRandomization_Init: failed to get random
numbers to initialize Python
Python runtime state: preinitialized
This commit is contained in:
Mariusz Felisiak 2020-11-03 11:38:40 +01:00 committed by GitHub
parent 542b4b3ab4
commit 009fddc96b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import os
import subprocess import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
@ -190,6 +191,8 @@ class MySqlDbshellCommandTestCase(SimpleTestCase):
}, },
[], [],
) )
if env:
env = {**os.environ, **env}
fake_client = Path(__file__).with_name('fake_client.py') fake_client = Path(__file__).with_name('fake_client.py')
args[0:1] = [sys.executable, str(fake_client)] args[0:1] = [sys.executable, str(fake_client)]
with self.assertRaises(subprocess.CalledProcessError) as ctx: with self.assertRaises(subprocess.CalledProcessError) as ctx:

View File

@ -1,3 +1,4 @@
import os
import signal import signal
import subprocess import subprocess
import sys import sys
@ -121,6 +122,8 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
# The password doesn't leak in an exception that results from a client # The password doesn't leak in an exception that results from a client
# crash. # crash.
args, env = self.settings_to_cmd_args_env({'PASSWORD': 'somepassword'}, []) args, env = self.settings_to_cmd_args_env({'PASSWORD': 'somepassword'}, [])
if env:
env = {**os.environ, **env}
fake_client = Path(__file__).with_name('fake_client.py') fake_client = Path(__file__).with_name('fake_client.py')
args[0:1] = [sys.executable, str(fake_client)] args[0:1] = [sys.executable, str(fake_client)]
with self.assertRaises(subprocess.CalledProcessError) as ctx: with self.assertRaises(subprocess.CalledProcessError) as ctx: