Skip to content

Replace hardcoded temp file path with tempfile in tests/test_config.py - #1316

Merged
JacobCallahan merged 2 commits into
masterfrom
copilot/fix-982
Jun 30, 2025
Merged

Replace hardcoded temp file path with tempfile in tests/test_config.py#1316
JacobCallahan merged 2 commits into
masterfrom
copilot/fix-982

Conversation

Copilot AI commented Jun 28, 2025

Copy link
Copy Markdown
Contributor

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.

@Satellite-QE

Copy link
Copy Markdown
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
Copilot AI requested a review from JacobCallahan June 28, 2025 03:07
@JacobCallahan JacobCallahan added CherryPick PR needs CherryPick to previous branches 6.15.z 6.16.z 6.17.z labels Jun 28, 2025
@JacobCallahan

Copy link
Copy Markdown
Member

@ogajduse 👀

@ogajduse ogajduse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ogajduse
ogajduse marked this pull request as ready for review June 30, 2025 15:39
@ogajduse

Copy link
Copy Markdown
Member

@JacobCallahan I'd say it still requires your re-review

@JacobCallahan

Copy link
Copy Markdown
Member

@ogajduse looks like I can't review because it was initiated on my behalf; interesting to know.

@JacobCallahan
JacobCallahan merged commit 0e97758 into master Jun 30, 2025
29 of 31 checks passed
@JacobCallahan
JacobCallahan deleted the copilot/fix-982 branch June 30, 2025 17:26
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)
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)
ogajduse pushed a commit that referenced this pull request Aug 11, 2025
#1316) (#1318)

* Initial plan

* Replace hardcoded temp file with tempfile.NamedTemporaryFile



---------



(cherry picked from commit 0e97758)

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JacobCallahan <6618303+JacobCallahan@users.noreply.github.com>
ogajduse pushed a commit that referenced this pull request Aug 11, 2025
#1316) (#1319)

* Initial plan

* Replace hardcoded temp file with tempfile.NamedTemporaryFile



---------



(cherry picked from commit 0e97758)

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JacobCallahan <6618303+JacobCallahan@users.noreply.github.com>
ogajduse pushed a commit that referenced this pull request Aug 11, 2025
#1316) (#1320)

* Initial plan

* Replace hardcoded temp file with tempfile.NamedTemporaryFile



---------



(cherry picked from commit 0e97758)

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JacobCallahan <6618303+JacobCallahan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.15.z 6.16.z 6.17.z CherryPick PR needs CherryPick to previous branches

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use tempfile instead of hard-coded bogus file in tests/test_config.py

4 participants