test_handlers_django.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:enkiWS 作者: juliettef 项目源码 文件源码
def test_91_django_generation(self):
        "test against output of Django's make_password()"
        from passlib.tests.test_ext_django import DJANGO_VERSION
        # make_password() not added until 1.4
        min_django_version = max(self.min_django_version, (1,4))
        if DJANGO_VERSION < min_django_version:
            raise self.skipTest("Django >= %s not installed" % vstr(min_django_version))
        from passlib.utils import tick
        from django.contrib.auth.hashers import make_password
        name = self.handler.django_name # set for all the django_* handlers
        end = tick() + self.max_fuzz_time/2
        while tick() < end:
            secret, other = self.get_fuzz_password_pair()
            if not secret: # django 1.4 rejects empty passwords.
                continue
            if DJANGO_VERSION >= (1,5) and 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.
                secret = secret.decode("utf-8")
            hash = make_password(secret, hasher=name)
            self.assertTrue(self.do_identify(hash))
            self.assertTrue(self.do_verify(secret, hash))
            self.assertFalse(self.do_verify(other, hash))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号