Пример #1
0
    def test_all_supported(self):
        for algo_name, (enabled, (fun_name, fun_args,
                                  fun_kwargs)) in hashes._HASH_ALGO_MAPPING:
            if not enabled:
                self.assertFalse(hashes.is_algo_supported(algo_name))
            else:
                with unittest.mock.patch("hashlib.{}".format(fun_name),
                                         create=True) as hash_impl:
                    self.assertTrue(hashes.is_algo_supported(algo_name))

                hash_impl.assert_not_called()
Пример #2
0
    def test_return_false_if_function_not_implemented(self):
        try:
            _sha3_256 = hashlib.sha3_256
        except AttributeError:
            self.assertFalse(hashes.is_algo_supported("sha3-256"))
            return

        self.assertTrue(hashes.is_algo_supported("sha3-256"))
        del hashlib.sha3_256

        try:
            self.assertFalse(hashes.is_algo_supported("sha3-256"))
        finally:
            hashlib.sha3_256 = _sha3_256
Пример #3
0
    def test_return_false_if_function_not_implemented(self):
        try:
            _sha3_256 = hashlib.sha3_256
        except AttributeError:
            self.assertFalse(hashes.is_algo_supported("sha3-256"))
            return

        self.assertTrue(hashes.is_algo_supported("sha3-256"))
        del hashlib.sha3_256

        try:
            self.assertFalse(hashes.is_algo_supported("sha3-256"))
        finally:
            hashlib.sha3_256 = _sha3_256
Пример #4
0
    def test_all_supported(self):
        for algo_name, (enabled,
                        (fun_name,
                         fun_args,
                         fun_kwargs)) in hashes._HASH_ALGO_MAPPING:
            if not enabled:
                self.assertFalse(
                    hashes.is_algo_supported(algo_name)
                )
            else:
                with unittest.mock.patch(
                        "hashlib.{}".format(fun_name),
                        create=True) as hash_impl:
                    self.assertTrue(hashes.is_algo_supported(algo_name))

                hash_impl.assert_not_called()
Пример #5
0
 def test_return_false_if_function_not_defined(self):
     self.assertFalse(hashes.is_algo_supported("foobar"))
Пример #6
0
 def test_return_false_for_MUST_NOT_hashes(self):
     self.assertFalse(hashes.is_algo_supported("md2"))
     self.assertFalse(hashes.is_algo_supported("md4"))
     self.assertFalse(hashes.is_algo_supported("md5"))
Пример #7
0
 def test_return_false_if_function_not_defined(self):
     self.assertFalse(hashes.is_algo_supported("foobar"))
Пример #8
0
 def test_return_false_for_MUST_NOT_hashes(self):
     self.assertFalse(hashes.is_algo_supported("md2"))
     self.assertFalse(hashes.is_algo_supported("md4"))
     self.assertFalse(hashes.is_algo_supported("md5"))