mirror of
https://github.com/jazzband/django-axes.git
synced 2026-05-05 06:04:47 +00:00
test: use AXES_LOCKOUT_PARAMETERS in handlers test
This commit is contained in:
parent
c3586ac3dc
commit
7cb0144770
1 changed files with 31 additions and 13 deletions
|
|
@ -261,7 +261,10 @@ class AxesDatabaseHandlerTestCase(AxesHandlerBaseTestCase):
|
|||
_more = 10
|
||||
for i in range(settings.AXES_ACCESS_FAILURE_LOG_PER_USER_LIMIT + _more):
|
||||
self.create_failure_log()
|
||||
self.assertEqual(_more, AxesProxyHandler.remove_out_of_limit_failure_logs(username=self.username))
|
||||
self.assertEqual(
|
||||
_more,
|
||||
AxesProxyHandler.remove_out_of_limit_failure_logs(username=self.username),
|
||||
)
|
||||
|
||||
@override_settings(AXES_RESET_ON_SUCCESS=True)
|
||||
def test_handler(self):
|
||||
|
|
@ -296,7 +299,7 @@ class AxesDatabaseHandlerTestCase(AxesHandlerBaseTestCase):
|
|||
def test_whitelist(self, log):
|
||||
self.check_whitelist(log)
|
||||
|
||||
@override_settings(AXES_ONLY_USER_FAILURES=True)
|
||||
@override_settings(AXES_LOCKOUT_PARAMETERS=["username"])
|
||||
@patch("axes.handlers.database.log")
|
||||
def test_user_login_failed_only_user_failures_with_none_username(self, log):
|
||||
credentials = {"username": None, "password": "test"}
|
||||
|
|
@ -305,7 +308,7 @@ class AxesDatabaseHandlerTestCase(AxesHandlerBaseTestCase):
|
|||
attempt = AccessAttempt.objects.all()
|
||||
self.assertEqual(0, AccessAttempt.objects.count())
|
||||
log.warning.assert_called_with(
|
||||
"AXES: Username is None and AXES_ONLY_USER_FAILURES is enabled, new record will NOT be created."
|
||||
"AXES: Username is None and username is the only one lockout parameter, new record will NOT be created."
|
||||
)
|
||||
|
||||
def test_user_login_failed_with_none_username(self):
|
||||
|
|
@ -318,22 +321,37 @@ class AxesDatabaseHandlerTestCase(AxesHandlerBaseTestCase):
|
|||
def test_user_login_failed_multiple_username(self):
|
||||
configurations = (
|
||||
(2, 1, {}, ["admin", "admin1"]),
|
||||
(2, 1, {"AXES_USE_USER_AGENT": True}, ["admin", "admin1"]),
|
||||
(2, 1, {"AXES_ONLY_USER_FAILURES": True}, ["admin", "admin1"]),
|
||||
(
|
||||
2,
|
||||
1,
|
||||
{"AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP": True},
|
||||
{"AXES_LOCKOUT_PARAMETERS": [("ip_address", "user_agent")]},
|
||||
["admin", "admin1"],
|
||||
),
|
||||
(2, 1, {"AXES_LOCKOUT_PARAMETERS": ["username"]}, ["admin", "admin1"]),
|
||||
(
|
||||
2,
|
||||
1,
|
||||
{"AXES_LOCKOUT_PARAMETERS": [("username", "ip_address")]},
|
||||
["admin", "admin1"],
|
||||
),
|
||||
(
|
||||
1,
|
||||
2,
|
||||
{"AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP": True},
|
||||
{"AXES_LOCKOUT_PARAMETERS": [("username", "ip_address")]},
|
||||
["admin", "admin"],
|
||||
),
|
||||
(1, 2, {"AXES_LOCK_OUT_BY_USER_OR_IP": True}, ["admin", "admin"]),
|
||||
(2, 1, {"AXES_LOCK_OUT_BY_USER_OR_IP": True}, ["admin", "admin1"]),
|
||||
(
|
||||
1,
|
||||
2,
|
||||
{"AXES_LOCKOUT_PARAMETERS": ["username", "ip_address"]},
|
||||
["admin", "admin"],
|
||||
),
|
||||
(
|
||||
2,
|
||||
1,
|
||||
{"AXES_LOCKOUT_PARAMETERS": ["username", "ip_address"]},
|
||||
["admin", "admin1"],
|
||||
),
|
||||
)
|
||||
|
||||
for (
|
||||
|
|
@ -400,7 +418,7 @@ class ResetAttemptsCacheHandlerTestCase(AxesHandlerBaseTestCase):
|
|||
with self.assertRaises(NotImplementedError):
|
||||
AxesProxyHandler.reset_attempts()
|
||||
|
||||
@override_settings(AXES_ONLY_USER_FAILURES=True)
|
||||
@override_settings(AXES_LOCKOUT_PARAMETERS=["username"])
|
||||
def test_handler_reset_attempts_username(self):
|
||||
self.set_up_login_attempts()
|
||||
self.assertEqual(
|
||||
|
|
@ -436,7 +454,7 @@ class ResetAttemptsCacheHandlerTestCase(AxesHandlerBaseTestCase):
|
|||
self.check_failures(0, ip_address=self.IP_1)
|
||||
self.check_failures(2, ip_address=self.IP_2)
|
||||
|
||||
@override_settings(AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP=True)
|
||||
@override_settings(AXES_LOCKOUT_PARAMETERS=[("username", "ip_address")])
|
||||
def test_handler_reset_attempts_ip_and_username(self):
|
||||
self.set_up_login_attempts()
|
||||
self.check_failures(1, username=self.USERNAME_1, ip_address=self.IP_1)
|
||||
|
|
@ -482,7 +500,7 @@ class AxesCacheHandlerTestCase(AxesHandlerBaseTestCase):
|
|||
def test_whitelist(self, log):
|
||||
self.check_whitelist(log)
|
||||
|
||||
@override_settings(AXES_ONLY_USER_FAILURES=True)
|
||||
@override_settings(AXES_LOCKOUT_PARAMETERS=["username"])
|
||||
@patch.object(cache, "set")
|
||||
@patch("axes.handlers.cache.log")
|
||||
def test_user_login_failed_only_user_failures_with_none_username(
|
||||
|
|
@ -493,7 +511,7 @@ class AxesCacheHandlerTestCase(AxesHandlerBaseTestCase):
|
|||
AxesProxyHandler.user_login_failed(sender, credentials, self.request)
|
||||
self.assertFalse(cache_set.called)
|
||||
log.warning.assert_called_with(
|
||||
"AXES: Username is None and AXES_ONLY_USER_FAILURES is enabled, new record will NOT be created."
|
||||
"AXES: Username is None and username is the only one lockout parameter, new record will NOT be created."
|
||||
)
|
||||
|
||||
@patch.object(cache, "add")
|
||||
|
|
|
|||
Loading…
Reference in a new issue