Try some new things

This commit is contained in:
djmore4 2022-10-11 17:11:22 -04:00 committed by Ken Cochrane
parent 5db32ed0be
commit 2d288b247a

View file

@ -286,7 +286,7 @@ class AccessAttemptTest(DefenderTestCase):
"""
self.test_failure_limit_by_ip_once()
# Wait for the cooling off period
time.sleep(config.ATTEMPT_COOLOFF_TIME)
time.sleep(config.LOCKOUT_COOLOFF_TIMES[0])
if config.MOCK_REDIS:
# mock redis require that we expire on our own
@ -427,6 +427,7 @@ class AccessAttemptTest(DefenderTestCase):
self.assertTemplateUsed(response, "defender/lockout.html")
@patch("defender.config.COOLOFF_TIME", 0)
@patch("defender.config.LOCKOUT_COOLOFF_TIMES", [0])
def test_failed_login_no_cooloff(self):
""" failed login no cooloff """
for i in range(0, config.FAILURE_LIMIT):
@ -950,39 +951,57 @@ class AccessAttemptTest(DefenderTestCase):
def test_lockout_cooloff_correctly_scales_with_ip_when_set(self):
self.test_failure_limit_by_ip_once()
time.sleep(config.LOCKOUT_COOLOFF_TIMES[0])
self.test_valid_login()
if config.MOCK_REDIS:
# mock redis require that we expire on our own
get_redis_connection().do_expire() # pragma: no cover
self.assertFalse(utils.is_source_ip_already_locked("127.0.0.1"))
self.test_failure_limit_by_ip_once()
time.sleep(config.LOCKOUT_COOLOFF_TIMES[0])
self.test_blocked_ip_cannot_login()
self.assertTrue(utils.is_source_ip_already_locked("127.0.0.1"))
utils.reset_failed_attempts(ip_address="127.0.0.1")
@patch("defender.config.LOCKOUT_COOLOFF_TIMES", [2, 4])
def test_lockout_cooloff_correctly_scales_with_username_when_set(self):
self.test_failure_limit_by_username_once()
time.sleep(config.LOCKOUT_COOLOFF_TIMES[0])
self.test_valid_login()
if config.MOCK_REDIS:
# mock redis require that we expire on our own
get_redis_connection().do_expire() # pragma: no cover
self.assertFalse(utils.is_user_already_locked(VALID_USERNAME))
self.test_failure_limit_by_username_once()
time.sleep(config.LOCKOUT_COOLOFF_TIMES[0])
self.test_blocked_username_cannot_login()
self.assertTrue(utils.is_user_already_locked(VALID_USERNAME))
utils.reset_failed_attempts(username=VALID_USERNAME)
@patch("defender.config.LOCKOUT_COOLOFF_TIMES", [2, 4])
def test_lockout_correctly_releases_after_scaling_with_ip(self):
self.test_failure_limit_by_ip_once()
time.sleep(config.LOCKOUT_COOLOFF_TIMES[0])
self.test_valid_login()
if config.MOCK_REDIS:
# mock redis require that we expire on our own
get_redis_connection().do_expire() # pragma: no cover
self.assertFalse(utils.is_source_ip_already_locked("127.0.0.1"))
self.test_failure_limit_by_ip_once()
time.sleep(config.LOCKOUT_COOLOFF_TIMES[1])
self.test_valid_login()
if config.MOCK_REDIS:
# mock redis require that we expire on our own
get_redis_connection().do_expire() # pragma: no cover
self.assertFalse(utils.is_source_ip_already_locked("127.0.0.1"))
@patch("defender.config.LOCKOUT_COOLOFF_TIMES", [2, 4])
def test_lockout_correctly_releases_after_scaling_with_username(self):
self.test_failure_limit_by_username_once()
time.sleep(config.LOCKOUT_COOLOFF_TIMES[0])
self.test_valid_login()
if config.MOCK_REDIS:
# mock redis require that we expire on our own
get_redis_connection().do_expire() # pragma: no cover
self.assertFalse(utils.is_user_already_locked(VALID_USERNAME))
self.test_failure_limit_by_username_once()
time.sleep(config.LOCKOUT_COOLOFF_TIMES[1])
self.test_valid_login()
if config.MOCK_REDIS:
# mock redis require that we expire on our own
get_redis_connection().do_expire() # pragma: no cover
self.assertFalse(utils.is_user_already_locked(VALID_USERNAME))
class SignalTest(DefenderTestCase):