nccgroup / ScoutSuite

Multi-Cloud Security Auditing Tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unit tests leak temporary file "tmp1.json"

rdegraaf opened this issue · comments

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