Пример #1
0
    def test_equal_on_equal_and_empty(self):
        """
        Test that the equality operator returns True when comparing two Digest
        objects with no internal data.
        """
        a = Digest()
        b = Digest()

        self.assertTrue(a == b)
        self.assertTrue(b == a)
Пример #2
0
    def test_not_equal_on_equal_and_empty(self):
        """
        Test that the inequality operator returns False when comparing two
        Digest objects with no internal data.
        """
        a = Digest()
        b = Digest()

        self.assertFalse(a != b)
        self.assertFalse(b != a)
Пример #3
0
    def test_equal_on_not_equal(self):
        """
        Test that the equality operator returns False when comparing two
        Digest objects with different sets of internal data.
        """
        a = Digest(hashing_algorithm=self.hashing_algorithm_b,
                   digest_value=self.digest_value_b,
                   key_format_type=self.key_format_type_b)
        b = Digest()

        self.assertFalse(a == b)
        self.assertFalse(b == a)
Пример #4
0
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing two
        Digest objects with the same internal data.
        """
        a = Digest(hashing_algorithm=self.hashing_algorithm_b,
                   digest_value=self.digest_value_b,
                   key_format_type=self.key_format_type_b)
        b = Digest(hashing_algorithm=self.hashing_algorithm_b,
                   digest_value=self.digest_value_b,
                   key_format_type=self.key_format_type_b)

        self.assertFalse(a != b)
        self.assertFalse(b != a)
Пример #5
0
 def test_init_with_args(self):
     """
     Test that a Digest object can be constructed with valid values.
     """
     Digest(hashing_algorithm=HashingAlgorithm(),
            digest_value=DigestValue(),
            key_format_type=KeyFormatType())
Пример #6
0
    def _test_str(self, value, expected):
        digest = Digest(digest_value=value)

        observed = str(digest)

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)
Пример #7
0
    def test_not_equal_on_not_equal(self):
        """
        Test that the inequality operator returns True when comparing two
        Digest objects with the different sets of internal data.
        """
        a = Digest(hashing_algorithm=self.hashing_algorithm_b,
                   digest_value=self.digest_value_b,
                   key_format_type=self.key_format_type_b)
        b = Digest()
        c = Digest(hashing_algorithm=self.hashing_algorithm_d,
                   digest_value=self.digest_value_b,
                   key_format_type=self.key_format_type_c)
        d = Digest(key_format_type=self.key_format_type_c)

        self.assertTrue(a != b)
        self.assertTrue(b != a)
        self.assertTrue(b != c)
        self.assertTrue(b != d)
Пример #8
0
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the inequality operator returns True when comparing an
        Digest object with a non-ExtensionInformation object.
        """
        a = Digest(hashing_algorithm=self.hashing_algorithm_b,
                   digest_value=self.digest_value_b,
                   key_format_type=self.key_format_type_b)
        b = "invalid"

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Пример #9
0
    def test_equal_on_type_mismatch(self):
        """
        Test that the equality operator returns False when comparing a Digest
        object with a non-Digest object.
        """
        a = Digest(hashing_algorithm=self.hashing_algorithm_b,
                   digest_value=self.digest_value_b,
                   key_format_type=self.key_format_type_b)
        b = "invalid"

        self.assertFalse(a == b)
        self.assertFalse(b == a)
Пример #10
0
    def _test_read(self, stream, hashing_algorithm, digest_value,
                   key_format_type):
        digest = Digest()
        digest.read(stream)

        msg = "hashing algorithm encoding mismatch"
        msg += "; expected {0}, observed {1}".format(hashing_algorithm,
                                                     digest.hashing_algorithm)
        self.assertEqual(hashing_algorithm, digest.hashing_algorithm, msg)

        msg = "digest value encoding mismatch"
        msg += "; expected {0}, observed {1}".format(digest_value,
                                                     digest.digest_value)
        self.assertEqual(digest_value, digest.digest_value, msg)

        msg = "key format type encoding mismatch"
        msg += "; expected {0}, observed {1}".format(key_format_type,
                                                     digest.key_format_type)
        self.assertEqual(key_format_type, digest.key_format_type, msg)
Пример #11
0
    def _test_write(self, stream_expected, hashing_algorithm, digest_value,
                    key_format_type):
        stream_observed = BytearrayStream()
        digest = Digest(hashing_algorithm=hashing_algorithm,
                        digest_value=digest_value,
                        key_format_type=key_format_type)
        digest.write(stream_observed)

        length_expected = len(stream_expected)
        length_observed = len(stream_observed)

        msg = "encoding lengths not equal"
        msg += "; expected {0}, observed {1}".format(length_expected,
                                                     length_observed)
        self.assertEqual(length_expected, length_observed, msg)

        msg = "encoding mismatch"
        msg += ";\nexpected:\n{0}\nobserved:\n{1}".format(
            stream_expected, stream_observed)
        self.assertEqual(stream_expected, stream_observed, msg)
Пример #12
0
    def test_repr(self):
        """
        Test that the representation of a Digest object with data is formatted
        properly.
        """
        hashing_algorithm = HashingAlgorithm(HashingAlgorithmEnum.MD5)
        digest_value = DigestValue(b'\x00\x01\x02\x03')
        key_format_type = KeyFormatType(KeyFormatTypeEnum.RAW)
        digest = Digest(hashing_algorithm=hashing_algorithm,
                        digest_value=digest_value,
                        key_format_type=key_format_type)

        hashing_algorithm = "hashing_algorithm={0}".format(
            repr(hashing_algorithm))
        digest_value = "digest_value={0}".format(repr(digest_value))
        key_format_type = "key_format_type={0}".format(repr(key_format_type))

        expected = "Digest({0}, {1}, {2})".format(hashing_algorithm,
                                                  digest_value,
                                                  key_format_type)
        observed = repr(digest)

        msg = "expected:\n{0},\nobserved:\n{1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)
Пример #13
0
 def test_init_with_none(self):
     """
     Test that a Digest object can be constructed with no specified values.
     """
     Digest()