mirror of
https://github.com/python/cpython.git
synced 2026-05-06 04:37:33 -04:00
gh-145417: Do not preserve SELinux context when copying venv scripts (#145454)
Co-authored-by: Miro Hrončok <miro@hroncok.cz> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
+11
-1
@@ -11,12 +11,12 @@ import os
|
||||
import os.path
|
||||
import pathlib
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import sysconfig
|
||||
import tempfile
|
||||
import shlex
|
||||
from test.support import (captured_stdout, captured_stderr,
|
||||
skip_if_broken_multiprocessing_synchronize, verbose,
|
||||
requires_subprocess, is_android, is_apple_mobile,
|
||||
@@ -373,6 +373,16 @@ class BasicTest(BaseTest):
|
||||
with open(fn, 'wb') as f:
|
||||
f.write(b'Still here?')
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'listxattr'), 'test requires os.listxattr')
|
||||
def test_install_scripts_selinux(self):
|
||||
"""
|
||||
gh-145417: Test that install_scripts does not copy SELinux context
|
||||
when copying scripts.
|
||||
"""
|
||||
with patch('os.listxattr') as listxattr_mock:
|
||||
venv.create(self.env_dir)
|
||||
listxattr_mock.assert_not_called()
|
||||
|
||||
def test_overwrite_existing(self):
|
||||
"""
|
||||
Test creating environment in an existing directory.
|
||||
|
||||
@@ -581,7 +581,7 @@ class EnvBuilder:
|
||||
'may be binary: %s', srcfile, e)
|
||||
continue
|
||||
if new_data == data:
|
||||
shutil.copy2(srcfile, dstfile)
|
||||
shutil.copy(srcfile, dstfile)
|
||||
else:
|
||||
with open(dstfile, 'wb') as f:
|
||||
f.write(new_data)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
:mod:`venv`: Prevent incorrect preservation of SELinux context
|
||||
when copying the ``Activate.ps1`` script. The script inherited
|
||||
the SELinux security context of the system template directory,
|
||||
rather than the destination project directory.
|
||||
Reference in New Issue
Block a user