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:
Aleksi Häkli 2019-02-24 22:35:15 +02:00
parent 7564603d9b
commit 13b807d647
No known key found for this signature in database
GPG key ID: 3E7146964D726BBE
2 changed files with 24 additions and 1 deletions

12
axes/handlers/dummy.py Normal file
View 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

View file

@ -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()