mirror of
https://github.com/jazzband/django-defender.git
synced 2026-03-16 22:10:32 +00:00
added more unit tests
This commit is contained in:
parent
e0393bb2eb
commit
6f0f5c26f2
2 changed files with 38 additions and 2 deletions
|
|
@ -31,8 +31,11 @@ CACHE_PREFIX = get_setting('DEFENDER_CACHE_PREFIX', 'defender')
|
|||
REVERSE_PROXY_HEADER = get_setting('DEFENDER_REVERSE_PROXY_HEADER',
|
||||
'HTTP_X_FORWARDED_FOR')
|
||||
|
||||
# how long to wait before the bad login attempt gets forgotten. in seconds.
|
||||
COOLOFF_TIME = get_setting('DEFENDER_COOLOFF_TIME', 300) # seconds
|
||||
try:
|
||||
# how long to wait before the bad login attempt gets forgotten. in seconds.
|
||||
COOLOFF_TIME = int(get_setting('DEFENDER_COOLOFF_TIME', 300)) # seconds
|
||||
except ValueError:
|
||||
raise Exception('COOLOFF_TIME needs to be an integer') # pragma: no cover
|
||||
|
||||
LOCKOUT_TEMPLATE = get_setting('DEFENDER_LOCKOUT_TEMPLATE')
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ from mock import patch
|
|||
import mockredis
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.contrib.sessions.backends.db import SessionStore
|
||||
from django.core.urlresolvers import NoReverseMatch
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
|
@ -148,6 +151,36 @@ class AccessAttemptTest(TestCase):
|
|||
response = self._login(is_valid=True, user_agent=long_user_agent)
|
||||
self.assertNotContains(response, LOGIN_FORM_KEY, status_code=302)
|
||||
|
||||
@patch('defender.config.BEHIND_REVERSE_PROXY', True)
|
||||
def test_get_ip_reverse_proxy(self):
|
||||
""" Tests if can handle a long user agent
|
||||
"""
|
||||
request_factory = RequestFactory()
|
||||
request = request_factory.get(ADMIN_LOGIN_URL)
|
||||
request.user = AnonymousUser()
|
||||
request.session = SessionStore()
|
||||
|
||||
request.META['HTTP_X_FORWARDED_FOR'] = '192.168.24.24'
|
||||
self.assertEquals(utils.get_ip(request), '192.168.24.24')
|
||||
|
||||
request_factory = RequestFactory()
|
||||
request = request_factory.get(ADMIN_LOGIN_URL)
|
||||
request.user = AnonymousUser()
|
||||
request.session = SessionStore()
|
||||
|
||||
request.META['REMOTE_ADDR'] = '24.24.24.24'
|
||||
self.assertEquals(utils.get_ip(request), '24.24.24.24')
|
||||
|
||||
def test_get_ip(self):
|
||||
""" Tests if can handle a long user agent
|
||||
"""
|
||||
request_factory = RequestFactory()
|
||||
request = request_factory.get(ADMIN_LOGIN_URL)
|
||||
request.user = AnonymousUser()
|
||||
request.session = SessionStore()
|
||||
|
||||
self.assertEquals(utils.get_ip(request), '127.0.0.1')
|
||||
|
||||
def test_long_user_agent_not_valid(self):
|
||||
""" Tests if can handle a long user agent with failure
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue