Repository navigation
Ensure uploaded validator files are always deleted - #228
Merged
Merged
Conversation
Uploaded XML/ZIP files were written to a NamedTemporaryFile(delete=False) and only unlinked on the single-XML success path. The API ZIP path never removed the upload, and exceptions in any path skipped cleanup, leaving files in /tmp. - Add a saved_upload context manager that always deletes the temp file - Use it in the API (XML and ZIP) and the web validator form - Extract API ZIP contents in a TemporaryDirectory context manager - Add a privacy notice to the validator page - Add tests asserting no files remain after XML, ZIP, and error cases Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Coverage Report for CI Build 37963916403Coverage increased (+0.4%) to 83.107%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Uploaded files for the validator are never stored in the database or on a persistent volume, but the temporary copies were not reliably deleted:
This PR adds a
saved_uploadcontext manager that always removes the temp file, uses it in the API and web form, extracts ZIPs in aTemporaryDirectorycontext manager, and splits the API handler into_validate_zip/_validate_xmlhelpers. It also adds a notice on the validator page that the site is managed by NLR and files are not retained.Testing
Ran against a temporary local Postgres with
DJANGO_SETTINGS_MODULE=bsyncviewer.settings.gh_actions python manage.py test bsyncviewer.tests.test_api bsyncviewer.tests.test_views: 10 tests, OK.New tests point
tempfile.tempdirat a private directory and assert it is empty after an XML upload, a ZIP upload, and a validation error. On the oldviews.pythe ZIP and error tests fail (leftover temp file), confirming the leak.Notes
testsuite.validate_sch) works in memory here sinceresult_pathis not passed, so it writes no files.