fix: validate file contents - #3031
Draft
andrewleith wants to merge 3 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens document-upload validation in the notification API by making base64 decoding stricter and rejecting empty decoded files, with tests updated to reflect the new validation behavior.
Changes:
- Use
base64.b64decode(..., validate=True)indecode_personalisation_filesfor stricter base64 validation. - Add an explicit check to reject empty decoded files (
len(...) == 0) with a clear validation error. - Update v2 notification tests to cover additional invalid base64 cases and empty uploads.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/notifications/validators.py | Stricter base64 decoding and explicit empty-file rejection during personalisation file decoding. |
| tests/app/v2/notifications/test_post_notifications.py | Expanded/updated test cases and assertions to match the new validation messages and empty-file behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
1621
to
+1623
| assert response.status_code == 400 | ||
| resp_json = json.loads(response.get_data(as_text=True)) | ||
| assert f"{message} : Error decoding base64 field" in resp_json["errors"][0]["message"] | ||
| assert expected_message in resp_json["errors"][0]["message"] |
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 | Résumé
This pull request improves validation for document uploads by ensuring that empty files are not accepted and enhances error messages for invalid base64 data. The main changes include stricter base64 decoding, explicit empty file checks, and updated tests to reflect the new validation logic.
Validation improvements:
decode_personalisation_filesinvalidators.pyto usebase64.b64decodewithvalidate=Truefor stricter base64 validation.Test enhancements:
test_post_notification_with_document_upload_not_base64_fileto cover empty file uploads and provide more descriptive error messages.Related Issues | Cartes liées
Test instructions | Instructions pour tester la modification
TODO: Fill in test instructions for the reviewer.
Release Instructions | Instructions pour le déploiement
None.
Reviewer checklist | Liste de vérification du réviseur