Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

[FIX] Use cross-platform os.urandom in test key generation - #1265

Open
rushil23shah-hue wants to merge 1 commit into
CCExtractor:masterfrom
rushil23shah-hue:fix/cross-platform-test-keys
Open

rushil23shah-hue wants to merge 1 commit into
CCExtractor:masterfrom
rushil23shah-hue:fix/cross-platform-test-keys

Conversation

@rushil23shah-hue

Copy link
Copy Markdown

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

My familiarity with the project is as follows (check one):

  • I have never used the project.
  • I have used the project briefly.
  • I have used the project extensively, but have not contributed previously.
  • I am an active contributor to the project.

Summary

generate_keys() in tests/base.py used os.system("head -c 24 /dev/urandom > ...") to create secret_csrf and secret_key files.

On Windows development environments (and any environment lacking /dev/urandom or head), this shell command fails silently, causing test initialization to raise:

FileNotFoundError: [Errno 2] No such file or directory: '.../secret_key'

Changes

  1. tests/base.py (generate_keys): Replaced the shell-based head -c 24 /dev/urandom calls with Python's standard os.urandom(24), making test key generation cross-platform across Windows, Linux, and macOS without spawning shell subprocesses.
  2. tests/base.py (generate_keys): Ensured parse.py creation uses an explicit context manager rather than leaving an open file descriptor.

Testing & Verification

  • Deleted secret_key, secret_csrf, and parse.py and ran tests from a clean state. Verified that all three files are generated automatically.
  • Ran test suites with nose2 (tests.test_config_parser, tests.test_utility, tests.test_log_configuration); all 12 tests passed cleanly.
  • Code quality checks passed with zero errors:
    • pycodestyle tests/base.py --config=./.pycodestylerc
    • pydocstyle tests/base.py --config=./.pydocstylerc
    • isort tests/base.py --check-only

@sonarqubecloud

sonarqubecloud Bot commented Nov 8, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant