Skip to content

[6.15.z] Replace hardcoded temp file path with tempfile in tests/test_config.py #1319

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

Open
wants to merge 1 commit into
base: 6.15.z
Choose a base branch
from

Conversation

Satellite-QE
Copy link
Contributor

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 standard tempfile module.

Changes

  • Added import tempfile to the imports
  • Replaced FILE_PATH = '/tmp/bogus.json' # noqa: S108 with FILE_PATH = tempfile.NamedTemporaryFile(suffix='.json', delete=False).name
  • Removed the # noqa: S108 comment since the hardcoded temp file issue is now resolved

Why 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

  • All existing tests continue to pass (272 tests)
  • The generated temporary file path maintains the same behavior for mocked operations
  • Ruff linting now passes without needing the # noqa: S108 suppression

The 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.

#1316)

* Initial plan

* Replace hardcoded temp file with tempfile.NamedTemporaryFile

Co-authored-by: JacobCallahan <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: JacobCallahan <[email protected]>
(cherry picked from commit 0e97758)
@Satellite-QE Satellite-QE added 6.15.z Auto_Cherry_Picked GHA has automatically cherrypicked this PR No-CherryPick PR doesnt need CherryPick to previous branches labels Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.15.z Auto_Cherry_Picked GHA has automatically cherrypicked this PR No-CherryPick PR doesnt need CherryPick to previous branches
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants