Exemplo n.º 1
0
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing two
        Sign request payloads with the same data.
        """
        a = sign.SignRequestPayload()
        b = sign.SignRequestPayload()

        self.assertFalse(a != b)
        self.assertFalse(b != a)

        a = sign.SignRequestPayload(
            unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959',
            cryptographic_parameters=attributes.CryptographicParameters(
                cryptographic_algorithm=enums.CryptographicAlgorithm.ECDSA),
            data=b'\x01\x02\x03\x04\x05\x06\x07\x08'
            b'\x09\x10\x11\x12\x13\x14\x15\x16')
        b = sign.SignRequestPayload(
            unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959',
            cryptographic_parameters=attributes.CryptographicParameters(
                cryptographic_algorithm=enums.CryptographicAlgorithm.ECDSA),
            data=b'\x01\x02\x03\x04\x05\x06\x07\x08'
            b'\x09\x10\x11\x12\x13\x14\x15\x16')

        self.assertFalse(a != b)
        self.assertFalse(b != a)
Exemplo n.º 2
0
    def test_not_equal_on_not_equal_data(self):
        """
        Test that the inequality operator returns True when comparing two
        Sign request payloads with different data.
        """
        a = sign.SignRequestPayload(data=b'\x01')
        b = sign.SignRequestPayload(data=b'\xFF')

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Exemplo n.º 3
0
    def test_not_equal_on_not_equal_unique_identifier(self):
        """
        Test that the inequality operator returns True when comparing two
        Sign request payloads with different unique identifiers.
        """
        a = sign.SignRequestPayload(unique_identifier='a')
        b = sign.SignRequestPayload(unique_identifier='b')

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Exemplo n.º 4
0
    def test_not_equal_on_not_equal_cryptographic_parameters(self):
        """
        Test that the equality operator returns False when comparing two
        Sign request payloads with cryptographic parameters.
        """
        a = sign.SignRequestPayload(
            cryptographic_parameters=attributes.CryptographicParameters(
                hashing_algorithm=enums.HashingAlgorithm.MD5))
        b = sign.SignRequestPayload(
            cryptographic_parameters=attributes.CryptographicParameters(
                cryptographic_algorithm=enums.CryptographicAlgorithm.ECDSA))

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Exemplo n.º 5
0
    def test_repr(self):
        """
        Test that repr can be applied to a Sign request payload.
        """
        payload = sign.SignRequestPayload(
            unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959',
            cryptographic_parameters=attributes.CryptographicParameters(
                cryptographic_algorithm=enums.CryptographicAlgorithm.ECDSA
            ),
            data=b'\x01\x02\x03\x04\x05\x06\x07\x08'
        )
        expected = (
            "SignRequestPayload("
            "unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959', "
            "cryptographic_parameters=CryptographicParameters("
            "block_cipher_mode=None, padding_method=None, "
            "hashing_algorithm=None, key_role_type=None, "
            "digital_signature_algorithm=None, "
            "cryptographic_algorithm=CryptographicAlgorithm.ECDSA, "
            "random_iv=None, iv_length=None, tag_length=None, "
            "fixed_field_length=None, invocation_field_length=None, "
            "counter_length=None, initial_counter_value=None), "
            "data=" + str(b'\x01\x02\x03\x04\x05\x06\x07\x08') + ")"
        )
        observed = repr(payload)

        self.assertEqual(expected, observed)
Exemplo n.º 6
0
    def test_read(self):
        """
        Test that a Sign request payload can be read from a data stream.
        """
        payload = sign.SignRequestPayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.cryptographic_parameters)
        self.assertEqual(None, payload.data)

        payload.read(self.full_encoding)

        self.assertEqual(
            'b4faee10-aa2a-4446-8ad4-0881f3422959',
            payload.unique_identifier
        )
        self.assertIsNotNone(payload.cryptographic_parameters)
        self.assertEqual(
            enums.CryptographicAlgorithm.ECDSA,
            payload.cryptographic_parameters.cryptographic_algorithm
        )
        self.assertEqual(
            b'\x01\x02\x03\x04\x05\x06\x07\x08'
            b'\x09\x10\x11\x12\x13\x14\x15\x16',
            payload.data
        )
Exemplo n.º 7
0
 def test_invalid_data(self):
     """
     Test that a TypeError is raised when an invalid value is used to set
     the data of a Sign request payload.
     """
     payload = sign.SignRequestPayload()
     args = (payload, 'data', 0)
     self.assertRaisesRegex(TypeError, "data must be bytes", setattr, *args)
Exemplo n.º 8
0
 def test_invalid_unique_identifier(self):
     """
     Test that a TypeError is raised when an invalid value is used to set
     the unique identifier of a Sign request payload.
     """
     payload = sign.SignRequestPayload()
     args = (payload, 'unique_identifier', 0)
     self.assertRaisesRegex(TypeError, "unique identifier must be a string",
                            setattr, *args)
Exemplo n.º 9
0
    def test_init(self):
        """
        Test that a Sign request payload can be constructed with no arguments.
        """
        payload = sign.SignRequestPayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.cryptographic_parameters)
        self.assertEqual(None, payload.data)
Exemplo n.º 10
0
 def test_read_invalid(self):
     """
     Test that a ValueError gets raised when a required Sign request
     payload attribute is missing from the payload encoding.
     """
     payload = sign.SignRequestPayload()
     args = (self.empty_encoding, )
     self.assertRaisesRegexp(ValueError,
                             "invalid payload missing the data attribute",
                             payload.read, *args)
Exemplo n.º 11
0
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the inequality operator returns True when comparing two
        Sign request payloads with different types.
        """
        a = sign.SignRequestPayload()
        b = 'invalid'

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Exemplo n.º 12
0
 def test_invalid_cryptographic_parameters(self):
     """
     Test that a TypeError is raised when an invalid value is used to set
     the cryptographic parameters of a Sign request payload.
     """
     payload = sign.SignRequestPayload()
     args = (payload, 'cryptographic_parameters', b'\x01\x02\x03')
     self.assertRaisesRegexp(
         TypeError,
         "cryptographic parameters must be a CryptographicParameters "
         "struct", setattr, *args)
Exemplo n.º 13
0
 def test_write_invalid(self):
     """
     Test that a ValueError gets raised when a required Sign request
     payload attribute is missing when encoding the payload.
     """
     payload = sign.SignRequestPayload()
     stream = utils.BytearrayStream()
     args = (stream, )
     self.assertRaisesRegexp(ValueError,
                             "invalid payload missing the data attribute",
                             payload.write, *args)
Exemplo n.º 14
0
    def test_write_partial(self):
        """
        Test that a partially defined Sign request payload can be written
        to a data stream.
        """
        payload = sign.SignRequestPayload(
            data=b'\x01\x02\x03\x04\x05\x06\x07\x08'
            b'\x09\x10\x11\x12\x13\x14\x15\x16')
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.minimum_encoding), len(stream))
        self.assertEqual(str(self.minimum_encoding), str(stream))
Exemplo n.º 15
0
    def test_init_with_args(self):
        """
        Test that a Sign request payload can be constructed with valid values.
        """
        payload = sign.SignRequestPayload(
            unique_identifier='00000000-1111-2222-3333-444444444444',
            cryptographic_parameters=attributes.CryptographicParameters(),
            data=b'\x01\x02\x03')

        self.assertEqual('00000000-1111-2222-3333-444444444444',
                         payload.unique_identifier)
        self.assertEqual(attributes.CryptographicParameters(),
                         payload.cryptographic_parameters)
        self.assertEqual(b'\x01\x02\x03', payload.data)
Exemplo n.º 16
0
    def test_write(self):
        """
        Test that a Sign request payload can be written to a data stream.
        """
        payload = sign.SignRequestPayload(
            unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959',
            cryptographic_parameters=attributes.CryptographicParameters(
                cryptographic_algorithm=enums.CryptographicAlgorithm.ECDSA),
            data=b'\x01\x02\x03\x04\x05\x06\x07\x08'
            b'\x09\x10\x11\x12\x13\x14\x15\x16')
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.full_encoding), len(stream))
        self.assertEqual(str(self.full_encoding), str(stream))
Exemplo n.º 17
0
    def test_read_partial(self):
        """
        Test that a Sign request payload can be read from a partial data
        stream containing the minimum required attributes.
        """
        payload = sign.SignRequestPayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.cryptographic_parameters)
        self.assertEqual(None, payload.data)

        payload.read(self.minimum_encoding)

        self.assertEqual(
            b'\x01\x02\x03\x04\x05\x06\x07\x08'
            b'\x09\x10\x11\x12\x13\x14\x15\x16', payload.data)
Exemplo n.º 18
0
    def test_str(self):
        """
        Test that str can be applied to a Sign request payload.
        """
        crypto_params = attributes.CryptographicParameters(
            cryptographic_algorithm=enums.CryptographicAlgorithm.ECDSA)
        payload = sign.SignRequestPayload(
            unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959',
            cryptographic_parameters=crypto_params,
            data=b'\x01\x02\x03\x04\x05\x06\x07\x08',
        )

        expected = str({
            'unique_identifier': 'b4faee10-aa2a-4446-8ad4-0881f3422959',
            'cryptographic_parameters': crypto_params,
            'data': b'\x01\x02\x03\x04\x05\x06\x07\x08'
        })
        observed = str(payload)

        self.assertEqual(expected, observed)
Exemplo n.º 19
0
 def _create_sign_payload(self):
     return sign.SignRequestPayload()