Replace hardcoded temp file path with tempfile in tests/test_config.py - #1316
Merged
Conversation
Contributor
|
Can one of the admins verify this patch? |
Co-authored-by: JacobCallahan <6618303+JacobCallahan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Use tempfile instead of hard-coded bogus file in tests/test_config.py
Replace hardcoded temp file path with tempfile in tests/test_config.py
Jun 28, 2025
JacobCallahan
approved these changes
Jun 28, 2025
Member
ogajduse
approved these changes
Jun 30, 2025
ogajduse
left a comment
Member
There was a problem hiding this comment.
I have checked it against https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile. LGTM
ogajduse
marked this pull request as ready for review
June 30, 2025 15:39
Member
|
@JacobCallahan I'd say it still requires your re-review |
JacobCallahan
approved these changes
Jun 30, 2025
Member
|
@ogajduse looks like I can't review because it was initiated on my behalf; interesting to know. |
github-actions Bot
pushed a commit
that referenced
this pull request
Jun 30, 2025
#1316) * Initial plan * Replace hardcoded temp file with tempfile.NamedTemporaryFile Co-authored-by: JacobCallahan <6618303+JacobCallahan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JacobCallahan <6618303+JacobCallahan@users.noreply.github.com> (cherry picked from commit 0e97758)
github-actions Bot
pushed a commit
that referenced
this pull request
Jun 30, 2025
#1316) * Initial plan * Replace hardcoded temp file with tempfile.NamedTemporaryFile Co-authored-by: JacobCallahan <6618303+JacobCallahan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JacobCallahan <6618303+JacobCallahan@users.noreply.github.com> (cherry picked from commit 0e97758)
This was referenced Jun 30, 2025
github-actions Bot
pushed a commit
that referenced
this pull request
Jun 30, 2025
#1316) * Initial plan * Replace hardcoded temp file with tempfile.NamedTemporaryFile Co-authored-by: JacobCallahan <6618303+JacobCallahan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JacobCallahan <6618303+JacobCallahan@users.noreply.github.com> (cherry picked from commit 0e97758)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR addresses a security best practice issue by replacing the hardcoded temporary file path
/tmp/bogus.jsonwith Python's standardtempfilemodule.Changes
import tempfileto the importsFILE_PATH = '/tmp/bogus.json' # noqa: S108withFILE_PATH = tempfile.NamedTemporaryFile(suffix='.json', delete=False).name# noqa: S108comment since the hardcoded temp file issue is now resolvedWhy this change?
The original code used a hardcoded path
/tmp/bogus.jsonwhich 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: S108suppressionThe 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.