Skip to content

[6.16.z] Replace hardcoded temp file path with tempfile in tests/test_config.py - #1320

Merged
ogajduse merged 1 commit into
6.16.zfrom
cherry-pick-6.16.z-0e977584beb3625d9322e999354266ef2b59259b
Aug 11, 2025
Merged

[6.16.z] Replace hardcoded temp file path with tempfile in tests/test_config.py#1320
ogajduse merged 1 commit into
6.16.zfrom
cherry-pick-6.16.z-0e977584beb3625d9322e999354266ef2b59259b

Conversation

@Satellite-QE

Copy link
Copy Markdown
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 <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)
@Satellite-QE Satellite-QE added 6.16.z Auto_Cherry_Picked GHA has automatically cherrypicked this PR No-CherryPick PR doesnt need CherryPick to previous branches labels Jun 30, 2025
@ogajduse
ogajduse merged commit 90792ca into 6.16.z Aug 11, 2025
27 checks passed
@ogajduse
ogajduse deleted the cherry-pick-6.16.z-0e977584beb3625d9322e999354266ef2b59259b branch August 11, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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