Skip to content
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

Unit tests leak temporary file "tmp1.json" #1617

Open
rdegraaf opened this issue Mar 5, 2024 · 0 comments
Open

Unit tests leak temporary file "tmp1.json" #1617

rdegraaf opened this issue Mar 5, 2024 · 0 comments
Labels
bug Something isn't working potential Unconfirmed issue

Comments

@rdegraaf
Copy link

rdegraaf commented Mar 5, 2024

Running unit tests creates an empty file named "tmp1.json" in the root of the project. This appears to come from TestOpinelFsClass.test_save_blob_as_json() in test_utils_fs.py. I'm not sure what that function is supposed to accomplish since it doesn't appear to examine the files that it creates and the third line should always fail (unless run as root).

Recommendation

  1. The test script should clean up any temporary files that it creates. Ideally, use context managers so that they are always deleted regardless of how the scope exits (normally, exception, etc.)
  2. Use a proper temporary-file creation API to create a temporary file that is guaranteed to not collide with anything else, rather than just hoping that nothing else uses the name "tmp1.json". See https://docs.python.org/3/library/tempfile.html for some options.
  3. Document the test function and ensure that it works.

To Reproduce

git clone https://github.com/nccgroup/ScoutSuite.git
cd ScoutSuite
python3 -m venv test-venv
source test-venv/bin/activate
pip install --upgrade pip wheel
pip install .
pip install pytest
pytest tests/test_utils_fs.py
ls tmp1.json
@rdegraaf rdegraaf added bug Something isn't working potential Unconfirmed issue labels Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working potential Unconfirmed issue
Projects
None yet
Development

No branches or pull requests

1 participant