From 6efe11128a7622a4e4e586e37b96e8a1a4e6d2a8 Mon Sep 17 00:00:00 2001 From: djmore4 Date: Sat, 15 Oct 2022 14:57:05 -0400 Subject: [PATCH] Remove incorrect tests --- defender/data.py | 17 ++++++----------- defender/tests.py | 12 ------------ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/defender/data.py b/defender/data.py index e847bbf..2bdac46 100644 --- a/defender/data.py +++ b/defender/data.py @@ -45,17 +45,12 @@ def get_approx_account_lockouts_from_login_attempts(ip_address=None, username=No and not config.DISABLE_IP_LOCKOUT and not config.DISABLE_USERNAME_LOCKOUT ): q = q & Q(ip_address=ip_address) & Q(username=username) - elif not config.LOCKOUT_BY_IP_USERNAME: - if ip_address and not config.DISABLE_IP_LOCKOUT: - failure_limit = config.IP_FAILURE_LIMIT - q = q & Q(ip_address=ip_address) - elif username and not config.DISABLE_USERNAME_LOCKOUT: - failure_limit = config.USERNAME_FAILURE_LIMIT - q = q & Q(username=username) - else: - # If we've made it this far and didn't hit one of the other if or elif - # conditions, we're in an inappropriate context. - raise Exception("Invalid state requested") + elif ip_address and not config.DISABLE_IP_LOCKOUT: + failure_limit = config.IP_FAILURE_LIMIT + q = q & Q(ip_address=ip_address) + elif username and not config.DISABLE_USERNAME_LOCKOUT: + failure_limit = config.USERNAME_FAILURE_LIMIT + q = q & Q(username=username) else: # If we've made it this far and didn't hit one of the other if or elif # conditions, we're in an inappropriate context. diff --git a/defender/tests.py b/defender/tests.py index e35d95c..69d87fe 100644 --- a/defender/tests.py +++ b/defender/tests.py @@ -995,18 +995,6 @@ class AccessAttemptTest(DefenderTestCase): def test_approx_account_lockout_count_default_case_invalid_args_pt2(self): with self.assertRaises(Exception): get_approx_account_lockouts_from_login_attempts(username=VALID_USERNAME) - - @patch("defender.config.DISABLE_IP_LOCKOUT", True) - @patch("defender.config.LOCKOUT_BY_IP_USERNAME", True) - def test_approx_account_lockout_count_default_case_invalid_args_pt3(self): - with self.assertRaises(Exception): - get_approx_account_lockouts_from_login_attempts(ip_address="127.0.0.1", username=VALID_USERNAME) - - @patch("defender.config.DISABLE_USERNAME_LOCKOUT", True) - @patch("defender.config.LOCKOUT_BY_IP_USERNAME", True) - def test_approx_account_lockout_count_default_case_invalid_args_pt4(self): - with self.assertRaises(Exception): - get_approx_account_lockouts_from_login_attempts(ip_address="127.0.0.1", username=VALID_USERNAME) class SignalTest(DefenderTestCase):