fix(brute-force): record_failure/mark_success work with any StorageBackend - #13
Merged
Merged
Conversation
…geBackend record_failure/mark_success called backend.incr_sync/reset_sync, which _patch_backend() only ever monkey-patched onto MemoryBackend (its ops are plain dict access, so a sync shim was safe there). Any other StorageBackend Protocol implementer -- RedisBackend, or a user's own -- would AttributeError on the very first failed login attempt, since it never got the patch. Made record_failure/mark_success async and call the Protocol's real incr/reset directly, and deleted the sync-shim/_patch_backend machinery entirely -- it existed solely to work around not doing this. is_locked/ get_retry_after stay sync (they only ever touched the local _lockouts dict, never the backend). velocix's own handlers are async throughout, so this doesn't cost the "call it from a plain sync handler" use case the module docstring advertised -- there wasn't really a sync handler to call it from. Updated the two affected test files for the new async signatures, and added a regression test using a backend that only implements the async Protocol (no _sync methods) to prove the actual bug is fixed. Removed tests/test_security_base.py's incr_sync/get_sync/reset_sync tests since they tested the now-deleted patch directly -- the async incr/get/reset they exercised already have full separate coverage in that same file. Fixes #12.
magi8101
force-pushed
the
fix/brute-force-async-backend
branch
from
September 6, 2026 14:19
dd79f2e to
4bf4a4c
Compare
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.
Fixes #12. record_failure/mark_success called backend.incr_sync/reset_sync, which _patch_backend() only ever monkey-patched onto MemoryBackend — any other StorageBackend (RedisBackend, or a user's own) would AttributeError on the first failed login.
Made both methods async and call the Protocol's real incr/reset directly, deleted the sync-shim machinery entirely. is_locked/get_retry_after stay sync since they only touch the local _lockouts dict. Added a regression test using a backend with only the async Protocol methods (no _sync anything) to prove it. 249/249 tests green (250 before minus 4 now-pointless sync-shim tests, plus this PR's new one).
Note: this branches off main, not PR #11 — so its own CI run still shows the pre-#11 mypy count; unrelated to this PR's change.