Beispiel #1
0
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing two
        Rekey request payloads with the same data.
        """
        a = payloads.RekeyRequestPayload()
        b = payloads.RekeyRequestPayload()

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

        a = payloads.RekeyRequestPayload(
            unique_identifier='1346d253-69d6-474c-8cd5-ad475a3e0a81',
            offset=0,
            template_attribute=objects.TemplateAttribute(attributes=[
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Activation Date'),
                    attribute_value=primitives.DateTime(
                        value=1136113200, tag=enums.Tags.ACTIVATION_DATE))
            ]))
        b = payloads.RekeyRequestPayload(
            unique_identifier='1346d253-69d6-474c-8cd5-ad475a3e0a81',
            offset=0,
            template_attribute=objects.TemplateAttribute(attributes=[
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Activation Date'),
                    attribute_value=primitives.DateTime(
                        value=1136113200, tag=enums.Tags.ACTIVATION_DATE))
            ]))

        self.assertFalse(a != b)
        self.assertFalse(b != a)
Beispiel #2
0
    def test_not_equal_on_not_equal_unique_identifier(self):
        """
        Test that the equality operator returns True when comparing two Rekey
        request payloads with different unique identifiers.
        """
        a = payloads.RekeyRequestPayload(unique_identifier='a')
        b = payloads.RekeyRequestPayload(unique_identifier='b')

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Beispiel #3
0
    def test_not_equal_on_not_equal_offset(self):
        """
        Test that the inequality operator returns True when comparing two Rekey
        request payloads with different offsets.
        """
        a = payloads.RekeyRequestPayload(offset=0)
        b = payloads.RekeyRequestPayload(offset=1)

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Beispiel #4
0
    def test_read(self):
        """
        Test that a Rekey request payload can be read from a data stream.
        """
        payload = payloads.RekeyRequestPayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.offset)
        self.assertEqual(None, payload.template_attribute)

        payload.read(self.full_encoding)

        self.assertEqual(
            '1346d253-69d6-474c-8cd5-ad475a3e0a81',
            payload.unique_identifier
        )
        self.assertEqual(0, payload.offset)
        self.assertEqual(
            objects.TemplateAttribute(
                attributes=[
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Activation Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1136113200,
                            tag=enums.Tags.ACTIVATION_DATE
                        )
                    ),
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Process Start Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1136113200,
                            tag=enums.Tags.PROCESS_START_DATE
                        )
                    ),
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Protect Stop Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1577876400,
                            tag=enums.Tags.PROTECT_STOP_DATE
                        )
                    ),
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Deactivation Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1577876400,
                            tag=enums.Tags.DEACTIVATION_DATE
                        )
                    )
                ]
            ),
            payload.template_attribute
        )
Beispiel #5
0
    def test_write(self):
        """
        Test that a Rekey request payload can be written to a data stream.
        """
        payload = payloads.RekeyRequestPayload(
            unique_identifier='1346d253-69d6-474c-8cd5-ad475a3e0a81',
            offset=0,
            template_attribute=objects.TemplateAttribute(attributes=[
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Activation Date'),
                    attribute_value=primitives.DateTime(
                        value=1136113200, tag=enums.Tags.ACTIVATION_DATE)),
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Process Start Date'),
                    attribute_value=primitives.DateTime(
                        value=1136113200, tag=enums.Tags.PROCESS_START_DATE)),
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Protect Stop Date'),
                    attribute_value=primitives.DateTime(
                        value=1577876400, tag=enums.Tags.PROTECT_STOP_DATE)),
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Deactivation Date'),
                    attribute_value=primitives.DateTime(
                        value=1577876400, tag=enums.Tags.DEACTIVATION_DATE))
            ]))
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.full_encoding), len(stream))
        self.assertEqual(str(self.full_encoding), str(stream))
Beispiel #6
0
    def test_str(self):
        """
        Test that str can be applied to a Rekey request payload
        """
        payload = payloads.RekeyRequestPayload(
            unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038',
            offset=0,
            template_attribute=objects.TemplateAttribute(
                attributes=[
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Deactivation Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1577876400,
                            tag=enums.Tags.DEACTIVATION_DATE
                        )
                    )
                ]
            )
        )

        # TODO (peter-hamilton) Update this when TemplateAttributes have str
        expected = str({
            'unique_identifier': '49a1ca88-6bea-4fb2-b450-7e58802c3038',
            'offset': 0,
            'template_attribute': 'Struct()'
        })
        observed = str(payload)

        self.assertEqual(expected, observed)
Beispiel #7
0
    def test_init(self):
        """
        Test that a Rekey request payload can be constructed with no arguments.
        """
        payload = payloads.RekeyRequestPayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.offset)
        self.assertEqual(None, payload.template_attribute)
Beispiel #8
0
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the inequality operator returns True when comparing two Rekey
        request payloads with different types.
        """
        a = payloads.RekeyRequestPayload()
        b = 'invalid'

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Beispiel #9
0
    def test_write_empty(self):
        """
        Test that an empty Rekey request payload can be written to a data
        stream.
        """
        payload = payloads.RekeyRequestPayload()
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.empty_encoding), len(stream))
        self.assertEqual(str(self.empty_encoding), str(stream))
Beispiel #10
0
    def test_write_partial(self):
        """
        Test that a partial Rekey request payload can be written to a data
        stream.
        """
        payload = payloads.RekeyRequestPayload(
            unique_identifier='964d3dd2-5f06-4529-8bb8-ae630b6ca2e0')
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.partial_encoding), len(stream))
        self.assertEqual(str(self.partial_encoding), str(stream))
Beispiel #11
0
    def test_invalid_offset(self):
        """
        Test that a TypeError is raised when an invalid value is used to set
        the offset of a Rekey request payload.
        """
        kwargs = {'offset': 'invalid'}
        self.assertRaisesRegex(TypeError, "Offset must be an integer.",
                               payloads.RekeyRequestPayload, **kwargs)

        args = (payloads.RekeyRequestPayload(), 'offset', 'invalid')
        self.assertRaisesRegex(TypeError, "Offset must be an integer.",
                               setattr, *args)
Beispiel #12
0
    def test_not_equal_on_not_equal_template_attribute(self):
        """
        Test that the inequality operator returns True when comparing two Rekey
        request payloads with different template attributes.
        """
        a = payloads.RekeyRequestPayload(
            template_attribute=objects.TemplateAttribute(
                attributes=[
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Protect Stop Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1577876400,
                            tag=enums.Tags.PROTECT_STOP_DATE
                        )
                    )
                ]
            )
        )
        b = payloads.RekeyRequestPayload(
            template_attribute=objects.TemplateAttribute(
                attributes=[
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Deactivation Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1577876400,
                            tag=enums.Tags.DEACTIVATION_DATE
                        )
                    )
                ]
            )
        )

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Beispiel #13
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 Rekey request payload.
        """
        kwargs = {'unique_identifier': 0}
        self.assertRaisesRegex(TypeError,
                               "Unique identifier must be a string.",
                               payloads.RekeyRequestPayload, **kwargs)

        args = (payloads.RekeyRequestPayload(), 'unique_identifier', 0)
        self.assertRaisesRegex(TypeError,
                               "Unique identifier must be a string.", setattr,
                               *args)
Beispiel #14
0
    def test_init_with_args(self):
        """
        Test that a Rekey request payload can be constructed with valid values.
        """
        payload = payloads.RekeyRequestPayload(
            unique_identifier='00000000-2222-4444-6666-888888888888',
            offset=0,
            template_attribute=objects.TemplateAttribute())

        self.assertEqual('00000000-2222-4444-6666-888888888888',
                         payload.unique_identifier)
        self.assertEqual(0, payload.offset)
        self.assertEqual(objects.TemplateAttribute(),
                         payload.template_attribute)
Beispiel #15
0
    def test_read_empty(self):
        """
        Test that a Rekey request payload can be read from an empty data
        stream.
        """
        payload = payloads.RekeyRequestPayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.offset)
        self.assertEqual(None, payload.template_attribute)

        payload.read(self.empty_encoding)

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.offset)
        self.assertEqual(None, payload.template_attribute)
Beispiel #16
0
    def test_invalid_template_attribute(self):
        """
        Test that a TypeError is raised when an invalid value is used to set
        the template attribute of a Rekey request payload.
        """
        kwargs = {'template_attribute': 'invalid'}
        self.assertRaisesRegex(
            TypeError,
            "Template attribute must be a TemplateAttribute struct.",
            payloads.RekeyRequestPayload, **kwargs)

        args = (payloads.RekeyRequestPayload(), 'template_attribute',
                'invalid')
        self.assertRaisesRegex(
            TypeError,
            "Template attribute must be a TemplateAttribute struct.", setattr,
            *args)
Beispiel #17
0
    def test_read_partial(self):
        """
        Test that a Rekey request payload can be read from a partial data
        stream.
        """
        payload = payloads.RekeyRequestPayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.offset)
        self.assertEqual(None, payload.template_attribute)

        payload.read(self.partial_encoding)

        self.assertEqual('964d3dd2-5f06-4529-8bb8-ae630b6ca2e0',
                         payload.unique_identifier)
        self.assertEqual(None, payload.offset)
        self.assertEqual(None, payload.template_attribute)
Beispiel #18
0
 def _create_rekey_payload(self):
     return payloads.RekeyRequestPayload()