From 13b807d647c791a9ebc74e2c9b5d321693f28bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksi=20H=C3=A4kli?= Date: Sun, 24 Feb 2019 22:35:15 +0200 Subject: [PATCH] Add dummy handler implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- axes/handlers/dummy.py | 12 ++++++++++++ axes/tests/test_handlers.py | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 axes/handlers/dummy.py diff --git a/axes/handlers/dummy.py b/axes/handlers/dummy.py new file mode 100644 index 0000000..6e7c1fb --- /dev/null +++ b/axes/handlers/dummy.py @@ -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 diff --git a/axes/tests/test_handlers.py b/axes/tests/test_handlers.py index 3e93981..2ac109c 100644 --- a/axes/tests/test_handlers.py +++ b/axes/tests/test_handlers.py @@ -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()