mirror of
https://github.com/jazzband/django-axes.git
synced 2026-03-16 22:30:23 +00:00
Add dummy handler implementation
A handler is always loaded if Axes is active, and the dummy handler is intended for use when the user wishes to use either the middleware or authentication backends but does not want Axes to handle or emit signals from authentication events. Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
This commit is contained in:
parent
7564603d9b
commit
13b807d647
2 changed files with 24 additions and 1 deletions
12
axes/handlers/dummy.py
Normal file
12
axes/handlers/dummy.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from django.http import HttpRequest
|
||||
|
||||
from axes.handlers.base import AxesBaseHandler
|
||||
|
||||
|
||||
class AxesDummyHandler(AxesBaseHandler): # pylint: disable=unused-argument
|
||||
"""
|
||||
Signal handler implementation that does nothing and can be used to disable signal processing.
|
||||
"""
|
||||
|
||||
def is_allowed(self, request: HttpRequest, credentials: dict = None) -> bool:
|
||||
return True
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from django.http import HttpRequest
|
||||
from django.test import override_settings
|
||||
from django.utils.timezone import timedelta
|
||||
|
||||
from axes.conf import settings
|
||||
from axes.handlers.proxy import AxesProxyHandler
|
||||
from axes.tests.base import AxesTestCase
|
||||
from axes.utils import get_client_str
|
||||
|
|
@ -147,3 +147,14 @@ class AxesCacheHandlerTestCase(AxesHandlerTestCase):
|
|||
@patch('axes.handlers.cache.log')
|
||||
def test_whitelist(self, log):
|
||||
self.check_whitelist(log)
|
||||
|
||||
|
||||
@override_settings(
|
||||
AXES_HANDLER='axes.handlers.dummy.AxesDummyHandler',
|
||||
)
|
||||
class AxesDummyHandlerTestCase(AxesHandlerTestCase):
|
||||
def test_handler(self):
|
||||
for _ in range(settings.AXES_FAILURE_LIMIT):
|
||||
self.login()
|
||||
|
||||
self.check_login()
|
||||
|
|
|
|||
Loading…
Reference in a new issue