コード例 #1
0
class BasePasswordHasherTests(SimpleTestCase):
    not_implemented_msg = "subclasses of BasePasswordHasher must provide %s() method"

    def setUp(self):
        self.hasher = BasePasswordHasher()

    def test_load_library_no_algorithm(self):
        msg = "Hasher 'BasePasswordHasher' doesn't specify a library attribute"
        with self.assertRaisesMessage(ValueError, msg):
            self.hasher._load_library()

    def test_load_library_importerror(self):
        PlainHasher = type(
            "PlainHasher",
            (BasePasswordHasher, ),
            {
                "algorithm": "plain",
                "library": "plain"
            },
        )
        msg = "Couldn't load 'PlainHasher' algorithm library: No module named 'plain'"
        with self.assertRaisesMessage(ValueError, msg):
            PlainHasher()._load_library()

    def test_attributes(self):
        self.assertIsNone(self.hasher.algorithm)
        self.assertIsNone(self.hasher.library)

    def test_encode(self):
        msg = self.not_implemented_msg % "an encode"
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.encode("password", "salt")

    def test_decode(self):
        msg = self.not_implemented_msg % "a decode"
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.decode("encoded")

    def test_harden_runtime(self):
        msg = (
            "subclasses of BasePasswordHasher should provide a harden_runtime() method"
        )
        with self.assertWarnsMessage(Warning, msg):
            self.hasher.harden_runtime("password", "encoded")

    def test_must_update(self):
        self.assertIs(self.hasher.must_update("encoded"), False)

    def test_safe_summary(self):
        msg = self.not_implemented_msg % "a safe_summary"
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.safe_summary("encoded")

    def test_verify(self):
        msg = self.not_implemented_msg % "a verify"
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.verify("password", "encoded")
コード例 #2
0
ファイル: test_hashers.py プロジェクト: z24225021/django
class BasePasswordHasherTests(SimpleTestCase):
    not_implemented_msg = 'subclasses of BasePasswordHasher must provide %s() method'

    def setUp(self):
        self.hasher = BasePasswordHasher()

    def test_load_library_no_algorithm(self):
        msg = "Hasher 'BasePasswordHasher' doesn't specify a library attribute"
        with self.assertRaisesMessage(ValueError, msg):
            self.hasher._load_library()

    def test_load_library_importerror(self):
        PlainHasher = type('PlainHasher', (BasePasswordHasher, ), {
            'algorithm': 'plain',
            'library': 'plain'
        })
        msg = "Couldn't load 'PlainHasher' algorithm library: No module named 'plain'"
        with self.assertRaisesMessage(ValueError, msg):
            PlainHasher()._load_library()

    def test_attributes(self):
        self.assertIsNone(self.hasher.algorithm)
        self.assertIsNone(self.hasher.library)

    def test_encode(self):
        msg = self.not_implemented_msg % 'an encode'
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.encode('password', 'salt')

    def test_decode(self):
        msg = self.not_implemented_msg % 'a decode'
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.decode('encoded')

    def test_harden_runtime(self):
        msg = 'subclasses of BasePasswordHasher should provide a harden_runtime() method'
        with self.assertWarnsMessage(Warning, msg):
            self.hasher.harden_runtime('password', 'encoded')

    def test_must_update(self):
        self.assertIs(self.hasher.must_update('encoded'), False)

    def test_safe_summary(self):
        msg = self.not_implemented_msg % 'a safe_summary'
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.safe_summary('encoded')

    def test_verify(self):
        msg = self.not_implemented_msg % 'a verify'
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.verify('password', 'encoded')
コード例 #3
0
ファイル: test_hashers.py プロジェクト: CodeMonk/django
class BasePasswordHasherTests(SimpleTestCase):
    not_implemented_msg = 'subclasses of BasePasswordHasher must provide %s() method'

    def setUp(self):
        self.hasher = BasePasswordHasher()

    def test_load_library_no_algorithm(self):
        msg = "Hasher 'BasePasswordHasher' doesn't specify a library attribute"
        with self.assertRaisesMessage(ValueError, msg):
            self.hasher._load_library()

    def test_load_library_importerror(self):
        PlainHasher = type('PlainHasher', (BasePasswordHasher,), {'algorithm': 'plain', 'library': 'plain'})
        msg = "Couldn't load 'PlainHasher' algorithm library: No module named 'plain'"
        with self.assertRaisesMessage(ValueError, msg):
            PlainHasher()._load_library()

    def test_attributes(self):
        self.assertIsNone(self.hasher.algorithm)
        self.assertIsNone(self.hasher.library)

    def test_encode(self):
        msg = self.not_implemented_msg % 'an encode'
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.encode('password', 'salt')

    def test_harden_runtime(self):
        msg = 'subclasses of BasePasswordHasher should provide a harden_runtime() method'
        with self.assertWarns(Warning, msg=msg):
            self.hasher.harden_runtime('password', 'encoded')

    def test_must_update(self):
        self.assertIs(self.hasher.must_update('encoded'), False)

    def test_safe_summary(self):
        msg = self.not_implemented_msg % 'a safe_summary'
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.safe_summary('encoded')

    def test_verify(self):
        msg = self.not_implemented_msg % 'a verify'
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.hasher.verify('password', 'encoded')