Fix an issue detected by tests: clear redis cache upon block reset

This commit is contained in:
Yurii Parfinenko 2026-01-27 13:43:12 -05:00
parent 394f89b4e0
commit 9bcd62aa2c
No known key found for this signature in database
GPG key ID: DC2DA451C163B361

View file

@ -12,7 +12,11 @@ from django.utils.module_loading import import_string
from .connection import get_redis_connection
from . import config
from .data import get_approx_account_lockouts_from_login_attempts, store_login_attempt
from .data import (
get_approx_account_lockouts_from_login_attempts,
get_approx_lockouts_cache_key,
store_login_attempt,
)
from .signals import (
send_username_block_signal,
send_ip_block_signal,
@ -331,6 +335,12 @@ def unblock_ip(ip_address, pipe=None):
pipe.execute()
send_ip_unblock_signal(ip_address)
redis_cache_key = get_approx_lockouts_cache_key(ip_address, None)
if redis_cache_key is not None:
redis_client = get_redis_connection()
redis_client.delete(redis_cache_key)
def unblock_username(username, pipe=None):
""" unblock the given Username """
@ -345,6 +355,12 @@ def unblock_username(username, pipe=None):
pipe.execute()
send_username_unblock_signal(username)
redis_cache_key = get_approx_lockouts_cache_key(None, username)
if redis_cache_key is not None:
redis_client = get_redis_connection()
redis_client.delete(redis_cache_key)
def reset_failed_attempts(ip_address=None, username=None):
""" reset the failed attempts for these ip's and usernames
@ -357,6 +373,12 @@ def reset_failed_attempts(ip_address=None, username=None):
unblock_ip(ip_address, pipe=pipe)
unblock_username(username, pipe=pipe)
redis_cache_key = get_approx_lockouts_cache_key(ip_address, username)
if redis_cache_key is not None:
redis_client = get_redis_connection()
redis_client.delete(redis_cache_key)
pipe.execute()