diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2019-11-19 14:41:30 -0500 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2019-11-19 14:41:30 -0500 |
commit | fb5484ca8006a722c21a9bb51e89b21ff8553266 (patch) | |
tree | 2d36ee69f88c67d3e41e4bf3ad6b3a3574db626f | |
parent | 5a1a6a1ba7c637462c25d307c5ef7a7777f51d57 (diff) | |
download | passlib-fb5484ca8006a722c21a9bb51e89b21ff8553266.tar.gz |
tests: django compat fixes
* test_ext_django: account for django 1.11 pbkdf2 defaults
* test_handlers_django: looks like django 2 and forward don't expect w
passwords-as-bytes at all, so test suites's "bytes -> str" special case
is now the default / only policy.
* test_handlers_django: django_bcrypt no longer enabled by default as of django 2.2
-rw-r--r-- | passlib/tests/test_ext_django.py | 5 | ||||
-rw-r--r-- | passlib/tests/test_handlers_django.py | 21 |
2 files changed, 12 insertions, 14 deletions
diff --git a/passlib/tests/test_ext_django.py b/passlib/tests/test_ext_django.py index 25513fc..f6ef4f1 100644 --- a/passlib/tests/test_ext_django.py +++ b/passlib/tests/test_ext_django.py @@ -118,7 +118,10 @@ def create_mock_setter(): # build config dict that matches stock django # XXX: move these to passlib.apps? -if DJANGO_VERSION >= (1, 10): +if DJANGO_VERSION >= (1, 11): + stock_config = _apps.django110_context.to_dict() + stock_rounds = 36000 +elif DJANGO_VERSION >= (1, 10): stock_config = _apps.django110_context.to_dict() stock_rounds = 30000 elif DJANGO_VERSION >= (1, 9): diff --git a/passlib/tests/test_handlers_django.py b/passlib/tests/test_handlers_django.py index fcab5b9..50d2b33 100644 --- a/passlib/tests/test_handlers_django.py +++ b/passlib/tests/test_handlers_django.py @@ -33,6 +33,10 @@ class _DjangoHelper(TestCase): min_django_version = MIN_DJANGO_VERSION #: max django version where hash alg is present + #: TODO: for a bunch of the tests below, this is just max version where + #: settings.PASSWORD_HASHERS includes it by default -- could add helper to patch + #: desired django hasher back in for duration of test. + #: XXX: change this to "disabled_in_django_version" instead? max_django_version = None def _require_django_support(self): @@ -57,10 +61,7 @@ class _DjangoHelper(TestCase): """django/check_password""" if self.handler.name == "django_bcrypt" and hash.startswith("bcrypt$$2y$"): hash = hash.replace("$$2y$", "$$2a$") - if self.django_has_encoding_glitch and isinstance(secret, bytes): - # e.g. unsalted_md5 on 1.5 and higher try to combine - # salt + password before encoding to bytes, leading to ascii error. - # this works around that issue. + if isinstance(secret, bytes): secret = secret.decode("utf-8") return check_password(secret, hash) return verify_django @@ -80,8 +81,6 @@ class _DjangoHelper(TestCase): "mangled secret=%r hash=%r incorrect verified" % (secret, hash)) - django_has_encoding_glitch = False - def test_91_django_generation(self): """test against output of Django's make_password()""" self._require_django_support() @@ -96,9 +95,7 @@ class _DjangoHelper(TestCase): secret, other = generator.random_password_pair() if not secret: # django rejects empty passwords. continue - if self.django_has_encoding_glitch and isinstance(secret, bytes): - # e.g. unsalted_md5 tried to combine salt + password before encoding to bytes, - # leading to ascii error. this works around that issue. + if isinstance(secret, bytes): secret = secret.decode("utf-8") hash = make_password(secret, hasher=name) self.assertTrue(self.do_identify(hash)) @@ -168,8 +165,6 @@ class django_salted_md5_test(HandlerCase, _DjangoHelper): handler = hash.django_salted_md5 max_django_version = (1,9) - django_has_encoding_glitch = True - known_correct_hashes = [ # test extra large salt ("password", 'md5$123abcdef$c8272612932975ee80e8a35995708e80'), @@ -210,8 +205,6 @@ class django_salted_sha1_test(HandlerCase, _DjangoHelper): handler = hash.django_salted_sha1 max_django_version = (1,9) - django_has_encoding_glitch = True - known_correct_hashes = [ # test extra large salt ("password",'sha1$123abcdef$e4a1877b0e35c47329e7ed7e58014276168a37ba'), @@ -271,6 +264,8 @@ class django_pbkdf2_sha1_test(HandlerCase, _DjangoHelper): class django_bcrypt_test(HandlerCase, _DjangoHelper): """test django_bcrypt""" handler = hash.django_bcrypt + # XXX: not sure when this wasn't in default list anymore. somewhere in [2.0 - 2.2] + max_django_version = (2, 0) fuzz_salts_need_bcrypt_repair = True known_correct_hashes = [ |