Commits

Nuno Maltez committed 04b2dbf

Fixes unit tests to work in Django 1.4 - the default password encription
algorithm changed

Comments (0)

Files changed (4)

 
 In the urls configuration set the two-step login views 
 
-    url(r'^accounts/login/$', 
-        'twostepauth.views.login_step_one', 
+    url(r'^accounts/login/$',
+        'twostepauth.views.login_step_one',
         name='auth_login'),
-    url(r'^accounts/login/step_two$', 
-        'twostepauth.views.login_step_two', 
+    url(r'^accounts/login/step_two$',
+        'twostepauth.views.login_step_two',
         name='login_step_two')
 
 The ``twostepauth`` also includes a view for the user profile management of
 the two-step authentication. Example setup for this view:
 
-    url(r'^profiles/twostepauth/$', 
-        'twostepauth.views.twostepauth_profile', 
+    url(r'^profiles/twostepauth/$',
+        'twostepauth.views.twostepauth_profile',
         name='twostepauth_profile'),
 
 You will need to create a template named ``twostepauth/profile.html``. You can

twostepauth/tests/__init__.py

         self.profile = self.user_otp.get_profile()
         self.original_reuse_setting = ts_settings.TWOSTEPAUTH_DISALLOW_REUSE
         ts_settings.TWOSTEPAUTH_DISALLOW_REUSE = True
+        if hasattr(settings, 'PASSWORD_HASHERS'):
+            self.original_password_hashers_setting = settings.PASSWORD_HASHERS
+            settings.PASSWORD_HASHERS = (
+                    'django.contrib.auth.hashers.SHA1PasswordHasher',
+                )
 
     def tearDown(self):
         super(TwoStepAuthProfileTestCase, self).tearDown()
         ts_settings.TWOSTEPAUTH_DISALLOW_REUSE = self.original_reuse_setting
+        if hasattr(self, 'original_password_hashers_setting'):
+            settings.PASSWORD_HASHERS = self.original_password_hashers_setting
         models.now = self.old_now
 
     def test_validate_totp(self):
         self.user_otp = User.objects.get(username='test_otp')
         self.original_reuse_setting = ts_settings.TWOSTEPAUTH_DISALLOW_REUSE
         ts_settings.TWOSTEPAUTH_DISALLOW_REUSE = False
+        if hasattr(settings, 'PASSWORD_HASHERS'):
+            self.original_password_hashers_setting = settings.PASSWORD_HASHERS
+            settings.PASSWORD_HASHERS = (
+                    'django.contrib.auth.hashers.SHA1PasswordHasher',
+                )
 
     def tearDown(self):
         super(TwoStepAuthProfileAllowReuseTestCase, self).tearDown()
         ts_settings.TWOSTEPAUTH_DISALLOW_REUSE = self.original_reuse_setting
+        if hasattr(self, 'original_password_hashers_setting'):
+            settings.PASSWORD_HASHERS = self.original_password_hashers_setting
 
     def test_invalidate_totp_code(self):
         """ test that if DISALLOW_REUSE is disabled, a code in the blocked list is accepted """
         ts_settings.TWOSTEPAUTH_DISALLOW_REUSE = True
         self.original_totp_setting = ts_settings.TWOSTEPAUTH_TOTP
         ts_settings.TWOSTEPAUTH_TOTP = False
+        if hasattr(settings, 'PASSWORD_HASHERS'):
+            self.original_password_hashers_setting = settings.PASSWORD_HASHERS
+            settings.PASSWORD_HASHERS = (
+                    'django.contrib.auth.hashers.SHA1PasswordHasher',
+                )
 
     def tearDown(self):
         super(TwoStepAuthProfileHotpTestCase, self).tearDown()
         ts_settings.TWOSTEPAUTH_DISALLOW_REUSE = self.original_reuse_setting
         ts_settings.TWOSTEPAUTH_TOTP = self.original_totp_setting
+        if hasattr(self, 'original_password_hashers_setting'):
+            settings.PASSWORD_HASHERS = self.original_password_hashers_setting
 
     def test_validate_hotp(self):
         """ Profile : Validate HOTP """

twostepauth/tests/auth_backend.py

 #coding: utf-8
+from django.conf import settings
 from django.contrib.auth.models import User
 from django.contrib.auth.tokens import default_token_generator
 from .. import models
 
     def setUp(self):
         super(TwoStepAuthBackendTestCase, self).setUp()
+        if hasattr(settings, 'PASSWORD_HASHERS'):
+            self.original_password_hashers_setting = settings.PASSWORD_HASHERS
+            settings.PASSWORD_HASHERS = (
+                    'django.contrib.auth.hashers.SHA1PasswordHasher',
+                )
         self.old_now = models.now
         models.now = get_fake_time_fn()
         self.backend = TwoStepAuthBackend()
 
     def tearDown(self):
         models.now = self.old_now
+        if hasattr(self, 'original_password_hashers_setting'):
+            settings.PASSWORD_HASHERS = self.original_password_hashers_setting
         super(TwoStepAuthBackendTestCase, self).tearDown()
 
     def test_user_no_profile(self):

twostepauth/tests/views.py

         )
         self.old_TEMPLATE_LOADERS = settings.TEMPLATE_LOADERS
         settings.TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader',)
- 
+        if hasattr(settings, 'PASSWORD_HASHERS'):
+            self.original_password_hashers_setting = settings.PASSWORD_HASHERS
+            settings.PASSWORD_HASHERS = (
+                    'django.contrib.auth.hashers.SHA1PasswordHasher',
+                )
 
     def tearDown(self):
         settings.TEMPLATE_LOADERS = self.old_TEMPLATE_LOADERS
         settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
+        if hasattr(self, 'original_password_hashers_setting'):
+            settings.PASSWORD_HASHERS = self.original_password_hashers_setting
         models.now = self.old_now
         super(TwoStepAuthenticationViewsTestCase, self).tearDown()
 
         self.login('test_no_otp', 'test_no_otp')
 
     def test_two_step_on(self):
-        """ Test that a user wit tsa active is show the token form. """
+        """ Test that a user with tsa active is shown the token form. """
         response = self.client.post(reverse('auth_login'), {
             'username': 'test_otp',
             'password': 'test_otp'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.