[6.15.z] Replace hardcoded temp file path with tempfile in tests/test_config.py #1319
+2
−1
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.
Cherrypick of PR: #1316
This PR addresses a security best practice issue by replacing the hardcoded temporary file path
/tmp/bogus.json
with Python's standardtempfile
module.Changes
import tempfile
to the importsFILE_PATH = '/tmp/bogus.json' # noqa: S108
withFILE_PATH = tempfile.NamedTemporaryFile(suffix='.json', delete=False).name
# noqa: S108
comment since the hardcoded temp file issue is now resolvedWhy this change?
The original code used a hardcoded path
/tmp/bogus.json
which violates security best practices (ruff rule S108 - hardcoded-temp-file). While the tests use mocked file operations and don't actually access the filesystem, using proper temporary file generation is the recommended approach.Testing
# noqa: S108
suppressionThe change is minimal and safe since all file operations in the tests are mocked with
mock_open
, so the actual file path value doesn't affect test behavior.Fixes #982.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.