示例#1
0
    def test_uses_and_hash_from_algo(self):
        with contextlib.ExitStack() as stack:
            hash_from_algo = stack.enter_context(
                unittest.mock.patch("aioxmpp.hashes.hash_from_algo")
            )

            _get_hash_input = stack.enter_context(
                unittest.mock.patch(
                    "aioxmpp.entitycaps.caps390._get_hash_input"
                )
            )

            result = caps390._calculate_hash(
                unittest.mock.sentinel.algo,
                unittest.mock.sentinel.hash_input,
            )

        hash_from_algo.assert_called_once_with(unittest.mock.sentinel.algo)
        _get_hash_input.assert_not_called()

        hash_from_algo().update.assert_called_once_with(
            unittest.mock.sentinel.hash_input
        )
        hash_from_algo().digest.assert_called_once_with()

        self.assertEqual(
            result,
            hash_from_algo().digest(),
        )
示例#2
0
    def test_uses_and_hash_from_algo(self):
        with contextlib.ExitStack() as stack:
            hash_from_algo = stack.enter_context(
                unittest.mock.patch("aioxmpp.hashes.hash_from_algo"))

            _get_hash_input = stack.enter_context(
                unittest.mock.patch(
                    "aioxmpp.entitycaps.caps390._get_hash_input"))

            result = caps390._calculate_hash(
                unittest.mock.sentinel.algo,
                unittest.mock.sentinel.hash_input,
            )

        hash_from_algo.assert_called_once_with(unittest.mock.sentinel.algo)
        _get_hash_input.assert_not_called()

        hash_from_algo().update.assert_called_once_with(
            unittest.mock.sentinel.hash_input)
        hash_from_algo().digest.assert_called_once_with()

        self.assertEqual(
            result,
            hash_from_algo().digest(),
        )
示例#3
0
    def test_verify_large_input(self):
        k = caps390.Key(
            "sha-256",
            caps390._calculate_hash(
                "sha-256",
                caps390._get_hash_input(TEST_LARGE),
            ),
        )

        self.assertTrue(k.verify(TEST_LARGE))

        self.assertFalse(k.verify(TEST_SMALL))
示例#4
0
    def test_verify_large_input_precalculated(self):
        hash_input_small = caps390._get_hash_input(TEST_SMALL)
        hash_input_large = caps390._get_hash_input(TEST_LARGE)

        k = caps390.Key(
            "sha-256",
            caps390._calculate_hash(
                "sha-256",
                hash_input_large,
            ),
        )

        self.assertTrue(k.verify(hash_input_large))

        self.assertFalse(k.verify(hash_input_small))
示例#5
0
    def test_verify_large_input(self):
        k = caps390.Key(
            "sha-256",
            caps390._calculate_hash(
                "sha-256",
                caps390._get_hash_input(TEST_LARGE),
            ),
        )

        self.assertTrue(
            k.verify(TEST_LARGE)
        )

        self.assertFalse(
            k.verify(TEST_SMALL)
        )
示例#6
0
    def test_verify_large_input_precalculated(self):
        hash_input_small = caps390._get_hash_input(TEST_SMALL)
        hash_input_large = caps390._get_hash_input(TEST_LARGE)

        k = caps390.Key(
            "sha-256",
            caps390._calculate_hash(
                "sha-256",
                hash_input_large,
            ),
        )

        self.assertTrue(
            k.verify(hash_input_large)
        )

        self.assertFalse(
            k.verify(hash_input_small)
        )