示例#1
0
    def test_create__with_fields(self):
        """Testing create instance with fields."""
        name = value = 'Test'
        fields = []
        entity = entities.Entity(name=name, value=value, fields=fields)

        self.assertEqual(entity.fields, fields)
示例#2
0
    def test_create__with_labels(self):
        """Testing create instance with labels."""
        name = value = 'Test'
        labels = []
        entity = entities.Entity(name=name, value=value, labels=labels)

        self.assertEqual(entity.labels, labels)
示例#3
0
    def test_create(self):
        """Testing create instance."""
        name = value = 'Test'
        entity = entities.Entity(name=name, value=value)

        self.assertIsInstance(entity, entities.Entity)
        self.assertEqual(entity.name, name)
        self.assertEqual(entity.value, value)
示例#4
0
    def test_to_node(self):
        """Testing `to_node` method."""
        entity_value = 'Test'
        entity = entities.Entity(name='Test', value=entity_value, labels=None)
        node = messages.TransformResponse([entity]).to_node()

        self.assertEqual(
            entity.value,
            node.find('Entities').getchildren()[0].find('Value').text
        )
示例#5
0
    def test_to_node_with_ui_messages(self):
        """Testing `to_node` method with ui messages."""
        entity_value = 'Test'
        ui_messages = [entities.UIMessage('Test', 'Test')]
        entity = entities.Entity(name='Test', value=entity_value, labels=None)
        node = messages.TransformResponse(
            [entity], ui_messages
        ).to_node()

        self.assertEqual(
            ui_messages[0].value,
            node.find('UIMessages').getchildren()[0].text
        )
示例#6
0
    def test_to_xml(self):
        """Testing to_xml method."""
        entity = entities.Entity(
            name='Test', value='Test'
        )
        response = messages.TransformResponse([entity])

        needle_xml = (
            '<MaltegoMessage><MaltegoTransformResponseMessage>'
            '<Entities><Entity Type="{}">'
            '<Value>{}</Value></Entity></Entities>'
            '</MaltegoTransformResponseMessage></MaltegoMessage>'
        ).format(entity.name, entity.value)

        self.assertEqual(response.to_xml().decode('ascii'), needle_xml)
示例#7
0
    def test_method_to_node(self):
        """Testing method to_node."""
        name = value = weight = icon_url = 'Test'
        field = entities.Field(name=name, value=value)
        label = entities.Label(name=name, value=value)
        node = entities.Entity(
            name=name, value=value, weight=weight,
            icon_url=icon_url, fields=[field], labels=[label]
        ).to_node()

        self.assertEqual(node.attrib['Type'], name)
        self.assertEqual(node.find('Weight').text, weight)
        self.assertEqual(node.find('IconURL').text, icon_url)
        self.assertEqual(node.find('Value').text, value)
        self.assertIn(
            field.value, node.find('AdditionalFields').getchildren()[0].text
        )
        self.assertIn(
            label.value, node.find('DisplayInformation').getchildren()[0].text
        )
示例#8
0
    def test_create__with_icon_url(self):
        """Testing create instance with icon_url."""
        name = value = icon_url = 'Test'
        entity = entities.Entity(name=name, value=value, icon_url=icon_url)

        self.assertEqual(entity.icon_url, icon_url)
示例#9
0
    def test_create__with_weight(self):
        """Testing create instance with weight."""
        name = value = weight = 'Test'
        entity = entities.Entity(name=name, value=value, weight=weight)

        self.assertEqual(entity.weight, weight)