From cdb294f8f548e41f43adb7f1546545cc8c3eb07a Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Sat, 16 Mar 2013 11:52:28 -0500 Subject: [PATCH 1/7] Updated version number --- axes/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axes/__init__.py b/axes/__init__.py index 5702867..6c8196e 100644 --- a/axes/__init__.py +++ b/axes/__init__.py @@ -1,7 +1,7 @@ import logging import os -VERSION = (1, 2, 9) +VERSION = (1, 3, 0) def get_version(): From 58c3a828813566ffa6fcfb04038001fb85c25f2f Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Sat, 16 Mar 2013 16:09:55 -0500 Subject: [PATCH 2/7] Added better testing schema --- axes/test_settings.py | 52 +++++++++++++++++++++++++++++++++++ axes/test_urls.py | 6 +++++ axes/tests.py | 63 +++++++++++++++++++++---------------------- 3 files changed, 89 insertions(+), 32 deletions(-) create mode 100644 axes/test_settings.py create mode 100644 axes/test_urls.py diff --git a/axes/test_settings.py b/axes/test_settings.py new file mode 100644 index 0000000..5a56375 --- /dev/null +++ b/axes/test_settings.py @@ -0,0 +1,52 @@ +import os +import django + +if django.VERSION[:2] >= (1, 3): + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + } + } +else: + DATABASE_ENGINE = 'sqlite3' + +SITE_ID = 1 + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'axes.middleware.FailedLoginMiddleware' +) + +ROOT_URLCONF = 'axes.test_urls' + +INSTALLED_APPS = [ + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.messages', + 'django.contrib.admin', + + 'axes', +] + +SECRET_KEY = 'too-secret-for-test' + +LOGGING = { + 'version': 1, + 'root': { + 'level': 'DEBUG', + 'handlers': ['console'], + }, + 'handlers': { + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + }, + } + } + +# AXES_LOGIN_FAILURE_LIMIT = 1 diff --git a/axes/test_urls.py b/axes/test_urls.py new file mode 100644 index 0000000..0d120ce --- /dev/null +++ b/axes/test_urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import patterns, include +from django.contrib import admin + +urlpatterns = patterns('', + (r'^admin/', include(admin.site.urls)), +) \ No newline at end of file diff --git a/axes/tests.py b/axes/tests.py index d5a8ae2..9391cb2 100644 --- a/axes/tests.py +++ b/axes/tests.py @@ -10,32 +10,19 @@ from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.test.utils import override_settings - -FAILURE_LIMIT = 3 +from axes.decorators import FAILURE_LIMIT +from axes.decorators import LOGIN_FORM_KEY -@override_settings( - AXES_LOGIN_FAILURE_LIMIT=FAILURE_LIMIT, - AXES_LOCKOUT_URL=None, - AXES_USE_USER_AGENT=False, - AXES_COOLOFF_TIME=None, - AXES_LOCKOUT_TEMPLATE=None, -) class AccessAttemptTest(TestCase): - """Test case using custom settings for testing""" - - def setUp(self): - for i in range(0, random.randrange(10, 50)): - username = "person%s" % i - email = "%s@example.org" % username - u = User.objects.create_user(email=email, username=username, password=username) - u.is_staff = True - u.save() + """Test case using custom settings for testing + """ + LOCKED_MESSAGE = 'Account locked: too many login attempts.' def _generate_random_string(self): """Generates a random string""" - return ''.join(random.choice(string.ascii_uppercase + string.digits) - for x in range(20)) + chars = string.ascii_uppercase + string.digits + return ''.join(random.choice(chars) for x in range(20)) def _random_username(self, existing_username=False): """Returns a username, existing or not depending on params""" @@ -44,40 +31,52 @@ class AccessAttemptTest(TestCase): return self._generate_random_string() - def _attempt_login(self, existing_username=False): + def _login(self, existing_username=False): response = self.client.post(reverse('admin:index'), { 'username': self._random_username(existing_username), - 'password': self._generate_random_string() + 'password': self._generate_random_string(), }) return response + def setUp(self): + for i in range(0, random.randrange(10, 50)): + username = "person%s" % i + email = "%s@example.org" % username + u = User.objects.create_user( + username=username, + password=username, + email=email, + ) + u.is_staff = True + u.save() + def test_login_max(self, existing_username=False): for i in range(0, FAILURE_LIMIT - 1): - response = self._attempt_login(existing_username=existing_username) + response = self._login(existing_username=existing_username) # Check if we are in the same login page - self.assertIn('this_is_the_login_form', response.content) + self.assertContains(response, LOGIN_FORM_KEY) # So, we shouldn't have gotten a lock-out yet. # But we should get one now - response = self._attempt_login() - self.assertContains(response, 'Account locked') + response = self._login() + self.assertContains(response, self.LOCKED_MESSAGE) def test_with_real_username_max(self): self.test_login_max(existing_username=True) def test_login_max_with_more_attempts(self, existing_username=False): - for i in range(0, FAILURE_LIMIT - 1): - response = self._attempt_login(existing_username=existing_username) + for i in range(0, FAILURE_LIMIT - 2): + response = self._login(existing_username=existing_username) # Check if we are in the same login page - self.assertIn('this_is_the_login_form', response.content) + self.assertContains(response, LOGIN_FORM_KEY) # So, we shouldn't have gotten a lock-out yet. # But we should get one now for i in range(0, random.randrange(1, 100)): # try to log in a bunch of times - response = self._attempt_login() - self.assertContains(response, 'Account locked') + response = self._login() + self.assertContains(response, self.LOCKED_MESSAGE) def test_with_real_username_max_with_more(self): self.test_login_max_with_more_attempts(existing_username=True) @@ -88,4 +87,4 @@ class AccessAttemptTest(TestCase): 'username': valid_username, 'password': valid_username }) - self.assertNotIn('authentication_form', response.context) + self.assertNotIn(LOGIN_FORM_KEY, response.context) From f6914c3c086c82ab15577e5990d161813a378564 Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Sat, 16 Mar 2013 16:15:54 -0500 Subject: [PATCH 3/7] Added travis support for testing --- axes/.travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 axes/.travis.yml diff --git a/axes/.travis.yml b/axes/.travis.yml new file mode 100644 index 0000000..42a505d --- /dev/null +++ b/axes/.travis.yml @@ -0,0 +1,10 @@ +language: python +python: + - "2.7" +env: + - DJANGO_VERSION=1.4.5 + - DJANGO_VERSION=1.5 +install: + - pip install --use-mirrors Django==$DJANGO_VERSION +script: + - django-admin.py test axes --settings=axes.test_settings From 86bb31e1956890aedff96e9e14cf628561fb903f Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Sat, 16 Mar 2013 16:18:07 -0500 Subject: [PATCH 4/7] Move travis.yml to root folder --- axes/.travis.yml => .travis.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename axes/.travis.yml => .travis.yml (100%) diff --git a/axes/.travis.yml b/.travis.yml similarity index 100% rename from axes/.travis.yml rename to .travis.yml From 01c539d90b4fa72e44fa97c50defddb285d3b004 Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Sat, 16 Mar 2013 16:34:18 -0500 Subject: [PATCH 5/7] Added missing python path --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 42a505d..ee363ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ python: env: - DJANGO_VERSION=1.4.5 - DJANGO_VERSION=1.5 + - PYTHONPATH=$PYTHONPATH:$PWD install: - pip install --use-mirrors Django==$DJANGO_VERSION script: From ea170a2a2a731aeea3a2146ebead81ef60874695 Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Sat, 16 Mar 2013 16:39:17 -0500 Subject: [PATCH 6/7] Fixed setting env variable --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ee363ff..eee3f05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,8 @@ language: python python: - "2.7" env: - - DJANGO_VERSION=1.4.5 - - DJANGO_VERSION=1.5 - - PYTHONPATH=$PYTHONPATH:$PWD + - PYTHONPATH=$PYTHONPATH:$PWD DJANGO_VERSION=1.4.5 + - PYTHONPATH=$PYTHONPATH:$PWD DJANGO_VERSION=1.5 install: - pip install --use-mirrors Django==$DJANGO_VERSION script: From 3f860e936870ada51cba4ddf58dd1bbe12cb559e Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Sat, 16 Mar 2013 17:03:11 -0500 Subject: [PATCH 7/7] Improved documentation adding testing --- README.rst | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/README.rst b/README.rst index a2cdfe3..bfda0cc 100644 --- a/README.rst +++ b/README.rst @@ -15,33 +15,29 @@ Requirements work around the Django admin and the regular ``django.contrib.auth`` login-powered pages. + Installation ============ -Download ``django-axes`` using **one** of the following methods: +Download and install ``django-axes`` using **one** of the following methods: -easy_install ------------- +PIP +--- -You can download the package from the `CheeseShop `_ or use:: +You can install the latest stable package running this command:: - easy_install django-axes + $ pip install django-axes -to download and install ``django-axes``. +Also you can install the development version running this command:: -Package Download ----------------- + $ pip install -e git+http://github.com/codekoala/django-axes.git#egg=django_axes-dev -Download the latest ``.tar.gz`` file from the downloads section and extract it -somewhere you'll remember. Use ``python setup.py install`` to install it. +Setuptools +---------- -Checkout from GitHub --------------------- +You can install the latest stable package running:: -Execute the following command, and make sure you're checking ``django-axes`` -out somewhere on the ``PYTHONPATH``:: - - git clone git://github.com/codekoala/django-axes.git + $ easy_install django-axes Verifying Installation ---------------------- @@ -55,6 +51,20 @@ If that command completes with some sort of version number, you're probably good to go. If you see error output, you need to check your installation (I'd start with your ``PYTHONPATH``). + +Development +=========== + +You can contribute to this project forking it from github and sending pull requests. + +Running tests +------------- + +Tests can be run, after you clone the repository and having django installed, like:: + + $ PYTHONPATH=$PYTHONPATH:$PWD django-admin.py test axes --settings=axes.test_settings + + Configuration =============