You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Django Defender to protect API login from brute forceDEFENDER_LOGIN_FAILURE_LIMIT=3DEFENDER_COOLOFF_TIME=300DEFENDER_BEHIND_REVERSE_PROXY=FalseDEFENDER_LOCK_OUT_BY_IP_AND_USERNAME=FalseDEFENDER_ACCESS_ATTEMPT_EXPIRATION=24DEFENDER_REDIS_URL="redis://redis:6379/0"DEFENDER_USE_CELERY=True
and here is my test:
importpytestfromdjango.urlsimportreversefromdefender.modelsimportAccessAttemptpytestmark=pytest.mark.django_db@pytest.mark.django_dbdeftest_brute_force_login(settings, client):
# settings.DEFENDER_LOGIN_FAILURE_LIMIT = 3# settings.DEFENDER_ACCESS_ATTEMPT_EXPIRATION = 5# settings.STORE_ACCESS_ATTEMPTS = True# settings.USE_CELERY = False# to clean up the database before testAccessAttempt.objects.all().delete()
login_url=reverse("api:auth_login")
response1=client.post(login_url, {
"username": "[email protected]",
"password": "wrong_pass1"
})
print("response1:", response1.data)
response2=client.post(login_url, {
"username": "[email protected]",
"password": "wrong_pass2"
})
print("response2:", response2.data)
response3=client.post(login_url, {
"username": "[email protected]",
"password": "wrong_pass3"
})
print("response3:", response3.data)
response4=client.post(login_url, {
"username": "[email protected]",
"password": "wrong_pass4"
})
print("response4:", response4.data)
# to clean up the database after testAccessAttempt.objects.all().delete()
assertFalse# just for raising the traceback to get the above prints
And the results of my test is:
First run
response1: {'result': {}, 'message': 'Unable to log in with provided credentials.', 'status': 400, 'success': False}
response2: {'result': {}, 'message': 'Unable to log in with provided credentials.', 'status': 400, 'success': False}
response3: {'result': {}, 'message': 'Unable to log in with provided credentials.', 'status': 400, 'success': False}
response4: {'result': {}, 'message': 'Unable to log in with provided credentials.', 'status': 400, 'success': False}
Second run
response1: {'result': {}, 'message': 'You have attempted to login 3 times, with no success. Your account is locked for 300 seconds.', 'status': 400, 'success': False}
response2: {'result': {}, 'message': 'You have attempted to login 3 times, with no success. Your account is locked for 300 seconds.', 'status': 400, 'success': False}
response3: {'result': {}, 'message': 'You have attempted to login 3 times, with no success. Your account is locked for 300 seconds.', 'status': 400, 'success': False}
response4: {'result': {}, 'message': 'You have attempted to login 3 times, with no success. Your account is locked for 300 seconds.', 'status': 400, 'success': False}
The text was updated successfully, but these errors were encountered:
Here is my
settings.py
:and here is my test:
And the results of my test is:
First run
Second run
The text was updated successfully, but these errors were encountered: