Skip to content

Commit

Permalink
Stop showing lockout message when lockout is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mogzol committed Jun 13, 2019
1 parent 0ba52cd commit 71708ef
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion axes/handlers/cache.py
Expand Up @@ -70,7 +70,7 @@ def user_login_failed(
cache_key = get_client_cache_key(request, credentials)
self.cache.set(cache_key, failures_since_start, self.cache_timeout)

if failures_since_start >= settings.AXES_FAILURE_LIMIT:
if settings.AXES_LOCK_OUT_AT_FAILURE and failures_since_start >= settings.AXES_FAILURE_LIMIT:
log.warning('AXES: Locking out %s after repeated login failures.', client_str)

request.axes_locked_out = True
Expand Down
2 changes: 1 addition & 1 deletion axes/handlers/database.py
Expand Up @@ -118,7 +118,7 @@ def user_login_failed(
attempt_time=request.axes_attempt_time,
)

if failures_since_start >= settings.AXES_FAILURE_LIMIT:
if settings.AXES_LOCK_OUT_AT_FAILURE and failures_since_start >= settings.AXES_FAILURE_LIMIT:
log.warning('AXES: Locking out %s after repeated login failures.', client_str)

request.axes_locked_out = True
Expand Down
5 changes: 4 additions & 1 deletion axes/tests/base.py
Expand Up @@ -154,7 +154,10 @@ def lockout(self):

def check_lockout(self):
response = self.lockout()
self.assertContains(response, self.LOCKED_MESSAGE, status_code=self.BLOCKED)
if settings.AXES_LOCK_OUT_AT_FAILURE == True:
self.assertContains(response, self.LOCKED_MESSAGE, status_code=self.BLOCKED)
else:
self.assertNotContains(response, self.LOCKED_MESSAGE, status_code=self.STATUS_SUCCESS)

def cool_off(self):
sleep(get_cool_off().total_seconds())
Expand Down
8 changes: 8 additions & 0 deletions axes/tests/test_handlers.py
Expand Up @@ -111,6 +111,10 @@ def test_handler(self):
def test_handler_without_reset(self):
self.check_handler()

@override_settings(AXES_LOCK_OUT_AT_FAILURE=False)
def test_handler_without_lockout(self):
self.check_handler()

@patch('axes.handlers.database.log')
def test_empty_request(self, log):
self.check_empty_request(log, 'AxesDatabaseHandler')
Expand Down Expand Up @@ -138,6 +142,10 @@ def test_handler(self):
def test_handler_without_reset(self):
self.check_handler()

@override_settings(AXES_LOCK_OUT_AT_FAILURE=False)
def test_handler_without_lockout(self):
self.check_handler()

@patch('axes.handlers.cache.log')
def test_empty_request(self, log):
self.check_empty_request(log, 'AxesCacheHandler')
Expand Down

0 comments on commit 71708ef

Please sign in to comment.