Repository navigation
test(django): exercise callback example with enforced CSRF middleware - #22
Open
Gwerdonatus wants to merge 1 commit into
Open
Gwerdonatus wants to merge 1 commit into
Gwerdonatus wants to merge 1 commit into
Conversation
This branch has not been deployed
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
The callback example is exempt from CSRF, but the existing adapter tests bypass middleware. Add integration tests that import and execute
examples/django/payments/views.pythroughClient(enforce_csrf_checks=True)andCsrfViewMiddleware, so removing the exemption cannot silently break server-to-server callbacks.Valid callbacks return 200 and look up the supplied payment ID through a mocked
TBCClient. Invalid JSON, a missing payment ID, and an array body return 400 without invoking the client. A separate unexempt endpoint returns 403, confirming middleware is active. No real credentials or network calls are used.Closes #13.
Validation
Python 3.12.14 / Django 5.2.17:
@csrf_exemptfrom the runnable example: four callback cases fail with 403; control still passes. Restored example: all five pass.ruff check .,ruff format --check ., andgit diff --checkpass.Checklist
pytest,ruff check ., andmypy(pytest/Ruff passed; mypy not run locally).CHANGELOG.mdwhen appropriate.AI assistance was used to prepare and verify this contribution.