-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
gh-145417: Do not preserve SELinux context when copying venv scripts #145454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+16
−2
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
de24338
Update __init__.py
Shrey-N ec2958b
Implement test for script installation mtime
Shrey-N 1428e75
Relint test_venv.py and fix trailing whitespace
Shrey-N 8778209
Refine venv test to use Activate.ps1 and check mode (gh-145417)
Shrey-N 52ee5ef
Add news entry
Shrey-N eec4e46
Rename News
Shrey-N c4d32d5
Delete Misc/NEWS.d/next/Library/gh-issue-145417.shrey.rst
Shrey-N 88fae45
Apply maintainer's suggestion for docstring clarity
Shrey-N 7dc69f0
Move template protection check before content assertion
Shrey-N 878d3b8
Merge branch 'python:main' into main
Shrey-N 75bd937
Clean up blank lines in test_venv.py
Shrey-N a76da3e
Enhance test for Activate.ps1 file integrity
Shrey-N 89c0c92
📜🤖 Added by blurb_it.
blurb-it[bot] 431c4ac
Applying maintainer's suggestion for news wording
Shrey-N 9bcf6db
Change Location of time module
Shrey-N ead93d7
Merge branch 'main' into main
Shrey-N 97652be
Reorder imports alphabetically
Shrey-N 4e127d8
Refactor test for SELinux acc to suggestion
Shrey-N 0e506f1
Fix SELinux context test and update patch usage
Shrey-N ace163b
Fix mock path for listxattr in SELinux test
Shrey-N d15ad82
Update test_venv.py
Shrey-N 7abaefc
Fix indentation for test_install_scripts_selinux
Shrey-N 2c23790
Update Misc/NEWS.d/next/Library/2026-03-03-11-49-44.gh-issue-145417.m…
Shrey-N File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Implement test for script installation mtime
Add a test to verify mtime behavior during script installation.
- Loading branch information
commit ec2958bcd328ca2f8393953c11991d4cd4bb9895
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -373,6 +373,38 @@ def create_contents(self, paths, filename): | |
| with open(fn, 'wb') as f: | ||
| f.write(b'Still here?') | ||
|
|
||
| def test_install_scripts_mtime(self): | ||
| """ | ||
| Test that install_scripts does not preserve mtime when copying scripts. | ||
| Using mtime serves as a proxy to verify that shutil.copy2 (and thus | ||
| SELinux bin_t contexts) is not being used during script installation. | ||
| """ | ||
| import time | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps move this to the toplevel imports. All the other unconditional imports are there, at the beginning of the file. |
||
| from unittest.mock import patch | ||
|
|
||
| builder = venv.EnvBuilder() | ||
| builder.create(self.env_dir) | ||
| context = builder.ensure_directories(self.env_dir) | ||
|
|
||
| with tempfile.TemporaryDirectory() as script_dir: | ||
| common_dir = os.path.join(script_dir, 'common') | ||
| os.mkdir(common_dir) | ||
| script_path = os.path.join(common_dir, 'test_script.sh') | ||
|
|
||
| with open(script_path, 'wb') as f: | ||
| f.write(b'echo Hello') | ||
|
|
||
| past_time = time.time() - 10_000_000 | ||
| os.utime(script_path, (past_time, past_time)) | ||
|
|
||
| builder.install_scripts(context, script_dir) | ||
|
|
||
| dst_path = os.path.join(context.bin_path, 'test_script.sh') | ||
| self.assertTrue(os.path.exists(dst_path)) | ||
|
|
||
| new_mtime = os.path.getmtime(dst_path) | ||
| self.assertGreater(new_mtime, past_time + 1000) | ||
|
|
||
| def test_overwrite_existing(self): | ||
| """ | ||
| Test creating environment in an existing directory. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's useful to link the issue here so people reading this know why it matters.