diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-12-14 23:51:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-14 23:51:22 (GMT) |
commit | 358e5e17a51ba00742bfaee4557a94c3c4179c22 (patch) | |
tree | 0918046bb6a75f31957b4d0aa24ca73df93d5bbf /Lib/test/test_cmd_line.py | |
parent | 96a5e50a5de3683b2afd6d680c7ecc4b525986f6 (diff) | |
download | cpython-358e5e17a51ba00742bfaee4557a94c3c4179c22.zip cpython-358e5e17a51ba00742bfaee4557a94c3c4179c22.tar.gz cpython-358e5e17a51ba00742bfaee4557a94c3c4179c22.tar.bz2 |
bpo-32329: Fix -R option for hash randomization (#4873)
bpo-32329, bpo-32030:
* The -R option now turns on hash randomization when the
PYTHONHASHSEED environment variable is set to 0 Previously, the
option was ignored.
* sys.flags.hash_randomization is now properly set to 0 when hash
randomization is turned off by PYTHONHASHSEED=0.
* _PyCoreConfig_ReadEnv() now reads the PYTHONHASHSEED environment
variable. _Py_HashRandomization_Init() now only apply the
configuration, it doesn't read PYTHONHASHSEED anymore.
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r-- | Lib/test/test_cmd_line.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 2aff51b..2b14c30 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -432,8 +432,16 @@ class CmdLineTest(unittest.TestCase): # Verify that sys.flags contains hash_randomization code = 'import sys; print("random is", sys.flags.hash_randomization)' - rc, out, err = assert_python_ok('-c', code) - self.assertEqual(rc, 0) + rc, out, err = assert_python_ok('-c', code, PYTHONHASHSEED='') + self.assertIn(b'random is 1', out) + + rc, out, err = assert_python_ok('-c', code, PYTHONHASHSEED='random') + self.assertIn(b'random is 1', out) + + rc, out, err = assert_python_ok('-c', code, PYTHONHASHSEED='0') + self.assertIn(b'random is 0', out) + + rc, out, err = assert_python_ok('-R', '-c', code, PYTHONHASHSEED='0') self.assertIn(b'random is 1', out) def test_del___main__(self): |